Skip to content

Commit bcbbcfd

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: Allow a device to wait on optional suppliers
Before this change, if a device is waiting on suppliers, it's assumed that all those suppliers are needed for the device to probe successfully. This change allows marking a devices as waiting only on optional suppliers. This allows a device to wait on suppliers (and link to them as soon as they are available) without preventing the device from being probed. Signed-off-by: Saravana Kannan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 05ef983 commit bcbbcfd

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

drivers/base/core.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,25 @@ EXPORT_SYMBOL_GPL(device_link_add);
480480
* This function is NOT meant to be called from the probe function of the
481481
* consumer but rather from code that creates/adds the consumer device.
482482
*/
483-
static void device_link_wait_for_supplier(struct device *consumer)
483+
static void device_link_wait_for_supplier(struct device *consumer,
484+
bool need_for_probe)
484485
{
485486
mutex_lock(&wfs_lock);
486487
list_add_tail(&consumer->links.needs_suppliers, &wait_for_suppliers);
488+
consumer->links.need_for_probe = need_for_probe;
487489
mutex_unlock(&wfs_lock);
488490
}
489491

492+
static void device_link_wait_for_mandatory_supplier(struct device *consumer)
493+
{
494+
device_link_wait_for_supplier(consumer, true);
495+
}
496+
497+
static void device_link_wait_for_optional_supplier(struct device *consumer)
498+
{
499+
device_link_wait_for_supplier(consumer, false);
500+
}
501+
490502
/**
491503
* device_link_add_missing_supplier_links - Add links from consumer devices to
492504
* supplier devices, leaving any
@@ -656,7 +668,8 @@ int device_links_check_suppliers(struct device *dev)
656668
* probe.
657669
*/
658670
mutex_lock(&wfs_lock);
659-
if (!list_empty(&dev->links.needs_suppliers)) {
671+
if (!list_empty(&dev->links.needs_suppliers) &&
672+
dev->links.need_for_probe) {
660673
mutex_unlock(&wfs_lock);
661674
return -EPROBE_DEFER;
662675
}
@@ -760,6 +773,15 @@ void device_links_driver_bound(struct device *dev)
760773
{
761774
struct device_link *link;
762775

776+
/*
777+
* If a device probes successfully, it's expected to have created all
778+
* the device links it needs to or make new device links as it needs
779+
* them. So, it no longer needs to wait on any suppliers.
780+
*/
781+
mutex_lock(&wfs_lock);
782+
list_del_init(&dev->links.needs_suppliers);
783+
mutex_unlock(&wfs_lock);
784+
763785
device_links_write_lock();
764786

765787
list_for_each_entry(link, &dev->links.consumers, s_node) {
@@ -2393,7 +2415,7 @@ int device_add(struct device *dev)
23932415

23942416
if (fwnode_has_op(dev->fwnode, add_links)
23952417
&& fwnode_call_int_op(dev->fwnode, add_links, dev))
2396-
device_link_wait_for_supplier(dev);
2418+
device_link_wait_for_mandatory_supplier(dev, true);
23972419

23982420
bus_probe_device(dev);
23992421
if (parent)

include/linux/device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,13 +1155,16 @@ enum dl_dev_state {
11551155
* @consumers: List of links to consumer devices.
11561156
* @needs_suppliers: Hook to global list of devices waiting for suppliers.
11571157
* @defer_sync: Hook to global list of devices that have deferred sync_state.
1158+
* @need_for_probe: If needs_suppliers is on a list, this indicates if the
1159+
* suppliers are needed for probe or not.
11581160
* @status: Driver status information.
11591161
*/
11601162
struct dev_links_info {
11611163
struct list_head suppliers;
11621164
struct list_head consumers;
11631165
struct list_head needs_suppliers;
11641166
struct list_head defer_sync;
1167+
bool need_for_probe;
11651168
enum dl_dev_state status;
11661169
};
11671170

0 commit comments

Comments
 (0)