diff options
author | Cornelia Huck <cornelia.huck@de.ibm.com> | 2007-02-05 19:15:26 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-04-27 13:57:29 -0400 |
commit | c6a46696f97ff260a4ecce5e287f8de4b9d7fe14 (patch) | |
tree | 335de50c9868cd575f535677e430677d33cbaaa1 /drivers/base | |
parent | eed40d3ad2ba652c08422d62a5ff6f62ac0be16d (diff) |
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: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/base.h | 2 | ||||
-rw-r--r-- | drivers/base/bus.c | 11 | ||||
-rw-r--r-- | drivers/base/core.c | 5 | ||||
-rw-r--r-- | drivers/base/dd.c | 6 |
4 files changed, 11 insertions, 13 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h index de7e1442ce60..d597f2659b23 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void); | |||
16 | extern int attribute_container_init(void); | 16 | extern int attribute_container_init(void); |
17 | 17 | ||
18 | extern int bus_add_device(struct device * dev); | 18 | extern int bus_add_device(struct device * dev); |
19 | extern int bus_attach_device(struct device * dev); | 19 | extern void bus_attach_device(struct device * dev); |
20 | extern void bus_remove_device(struct device * dev); | 20 | extern void bus_remove_device(struct device * dev); |
21 | extern struct bus_type *get_bus(struct bus_type * bus); | 21 | extern struct bus_type *get_bus(struct bus_type * bus); |
22 | extern void put_bus(struct bus_type * bus); | 22 | extern void put_bus(struct bus_type * bus); |
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 9df2e6dff519..20b6dc8706fa 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -447,7 +447,7 @@ out_put: | |||
447 | * - Add device to bus's list of devices. | 447 | * - Add device to bus's list of devices. |
448 | * - Try to attach to driver. | 448 | * - Try to attach to driver. |
449 | */ | 449 | */ |
450 | int bus_attach_device(struct device * dev) | 450 | void bus_attach_device(struct device * dev) |
451 | { | 451 | { |
452 | struct bus_type *bus = dev->bus; | 452 | struct bus_type *bus = dev->bus; |
453 | int ret = 0; | 453 | int ret = 0; |
@@ -456,13 +456,12 @@ int bus_attach_device(struct device * dev) | |||
456 | dev->is_registered = 1; | 456 | dev->is_registered = 1; |
457 | if (bus->drivers_autoprobe) | 457 | if (bus->drivers_autoprobe) |
458 | ret = device_attach(dev); | 458 | ret = device_attach(dev); |
459 | if (ret >= 0) { | 459 | WARN_ON(ret < 0); |
460 | if (ret >= 0) | ||
460 | klist_add_tail(&dev->knode_bus, &bus->klist_devices); | 461 | klist_add_tail(&dev->knode_bus, &bus->klist_devices); |
461 | ret = 0; | 462 | else |
462 | } else | ||
463 | dev->is_registered = 0; | 463 | dev->is_registered = 0; |
464 | } | 464 | } |
465 | return ret; | ||
466 | } | 465 | } |
467 | 466 | ||
468 | /** | 467 | /** |
@@ -669,8 +668,6 @@ static int __must_check bus_rescan_devices_helper(struct device *dev, | |||
669 | ret = device_attach(dev); | 668 | ret = device_attach(dev); |
670 | if (dev->parent) | 669 | if (dev->parent) |
671 | up(&dev->parent->sem); | 670 | up(&dev->parent->sem); |
672 | if (ret > 0) | ||
673 | ret = 0; | ||
674 | } | 671 | } |
675 | return ret < 0 ? ret : 0; | 672 | return ret < 0 ? ret : 0; |
676 | } | 673 | } |
diff --git a/drivers/base/core.c b/drivers/base/core.c index bffb69e4bde2..be6aeb430798 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -677,8 +677,7 @@ int device_add(struct device *dev) | |||
677 | goto BusError; | 677 | goto BusError; |
678 | if (!dev->uevent_suppress) | 678 | if (!dev->uevent_suppress) |
679 | kobject_uevent(&dev->kobj, KOBJ_ADD); | 679 | kobject_uevent(&dev->kobj, KOBJ_ADD); |
680 | if ((error = bus_attach_device(dev))) | 680 | bus_attach_device(dev); |
681 | goto AttachError; | ||
682 | if (parent) | 681 | if (parent) |
683 | klist_add_tail(&dev->knode_parent, &parent->klist_children); | 682 | klist_add_tail(&dev->knode_parent, &parent->klist_children); |
684 | 683 | ||
@@ -697,8 +696,6 @@ int device_add(struct device *dev) | |||
697 | kfree(class_name); | 696 | kfree(class_name); |
698 | put_device(dev); | 697 | put_device(dev); |
699 | return error; | 698 | return error; |
700 | AttachError: | ||
701 | bus_remove_device(dev); | ||
702 | BusError: | 699 | BusError: |
703 | device_pm_remove(dev); | 700 | device_pm_remove(dev); |
704 | PMError: | 701 | PMError: |
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 616b4bbacf1b..18dba8e78da7 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
@@ -232,7 +232,7 @@ static int device_probe_drivers(void *data) | |||
232 | * | 232 | * |
233 | * Returns 1 if the device was bound to a driver; | 233 | * Returns 1 if the device was bound to a driver; |
234 | * 0 if no matching device was found or multithreaded probing is done; | 234 | * 0 if no matching device was found or multithreaded probing is done; |
235 | * error code otherwise. | 235 | * -ENODEV if the device is not registered. |
236 | * | 236 | * |
237 | * When called for a USB interface, @dev->parent->sem must be held. | 237 | * When called for a USB interface, @dev->parent->sem must be held. |
238 | */ | 238 | */ |
@@ -246,6 +246,10 @@ int device_attach(struct device * dev) | |||
246 | ret = device_bind_driver(dev); | 246 | ret = device_bind_driver(dev); |
247 | if (ret == 0) | 247 | if (ret == 0) |
248 | ret = 1; | 248 | ret = 1; |
249 | else { | ||
250 | dev->driver = NULL; | ||
251 | ret = 0; | ||
252 | } | ||
249 | } else { | 253 | } else { |
250 | if (dev->bus->multithread_probe) | 254 | if (dev->bus->multithread_probe) |
251 | probe_task = kthread_run(device_probe_drivers, dev, | 255 | probe_task = kthread_run(device_probe_drivers, dev, |