From: "Jinhui Guo" <guojinhui.liam@bytedance.com>
To: <dakr@kernel.org>, <alexanderduyck@fb.com>, <bhelgaas@google.com>,
<bvanassche@acm.org>, <dan.j.williams@intel.com>,
<gregkh@linuxfoundation.org>, <helgaas@kernel.org>,
<rafael@kernel.org>, <tj@kernel.org>, <frederic@kernel.org>
Cc: <guojinhui.liam@bytedance.com>, <linux-kernel@vger.kernel.org>,
<linux-pci@vger.kernel.org>
Subject: [PATCH v2 1/3] driver core: Introduce helper function __device_attach_driver_scan()
Date: Thu, 22 Jan 2026 22:52:06 +0800 [thread overview]
Message-ID: <20260122145208.1013-2-guojinhui.liam@bytedance.com> (raw)
In-Reply-To: <20260122145208.1013-1-guojinhui.liam@bytedance.com>
The logic responsible for managing parent device PM
runtime (get/put), iterating over the bus drivers,and
determining if asynchronous probing is required is
currently duplicated between __device_attach() and
__device_attach_async_helper().
This patch factors out this common logic into a new
static helper function __device_attach_driver_scan().
This change reduces code duplication and improves
maintainability without altering the existing behavior.
Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
---
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 ed3a07624816..b6be95871d3d 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -964,6 +964,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;
@@ -984,16 +1022,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);
@@ -1027,28 +1057,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
next prev parent reply other threads:[~2026-01-22 14:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 14:52 [PATCH v2 0/3] Add NUMA-node-aware synchronous probing to driver core Jinhui Guo
2026-01-22 14:52 ` Jinhui Guo [this message]
2026-01-22 14:52 ` [PATCH v2 2/3] driver core: Add NUMA-node awareness to the synchronous probe path Jinhui Guo
2026-01-22 14:52 ` [PATCH v2 3/3] PCI: Clean up NUMA-node awareness in pci_bus_type probe Jinhui Guo
2026-01-24 1:04 ` [PATCH v2 0/3] Add NUMA-node-aware synchronous probing to driver core dan.j.williams
2026-01-26 9:17 ` Jinhui Guo
2026-01-27 2:32 ` Jinhui Guo
2026-01-27 3:37 ` dan.j.williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260122145208.1013-2-guojinhui.liam@bytedance.com \
--to=guojinhui.liam@bytedance.com \
--cc=alexanderduyck@fb.com \
--cc=bhelgaas@google.com \
--cc=bvanassche@acm.org \
--cc=dakr@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=frederic@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=helgaas@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®