Skip to content

Commit c6a4669

Browse files
cohuckgregkh
authored andcommitted
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>
1 parent eed40d3 commit c6a4669

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void);
1616
extern int attribute_container_init(void);
1717

1818
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);
2020
extern void bus_remove_device(struct device * dev);
2121
extern struct bus_type *get_bus(struct bus_type * bus);
2222
extern void put_bus(struct bus_type * bus);

‎drivers/base/bus.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ int bus_add_device(struct device * dev)
447447
* - Add device to bus's list of devices.
448448
* - Try to attach to driver.
449449
*/
450-
int bus_attach_device(struct device * dev)
450+
void bus_attach_device(struct device * dev)
451451
{
452452
struct bus_type *bus = dev->bus;
453453
int ret = 0;
@@ -456,13 +456,12 @@ int bus_attach_device(struct device * dev)
456456
dev->is_registered = 1;
457457
if (bus->drivers_autoprobe)
458458
ret = device_attach(dev);
459-
if (ret >= 0) {
459+
WARN_ON(ret < 0);
460+
if (ret >= 0)
460461
klist_add_tail(&dev->knode_bus, &bus->klist_devices);
461-
ret = 0;
462-
} else
462+
else
463463
dev->is_registered = 0;
464464
}
465-
return ret;
466465
}
467466

468467
/**
@@ -669,8 +668,6 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
669668
ret = device_attach(dev);
670669
if (dev->parent)
671670
up(&dev->parent->sem);
672-
if (ret > 0)
673-
ret = 0;
674671
}
675672
return ret < 0 ? ret : 0;
676673
}

‎drivers/base/core.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,7 @@ int device_add(struct device *dev)
677677
goto BusError;
678678
if (!dev->uevent_suppress)
679679
kobject_uevent(&dev->kobj, KOBJ_ADD);
680-
if ((error = bus_attach_device(dev)))
681-
goto AttachError;
680+
bus_attach_device(dev);
682681
if (parent)
683682
klist_add_tail(&dev->knode_parent, &parent->klist_children);
684683

@@ -697,8 +696,6 @@ int device_add(struct device *dev)
697696
kfree(class_name);
698697
put_device(dev);
699698
return error;
700-
AttachError:
701-
bus_remove_device(dev);
702699
BusError:
703700
device_pm_remove(dev);
704701
PMError:

‎drivers/base/dd.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static int device_probe_drivers(void *data)
232232
*
233233
* Returns 1 if the device was bound to a driver;
234234
* 0 if no matching device was found or multithreaded probing is done;
235-
* error code otherwise.
235+
* -ENODEV if the device is not registered.
236236
*
237237
* When called for a USB interface, @dev->parent->sem must be held.
238238
*/
@@ -246,6 +246,10 @@ int device_attach(struct device * dev)
246246
ret = device_bind_driver(dev);
247247
if (ret == 0)
248248
ret = 1;
249+
else {
250+
dev->driver = NULL;
251+
ret = 0;
252+
}
249253
} else {
250254
if (dev->bus->multithread_probe)
251255
probe_task = kthread_run(device_probe_drivers, dev,

0 commit comments

Comments
 (0)