[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260107175548.1792-2-guojinhui.liam@bytedance.com>
Date: Thu, 8 Jan 2026 01:55:46 +0800
From: "Jinhui Guo" <guojinhui.liam@...edance.com>
To: <dakr@...nel.org>, <alexander.h.duyck@...ux.intel.com>,
<alexanderduyck@...com>, <bhelgaas@...gle.com>, <bvanassche@....org>,
<dan.j.williams@...el.com>, <gregkh@...uxfoundation.org>,
<helgaas@...nel.org>, <rafael@...nel.org>, <tj@...nel.org>
Cc: <guojinhui.liam@...edance.com>, <linux-kernel@...r.kernel.org>,
<linux-pci@...r.kernel.org>
Subject: [PATCH 1/3] driver core: Introduce helper function __device_attach_driver_scan()
Introduce a helper to eliminate duplication between
__device_attach() and __device_attach_async_helper();
a later patch will reuse it to add NUMA-node awareness
to the synchronous probe path in __device_attach().
No functional changes.
Signed-off-by: Jinhui Guo <guojinhui.liam@...edance.com>
---
drivers/base/dd.c | 71 ++++++++++++++++++++++++++---------------------
1 file changed, 40 insertions(+), 31 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 349f31bedfa1..896f98add97d 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -962,6 +962,44 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
return ret == 0;
}
+static int __device_attach_driver_scan(struct device_attach_data *data,
+ bool *need_async)
+{
+ int ret = 0;
+ struct device *dev = data->dev;
+
+ if (dev->parent)
+ pm_runtime_get_sync(dev->parent);
+
+ ret = bus_for_each_drv(dev->bus, NULL, data,
+ __device_attach_driver);
+ /*
+ * When running in an async worker, a NULL need_async is passed
+ * since we are already in an async worker.
+ */
+ if (need_async && !ret && data->check_async && data->have_async) {
+ /*
+ * If we could not find appropriate driver
+ * synchronously and we are allowed to do
+ * async probes and there are drivers that
+ * want to probe asynchronously, we'll
+ * try them.
+ */
+ dev_dbg(dev, "scheduling asynchronous probe\n");
+ get_device(dev);
+ *need_async = true;
+ } else {
+ if (!need_async)
+ dev_dbg(dev, "async probe completed\n");
+ pm_request_idle(dev);
+ }
+
+ if (dev->parent)
+ pm_runtime_put(dev->parent);
+
+ return ret;
+}
+
static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
{
struct device *dev = _dev;
@@ -982,16 +1020,8 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
if (dev->p->dead || dev->driver)
goto out_unlock;
- if (dev->parent)
- pm_runtime_get_sync(dev->parent);
+ __device_attach_driver_scan(&data, NULL);
- bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver);
- dev_dbg(dev, "async probe completed\n");
-
- pm_request_idle(dev);
-
- if (dev->parent)
- pm_runtime_put(dev->parent);
out_unlock:
device_unlock(dev);
@@ -1025,28 +1055,7 @@ static int __device_attach(struct device *dev, bool allow_async)
.want_async = false,
};
- if (dev->parent)
- pm_runtime_get_sync(dev->parent);
-
- ret = bus_for_each_drv(dev->bus, NULL, &data,
- __device_attach_driver);
- if (!ret && allow_async && data.have_async) {
- /*
- * If we could not find appropriate driver
- * synchronously and we are allowed to do
- * async probes and there are drivers that
- * want to probe asynchronously, we'll
- * try them.
- */
- dev_dbg(dev, "scheduling asynchronous probe\n");
- get_device(dev);
- async = true;
- } else {
- pm_request_idle(dev);
- }
-
- if (dev->parent)
- pm_runtime_put(dev->parent);
+ ret = __device_attach_driver_scan(&data, &async);
}
out_unlock:
device_unlock(dev);
--
2.20.1
Powered by blists - more mailing lists