History

Revert "driver core: Add support for linking devices during device addition"

This reverts commit 5302dd7dd0b6d04c63cdce51d1e9fda9ef0be886. Based on a lot of email and in-person discussions, this patch series is being reworked to address a number of issues that were pointed out that needed to be taken care of before it should be merged. It will be resubmitted with those changes hopefully soon.

Greg Kroah-Hartman committed 7 years ago

Commit bfb39431 parent 33cbfe52 files · +0 −97Browse files

Unified · Split

2 files
  1. drivers/base/core.c +0 −83
  2. include/linux/device.h +0 −14
drivers/base/core.c+0−83
@@ -44,8 +44,6 @@ early_param("sysfs.deprecated", sysfs_deprecated_setup); · 43 unmodified lines
44#endif44#endif
45 45
46/* Device links support. */46/* Device links support. */
47static LIST_HEAD(wait_for_suppliers);
48static DEFINE_MUTEX(wfs_lock);
49 47
50#ifdef CONFIG_SRCU48#ifdef CONFIG_SRCU
51static DEFINE_MUTEX(device_links_lock);49static DEFINE_MUTEX(device_links_lock);
@@ -420,51 +418,6 @@ struct device_link *device_link_add(struct device *consumer, · 368 unmodified lines
420}418}
421EXPORT_SYMBOL_GPL(device_link_add);419EXPORT_SYMBOL_GPL(device_link_add);
422 420
423/**
424 * device_link_wait_for_supplier - Mark device as waiting for supplier
425 * @consumer: Consumer device
426 *
427 * Marks the consumer device as waiting for suppliers to become available. The
428 * consumer device will never be probed until it's unmarked as waiting for
429 * suppliers. The caller is responsible for adding the link to the supplier
430 * once the supplier device is present.
431 *
432 * This function is NOT meant to be called from the probe function of the
433 * consumer but rather from code that creates/adds the consumer device.
434 */
435static void device_link_wait_for_supplier(struct device *consumer)
436{
437 mutex_lock(&wfs_lock);
438 list_add_tail(&consumer->links.needs_suppliers, &wait_for_suppliers);
439 mutex_unlock(&wfs_lock);
440}
441
442/**
443 * device_link_check_waiting_consumers - Try to unmark waiting consumers
444 *
445 * Loops through all consumers waiting on suppliers and tries to add all their
446 * supplier links. If that succeeds, the consumer device is unmarked as waiting
447 * for suppliers. Otherwise, they are left marked as waiting on suppliers,
448 *
449 * The add_links bus callback is expected to return 0 if it has found and added
450 * all the supplier links for the consumer device. It should return an error if
451 * it isn't able to do so.
452 *
453 * The caller of device_link_wait_for_supplier() is expected to call this once
454 * it's aware of potential suppliers becoming available.
455 */
456static void device_link_check_waiting_consumers(void)
457{
458 struct device *dev, *tmp;
459
460 mutex_lock(&wfs_lock);
461 list_for_each_entry_safe(dev, tmp, &wait_for_suppliers,
462 links.needs_suppliers)
463 if (!dev->bus->add_links(dev))
464 list_del_init(&dev->links.needs_suppliers);
465 mutex_unlock(&wfs_lock);
466}
467
468static void device_link_free(struct device_link *link)421static void device_link_free(struct device_link *link)
469{422{
470 while (refcount_dec_not_one(&link->rpm_active))423 while (refcount_dec_not_one(&link->rpm_active))
@@ -599,19 +552,6 @@ int device_links_check_suppliers(struct device *dev) · 128 unmodified lines
599 struct device_link *link;552 struct device_link *link;
600 int ret = 0;553 int ret = 0;
601 554
602 /*
603 * If a device is waiting for one or more suppliers (in
604 * wait_for_suppliers list), it is not ready to probe yet. So just
605 * return -EPROBE_DEFER without having to check the links with existing
606 * suppliers.
607 */
608 mutex_lock(&wfs_lock);
609 if (!list_empty(&dev->links.needs_suppliers)) {
610 mutex_unlock(&wfs_lock);
611 return -EPROBE_DEFER;
612 }
613 mutex_unlock(&wfs_lock);
614
615 device_links_write_lock();555 device_links_write_lock();
616 556
617 list_for_each_entry(link, &dev->links.suppliers, c_node) {557 list_for_each_entry(link, &dev->links.suppliers, c_node) {
@@ -896,10 +836,6 @@ static void device_links_purge(struct device *dev) · 278 unmodified lines
896{836{
897 struct device_link *link, *ln;837 struct device_link *link, *ln;
898 838
899 mutex_lock(&wfs_lock);
900 list_del(&dev->links.needs_suppliers);
901 mutex_unlock(&wfs_lock);
902
903 /*839 /*
904 * Delete all of the remaining links from this device to any other840 * Delete all of the remaining links from this device to any other
905 * devices (either consumers or suppliers).841 * devices (either consumers or suppliers).
@@ -1764,7 +1700,6 @@ void device_initialize(struct device *dev) · 858 unmodified lines
1764#endif1700#endif
1765 INIT_LIST_HEAD(&dev->links.consumers);1701 INIT_LIST_HEAD(&dev->links.consumers);
1766 INIT_LIST_HEAD(&dev->links.suppliers);1702 INIT_LIST_HEAD(&dev->links.suppliers);
1767 INIT_LIST_HEAD(&dev->links.needs_suppliers);
1768 dev->links.status = DL_DEV_NO_DRIVER;1703 dev->links.status = DL_DEV_NO_DRIVER;
1769}1704}
1770EXPORT_SYMBOL_GPL(device_initialize);1705EXPORT_SYMBOL_GPL(device_initialize);
@@ -2251,24 +2186,6 @@ int device_add(struct device *dev) · 480 unmodified lines
2251 BUS_NOTIFY_ADD_DEVICE, dev);2186 BUS_NOTIFY_ADD_DEVICE, dev);
2252 2187
2253 kobject_uevent(&dev->kobj, KOBJ_ADD);2188 kobject_uevent(&dev->kobj, KOBJ_ADD);
2254
2255 /*
2256 * Check if any of the other devices (consumers) have been waiting for
2257 * this device (supplier) to be added so that they can create a device
2258 * link to it.
2259 *
2260 * This needs to happen after device_pm_add() because device_link_add()
2261 * requires the supplier be registered before it's called.
2262 *
2263 * But this also needs to happe before bus_probe_device() to make sure
2264 * waiting consumers can link to it before the driver is bound to the
2265 * device and the driver sync_state callback is called for this device.
2266 */
2267 device_link_check_waiting_consumers();
2268
2269 if (dev->bus && dev->bus->add_links && dev->bus->add_links(dev))
2270 device_link_wait_for_supplier(dev);
2271
2272 bus_probe_device(dev);2189 bus_probe_device(dev);
2273 if (parent)2190 if (parent)
2274 klist_add_tail(&dev->p->knode_parent,2191 klist_add_tail(&dev->p->knode_parent,
include/linux/device.h+0−14
@@ -78,17 +78,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); · 77 unmodified lines
78 * -EPROBE_DEFER it will queue the device for deferred probing.78 * -EPROBE_DEFER it will queue the device for deferred probing.
79 * @uevent: Called when a device is added, removed, or a few other things79 * @uevent: Called when a device is added, removed, or a few other things
80 * that generate uevents to add the environment variables.80 * that generate uevents to add the environment variables.
81 * @add_links: Called, perhaps multiple times per device, after a device is
82 * added to this bus. The function is expected to create device
83 * links to all the suppliers of the input device that are
84 * available at the time this function is called. As in, the
85 * function should NOT stop at the first failed device link if
86 * other unlinked supplier devices are present in the system.
87 *
88 * Return 0 if device links have been successfully created to all
89 * the suppliers of this device. Return an error if some of the
90 * suppliers are not yet available and this function needs to be
91 * reattempted in the future.
92 * @probe: Called when a new device or driver add to this bus, and callback81 * @probe: Called when a new device or driver add to this bus, and callback
93 * the specific driver's probe to initial the matched device.82 * the specific driver's probe to initial the matched device.
94 * @remove: Called when a device removed from this bus.83 * @remove: Called when a device removed from this bus.
@@ -133,7 +122,6 @@ struct bus_type { · 38 unmodified lines
133 122
134 int (*match)(struct device *dev, struct device_driver *drv);123 int (*match)(struct device *dev, struct device_driver *drv);
135 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);124 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
136 int (*add_links)(struct device *dev);
137 int (*probe)(struct device *dev);125 int (*probe)(struct device *dev);
138 int (*remove)(struct device *dev);126 int (*remove)(struct device *dev);
139 void (*shutdown)(struct device *dev);127 void (*shutdown)(struct device *dev);
@@ -1143,13 +1131,11 @@ enum dl_dev_state { · 1003 unmodified lines
1143 * struct dev_links_info - Device data related to device links.1131 * struct dev_links_info - Device data related to device links.
1144 * @suppliers: List of links to supplier devices.1132 * @suppliers: List of links to supplier devices.
1145 * @consumers: List of links to consumer devices.1133 * @consumers: List of links to consumer devices.
1146 * @needs_suppliers: Hook to global list of devices waiting for suppliers.
1147 * @status: Driver status information.1134 * @status: Driver status information.
1148 */1135 */
1149struct dev_links_info {1136struct dev_links_info {
1150 struct list_head suppliers;1137 struct list_head suppliers;
1151 struct list_head consumers;1138 struct list_head consumers;
1152 struct list_head needs_suppliers;
1153 enum dl_dev_state status;1139 enum dl_dev_state status;
1154};1140};
1155 1141

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t