summaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorSaravana Kannan <saravanak@google.com>2019-10-29 01:00:23 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-11-02 20:05:17 +0300
commitbcbbcfd57247f4c2976055995e5760fb576aae1e (patch)
treecb6db68c1ef8083ff8eb7899b2fd6d1a1dbce94c /drivers/base
parent05ef983e0d65a31b370a4e1b93c1efd490ae778f (diff)
downloadlinux-bcbbcfd57247f4c2976055995e5760fb576aae1e.tar.xz
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 <saravanak@google.com> Link: https://lore.kernel.org/r/20191028220027.251605-3-saravanak@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/core.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 17ed054c4132..48cd43a91ce6 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -480,13 +480,25 @@ EXPORT_SYMBOL_GPL(device_link_add);
* This function is NOT meant to be called from the probe function of the
* consumer but rather from code that creates/adds the consumer device.
*/
-static void device_link_wait_for_supplier(struct device *consumer)
+static void device_link_wait_for_supplier(struct device *consumer,
+ bool need_for_probe)
{
mutex_lock(&wfs_lock);
list_add_tail(&consumer->links.needs_suppliers, &wait_for_suppliers);
+ consumer->links.need_for_probe = need_for_probe;
mutex_unlock(&wfs_lock);
}
+static void device_link_wait_for_mandatory_supplier(struct device *consumer)
+{
+ device_link_wait_for_supplier(consumer, true);
+}
+
+static void device_link_wait_for_optional_supplier(struct device *consumer)
+{
+ device_link_wait_for_supplier(consumer, false);
+}
+
/**
* device_link_add_missing_supplier_links - Add links from consumer devices to
* supplier devices, leaving any
@@ -656,7 +668,8 @@ int device_links_check_suppliers(struct device *dev)
* probe.
*/
mutex_lock(&wfs_lock);
- if (!list_empty(&dev->links.needs_suppliers)) {
+ if (!list_empty(&dev->links.needs_suppliers) &&
+ dev->links.need_for_probe) {
mutex_unlock(&wfs_lock);
return -EPROBE_DEFER;
}
@@ -760,6 +773,15 @@ void device_links_driver_bound(struct device *dev)
{
struct device_link *link;
+ /*
+ * If a device probes successfully, it's expected to have created all
+ * the device links it needs to or make new device links as it needs
+ * them. So, it no longer needs to wait on any suppliers.
+ */
+ mutex_lock(&wfs_lock);
+ list_del_init(&dev->links.needs_suppliers);
+ mutex_unlock(&wfs_lock);
+
device_links_write_lock();
list_for_each_entry(link, &dev->links.consumers, s_node) {
@@ -2393,7 +2415,7 @@ int device_add(struct device *dev)
if (fwnode_has_op(dev->fwnode, add_links)
&& fwnode_call_int_op(dev->fwnode, add_links, dev))
- device_link_wait_for_supplier(dev);
+ device_link_wait_for_mandatory_supplier(dev, true);
bus_probe_device(dev);
if (parent)