Commit f70fa629 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

Driver core: Don't ignore error returns from probing

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: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 952ab431
...@@ -439,8 +439,10 @@ void bus_remove_device(struct device * dev) ...@@ -439,8 +439,10 @@ void bus_remove_device(struct device * dev)
sysfs_remove_link(&dev->kobj, "bus"); sysfs_remove_link(&dev->kobj, "bus");
sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
device_remove_attrs(dev->bus, dev); device_remove_attrs(dev->bus, dev);
dev->is_registered = 0; if (dev->is_registered) {
klist_del(&dev->knode_bus); dev->is_registered = 0;
klist_del(&dev->knode_bus);
}
pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
device_release_driver(dev); device_release_driver(dev);
put_bus(dev->bus); put_bus(dev->bus);
......
...@@ -479,7 +479,8 @@ int device_add(struct device *dev) ...@@ -479,7 +479,8 @@ int device_add(struct device *dev)
if ((error = bus_add_device(dev))) if ((error = bus_add_device(dev)))
goto BusError; goto BusError;
kobject_uevent(&dev->kobj, KOBJ_ADD); kobject_uevent(&dev->kobj, KOBJ_ADD);
bus_attach_device(dev); if ((error = bus_attach_device(dev)))
goto AttachError;
if (parent) if (parent)
klist_add_tail(&dev->knode_parent, &parent->klist_children); klist_add_tail(&dev->knode_parent, &parent->klist_children);
...@@ -498,6 +499,8 @@ int device_add(struct device *dev) ...@@ -498,6 +499,8 @@ int device_add(struct device *dev)
kfree(class_name); kfree(class_name);
put_device(dev); put_device(dev);
return error; return error;
AttachError:
bus_remove_device(dev);
BusError: BusError:
device_pm_remove(dev); device_pm_remove(dev);
PMError: PMError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment