Skip to content

Commit

Permalink
Driver core: Don't ignore error returns from probing
Browse files Browse the repository at this point in the history
This patch (as797) fixes device_add() in the driver core.  It needs to
pay attention when the driver for a new device reports an error.

At the same time, since bus_remove_device() undoes the effects of both
bus_add_device() and bus_attach_device(), it needs to check whether
the bus_attach_device step failed.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Alan Stern authored and Greg Kroah-Hartman committed Oct 18, 2006
1 parent 952ab43 commit f70fa62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,10 @@ void bus_remove_device(struct device * dev)
sysfs_remove_link(&dev->kobj, "bus");
sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
device_remove_attrs(dev->bus, dev);
dev->is_registered = 0;
klist_del(&dev->knode_bus);
if (dev->is_registered) {
dev->is_registered = 0;
klist_del(&dev->knode_bus);
}
pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
device_release_driver(dev);
put_bus(dev->bus);
Expand Down
5 changes: 4 additions & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ int device_add(struct device *dev)
if ((error = bus_add_device(dev)))
goto BusError;
kobject_uevent(&dev->kobj, KOBJ_ADD);
bus_attach_device(dev);
if ((error = bus_attach_device(dev)))
goto AttachError;
if (parent)
klist_add_tail(&dev->knode_parent, &parent->klist_children);

Expand All @@ -498,6 +499,8 @@ int device_add(struct device *dev)
kfree(class_name);
put_device(dev);
return error;
AttachError:
bus_remove_device(dev);
BusError:
device_pm_remove(dev);
PMError:
Expand Down

0 comments on commit f70fa62

Please sign in to comment.