chiark / gitweb /
[PATCH] update libsysfs to CVS version and fix segfaulting attribute reading
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Thu, 16 Dec 2004 15:05:01 +0000 (16:05 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:17:47 +0000 (23:17 -0700)
libsysfs/sysfs_class.c
libsysfs/sysfs_device.c

index db59aef90f60ce61ee2bf086e076a4f07e40c180..a132bb64cbc097a989e52a8ddeeeda2bdf69ddaa 100644 (file)
@@ -640,6 +640,9 @@ struct sysfs_attribute *sysfs_get_classdev_attr
                        return cur;
        }
 
                        return cur;
        }
 
+       if (clsdev->directory == NULL)
+               return NULL;
+
        if (clsdev->directory->subdirs == NULL) 
                if ((sysfs_read_dir_subdirs(clsdev->directory)) != 0 ||
                    clsdev->directory->subdirs == NULL) 
        if (clsdev->directory->subdirs == NULL) 
                if ((sysfs_read_dir_subdirs(clsdev->directory)) != 0 ||
                    clsdev->directory->subdirs == NULL) 
index f2f8d2d611b6c121985b32b93b5fdd0d99445d1f..83c3adc080cd3b81ffc29a13c03392660659fd51 100644 (file)
@@ -24,7 +24,9 @@
 #include "sysfs.h"
 
 /**
 #include "sysfs.h"
 
 /**
- * get_dev_driver: fills in the dev->driver_name field 
+ * get_dev_driver: fills in the dev->driver_name field, but searches by
+ *     opening subsystem. Only to be used if no driver link exists in
+ *     device directory.
  *
  * Returns 0 on SUCCESS and 1 on error
  */
  *
  * Returns 0 on SUCCESS and 1 on error
  */
@@ -73,6 +75,32 @@ static int get_dev_driver(struct sysfs_device *dev)
        }
        return 1;
 }
        }
        return 1;
 }
+
+/*
+ * get_device_driver_name: gets device's driver name, searches for driver
+ *     link first before going the brute force route.
+ * @dev: device to retrieve driver
+ * returns 0 with success and 1 with error
+ */
+static int get_device_driver_name(struct sysfs_device *dev)
+{
+       char devpath[SYSFS_PATH_MAX], drvpath[SYSFS_PATH_MAX];
+
+       if (dev == NULL) {
+               errno = EINVAL;
+               return 1;
+       }
+       memset(devpath, 0, SYSFS_PATH_MAX);
+       memset(drvpath, 0, SYSFS_PATH_MAX);
+       safestrcpy(devpath, dev->path);
+       safestrcat(devpath, "/driver");
+
+       if ((sysfs_get_link(devpath, drvpath, SYSFS_PATH_MAX)) != 0) 
+               return(get_dev_driver(dev));
+
+       return (sysfs_get_name_from_path(drvpath, dev->driver_name, 
+               SYSFS_NAME_LEN));
+}
        
 /**
  * sysfs_get_device_bus: retrieves the bus name the device is on, checks path 
        
 /**
  * sysfs_get_device_bus: retrieves the bus name the device is on, checks path 
@@ -262,7 +290,7 @@ struct sysfs_device *sysfs_open_device_path(const char *path)
        if (sysfs_get_device_bus(dev) != 0)
                dprintf("Could not get device bus\n");
        
        if (sysfs_get_device_bus(dev) != 0)
                dprintf("Could not get device bus\n");
        
-       if (get_dev_driver(dev) != 0) {
+       if (get_device_driver_name(dev) != 0) {
                dprintf("Could not get device %s's driver\n", dev->bus_id);
                safestrcpy(dev->driver_name, SYSFS_UNKNOWN);
        }
                dprintf("Could not get device %s's driver\n", dev->bus_id);
                safestrcpy(dev->driver_name, SYSFS_UNKNOWN);
        }