+ struct sysfs_driver *driver = NULL;
+
+ if (!path) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (sysfs_path_is_dir(path)) {
+ dprintf("Invalid path to driver: %s\n", path);
+ return NULL;
+ }
+ driver = alloc_driver();
+ if (!driver) {
+ dprintf("Error allocating driver at %s\n", path);
+ return NULL;
+ }
+ if (sysfs_get_name_from_path(path, driver->name, SYSFS_NAME_LEN)) {
+ dprintf("Error getting driver name from path\n");
+ free(driver);
+ return NULL;
+ }
+ safestrcpy(driver->path, path);
+ if (sysfs_remove_trailing_slash(driver->path)) {
+ dprintf("Invalid path to driver %s\n", driver->path);
+ sysfs_close_driver(driver);
+ return NULL;
+ }
+ if (get_driver_bus(driver)) {
+ dprintf("Could not get the bus driver is on\n");
+ sysfs_close_driver(driver);