gregkh avatar gregkh committed 63dde9f

[PATCH] minor cleanups.

Comments (0)

Files changed (1)

 #include "libsysfs/libsysfs.h"
 
 
-static char sysfs_path[SYSFS_PATH_MAX];
-
 /* 
  * Right now the major/minor of a device is stored in a file called
  * "dev" in sysfs.
 
 struct sysfs_class_device *get_class_dev(char *device_name)
 {
+	char sysfs_path[SYSFS_PATH_MAX];
 	char dev_path[SYSFS_PATH_MAX];
-	struct sysfs_class_device *class_dev;
+	int retval;
+	struct sysfs_class_device *class_dev = NULL;
+
+
+	retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
+	dbg("sysfs_path = %s", sysfs_path);
+	if (retval) {
+		dbg("sysfs_get_mnt_path failed");
+		goto exit;
+	}
 
 	strcpy(dev_path, sysfs_path);
 	strcat(dev_path, device_name);
 	class_dev = sysfs_open_class_device(dev_path);
 	if (class_dev == NULL) {
 		dbg ("sysfs_open_class_device failed");
-		return NULL;
+		goto exit;
 	}
 	dbg("class_dev->name = %s", class_dev->name);
 
+exit:
 	return class_dev;
 }
 
-static int udev_init(void)
-{
-	int retval;
-
-	retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
-	dbg("sysfs_path = %s", sysfs_path);
-	return retval;
-}
-
 int udev_add_device(char *device, char *subsystem)
 {
 	struct sysfs_class_device *class_dev;
 	struct device_attr attr;
-	//char *name;
 	int major;
 	int minor;
 	char type;
-	//int mode;
 	int retval = -EINVAL;
 
-	/* sleep for a second or two to give the kernel a chance to
-	 * create the dev file
-	 */
-	sleep(1);
-
-	udev_init();
-
 	/* for now, the block layer is the only place where block devices are */
 	if (strcmp(subsystem, "block") == 0)
 		type = 'b';
 	else
 		type = 'c';
 
+	/* sleep for a second or two to give the kernel a chance to
+	 * create the dev file
+	 */
+	sleep(1);
+
 	class_dev = get_class_dev(device);
 	if (class_dev == NULL)
 		goto exit;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.