- bus = alloc_bus();
- if (bus == NULL) {
- perror("malloc");
- return NULL;
- }
- strcpy(bus->name, name);
- busdir = open_bus_dir(name);
- if (busdir == NULL) {
- dprintf(stderr,"Invalid bus, %s not supported on this system\n",
- name);
- sysfs_close_bus(bus);
- return NULL;
- }
- bus->directory = busdir;
- if ((get_all_bus_devices(bus)) != 0) {
- dprintf(stderr, "Error reading %s bus devices\n", name);
- sysfs_close_bus(bus);
- return NULL;
- }
- if ((get_all_bus_drivers(bus)) != 0) {
- dprintf(stderr, "Error reading %s bus drivers\n", name);
- sysfs_close_bus(bus);
- return NULL;
+ memset(subsys, 0, SYSFS_PATH_MAX);
+ safestrcpy(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);
+ safestrcpy(subsys, SYSFS_BUS_NAME);
+ safestrcat(subsys, "/");
+ safestrcat(subsys, bus);
+ safestrcat(subsys, "/");
+ safestrcat(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) {
+ safestrcpymax(busname,
+ bus, bsize);
+ sysfs_close_list(drivers);
+ sysfs_close_list(buslist);
+ return 0;
+ }
+ }
+ sysfs_close_list(drivers);
+ }
+ }
+ sysfs_close_list(buslist);