Commit c6a46696 authored by Cornelia Huck's avatar Cornelia Huck Committed by Greg Kroah-Hartman

driver core: don't fail attaching the device if it cannot be bound

Don't fail bus_attach_device() if the device cannot be bound.

If dev->driver has been specified, reset it to NULL if device_bind_driver()
failed and add the device as an unbound device.  As a result,
bus_attach_device() now cannot fail, and we can remove some checking from
device_add().

Also remove an unneeded check in bus_rescan_devices_helper().
Signed-off-by: default avatarCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent eed40d3a
...@@ -16,7 +16,7 @@ extern int cpu_dev_init(void); ...@@ -16,7 +16,7 @@ extern int cpu_dev_init(void);
extern int attribute_container_init(void); extern int attribute_container_init(void);
extern int bus_add_device(struct device * dev); extern int bus_add_device(struct device * dev);
extern int bus_attach_device(struct device * dev); extern void bus_attach_device(struct device * dev);
extern void bus_remove_device(struct device * dev); extern void bus_remove_device(struct device * dev);
extern struct bus_type *get_bus(struct bus_type * bus); extern struct bus_type *get_bus(struct bus_type * bus);
extern void put_bus(struct bus_type * bus); extern void put_bus(struct bus_type * bus);
......
...@@ -447,7 +447,7 @@ out_put: ...@@ -447,7 +447,7 @@ out_put:
* - Add device to bus's list of devices. * - Add device to bus's list of devices.
* - Try to attach to driver. * - Try to attach to driver.
*/ */
int bus_attach_device(struct device * dev) void bus_attach_device(struct device * dev)
{ {
struct bus_type *bus = dev->bus; struct bus_type *bus = dev->bus;
int ret = 0; int ret = 0;
...@@ -456,13 +456,12 @@ int bus_attach_device(struct device * dev) ...@@ -456,13 +456,12 @@ int bus_attach_device(struct device * dev)
dev->is_registered = 1; dev->is_registered = 1;
if (bus->drivers_autoprobe) if (bus->drivers_autoprobe)
ret = device_attach(dev); ret = device_attach(dev);
if (ret >= 0) { WARN_ON(ret < 0);
if (ret >= 0)
klist_add_tail(&dev->knode_bus, &bus->klist_devices); klist_add_tail(&dev->knode_bus, &bus->klist_devices);
ret = 0; else
} else
dev->is_registered = 0; dev->is_registered = 0;
} }
return ret;
} }
/** /**
...@@ -669,8 +668,6 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, ...@@ -669,8 +668,6 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
ret = device_attach(dev); ret = device_attach(dev);
if (dev->parent) if (dev->parent)
up(&dev->parent->sem); up(&dev->parent->sem);
if (ret > 0)
ret = 0;
} }
return ret < 0 ? ret : 0; return ret < 0 ? ret : 0;
} }
......
...@@ -677,8 +677,7 @@ int device_add(struct device *dev) ...@@ -677,8 +677,7 @@ int device_add(struct device *dev)
goto BusError; goto BusError;
if (!dev->uevent_suppress) if (!dev->uevent_suppress)
kobject_uevent(&dev->kobj, KOBJ_ADD); kobject_uevent(&dev->kobj, KOBJ_ADD);
if ((error = bus_attach_device(dev))) 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);
...@@ -697,8 +696,6 @@ int device_add(struct device *dev) ...@@ -697,8 +696,6 @@ 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:
......
...@@ -232,7 +232,7 @@ static int device_probe_drivers(void *data) ...@@ -232,7 +232,7 @@ static int device_probe_drivers(void *data)
* *
* Returns 1 if the device was bound to a driver; * Returns 1 if the device was bound to a driver;
* 0 if no matching device was found or multithreaded probing is done; * 0 if no matching device was found or multithreaded probing is done;
* error code otherwise. * -ENODEV if the device is not registered.
* *
* When called for a USB interface, @dev->parent->sem must be held. * When called for a USB interface, @dev->parent->sem must be held.
*/ */
...@@ -246,6 +246,10 @@ int device_attach(struct device * dev) ...@@ -246,6 +246,10 @@ int device_attach(struct device * dev)
ret = device_bind_driver(dev); ret = device_bind_driver(dev);
if (ret == 0) if (ret == 0)
ret = 1; ret = 1;
else {
dev->driver = NULL;
ret = 0;
}
} else { } else {
if (dev->bus->multithread_probe) if (dev->bus->multithread_probe)
probe_task = kthread_run(device_probe_drivers, dev, probe_task = kthread_run(device_probe_drivers, dev,
......
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