summaryrefslogtreecommitdiff
path: root/lib/sysfs_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sysfs_driver.c')
-rw-r--r--lib/sysfs_driver.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/sysfs_driver.c b/lib/sysfs_driver.c
index f2145e0..1ccaf03 100644
--- a/lib/sysfs_driver.c
+++ b/lib/sysfs_driver.c
@@ -98,11 +98,11 @@ static struct sysfs_driver *alloc_driver(void)
}
/**
- * sysfs_open_driver: opens and initializes driver structure
+ * sysfs_open_driver_path: opens and initializes driver structure
* @path: path to driver directory
* returns struct sysfs_driver with success and NULL with error
*/
-struct sysfs_driver *sysfs_open_driver(const unsigned char *path)
+struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path)
{
struct sysfs_driver *driver = NULL;
struct sysfs_directory *sdir = NULL;
@@ -243,7 +243,7 @@ struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver)
if (driver->directory->links != NULL) {
dlist_for_each_data(driver->directory->links, curlink,
struct sysfs_link) {
- device = sysfs_open_device(curlink->target);
+ device = sysfs_open_device_path(curlink->target);
if (device == NULL) {
dprintf("Error opening device at %s\n",
curlink->target);
@@ -345,7 +345,7 @@ struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
return NULL;
}
- memset(path, 0, SYSFS_NAME_LEN);
+ memset(path, 0, SYSFS_PATH_MAX);
if ((get_driver_path(bus, drv, path, SYSFS_PATH_MAX)) != 0) {
dprintf("Error getting to driver %s\n", drv);
return NULL;
@@ -367,3 +367,33 @@ struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
return attribute;
}
+/**
+ * sysfs_open_driver: open driver by name, given its bus
+ * @drv_name: Name of the driver
+ * @bus_name: Name of the bus
+ * Returns the sysfs_driver reference on success and NULL on failure
+ */
+struct sysfs_driver *sysfs_open_driver(const unsigned char *drv_name,
+ const unsigned char *bus_name)
+{
+ unsigned char path[SYSFS_PATH_MAX];
+ struct sysfs_driver *driver = NULL;
+
+ if (drv_name == NULL || bus_name == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ memset(path, 0, SYSFS_PATH_MAX);
+ if ((get_driver_path(bus_name, drv_name, path, SYSFS_PATH_MAX)) != 0) {
+ dprintf("Error getting to driver %s\n", drv_name);
+ return NULL;
+ }
+ driver = sysfs_open_driver_path(path);
+ if (driver == NULL) {
+ dprintf("Error opening driver at %s\n", path);
+ return NULL;
+ }
+ return driver;
+}
+