-/**
- * sysfs_find_driver_bus: locates the bus the driver is on.
- * @driver: name of the driver to locate
- * @busname: buffer to copy name to
- * @bsize: buffer size
- * returns 0 with success, -1 with error
- */
-int sysfs_find_driver_bus(const unsigned char *driver, unsigned char *busname,
- size_t bsize)
-{
- unsigned char subsys[SYSFS_PATH_MAX], *bus = NULL, *curdrv = NULL;
- struct dlist *buslist = NULL, *drivers = NULL;
-
- if (driver == NULL || busname == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- memset(subsys, 0, SYSFS_PATH_MAX);
- strcpy(subsys, SYSFS_BUS_NAME);
- buslist = sysfs_open_subsystem_list(subsys);
- if (buslist != NULL) {
- dlist_for_each_data(buslist, bus, char) {
- memset(subsys, 0, SYSFS_PATH_MAX);
- strcat(subsys, "/");
- strcpy(subsys, SYSFS_BUS_NAME);
- strcat(subsys, "/");
- strcat(subsys, bus);
- strcat(subsys, "/");
- strcat(subsys, SYSFS_DRIVERS_NAME);
- drivers = sysfs_open_subsystem_list(subsys);
- if (drivers != NULL) {
- dlist_for_each_data(drivers, curdrv, char) {
- if (strcmp(driver, curdrv) == 0) {
- strncpy(busname, bus, bsize);
- sysfs_close_list(drivers);
- sysfs_close_list(buslist);
- return 0;
- }
- }
- sysfs_close_list(drivers);
- }
- }
- sysfs_close_list(buslist);
- }
- return -1;
-}
-