From nobody Mon Feb 9 16:17:12 2026 Received: from sg-1-100.ptr.blmpb.com (sg-1-100.ptr.blmpb.com [118.26.132.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6DC436BCF6 for ; Wed, 7 Jan 2026 17:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767808630; cv=none; b=RLfxGxGBmX8Qs/JwZ/WrSLWZQ/+JRnGilH0v8rEzrtWB6NUqB9csWSkR5iLPUi/yzI9dDRhgMocfAVufbwN+nNmSl3yQYklQYccJuPV+hcN4A3HC0/U3oCj8Ahj6oPFOyDsyJo8n1nyClnlBNjqg7QzjyepR4KMQfZhynXW2oRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767808630; c=relaxed/simple; bh=ZYug4yNuU4av7KeoafX84stshFAma87Mg8qQ3P2JQKk=; h=References:Mime-Version:In-Reply-To:Cc:Message-Id:Content-Type: From:Subject:Date:To; b=Y7ZndCxubWfdwxVlArZb9Y1/Va9h4Cc9CNh1kPuqbUCOX4yJN9bTVDGOg+kPfxdEGdr+/cwy7FDW1ccX7ddYU7ojZK20DeE1H3DlB0U+qgSW717Xr8atEYrU+Q6MElitbbCa1Jss1ylgh8+LPzGSsBpDwE74sNbt+sw8BDi1pe8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=qfDtnwS+; arc=none smtp.client-ip=118.26.132.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="qfDtnwS+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1767808621; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=3lqZAckEjBHvH7t1Qq0KweacFxTKdPPI8/L7We/Rsrw=; b=qfDtnwS+ohbPccRDv/69ufj6qlXMhnB4FxeGzE8dVQWZJEA2A5Hl1kkFDfZwQQD6LiXGwk 44SxyfoPLaxN2zPsVI9ypKC/VlQxVeC+1t6FY5OWu7uCwLJfGc+DZqoCWtjT5C7K9NjR7n M8nLHtWXS9Vk6w3awho+dV63Vclqst2Yltp+pnW2HWEYK+wzGJNqQH4IM4ehx7saXrKixJ OhQE2e4a+6uExv0qrhcQ4YYlI+Qmb+RoGxKSiU6JcYdUMUQwhh0g2CvkmfSuyHa+ducLlR VjQw/1QdVCMdD4ANyBPk40HpC7Bz0WgR3RNQED4uuX6k58g/UHazRQg4gffuxQ== X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable References: <20260107175548.1792-1-guojinhui.liam@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260107175548.1792-1-guojinhui.liam@bytedance.com> Cc: , , Message-Id: <20260107175548.1792-2-guojinhui.liam@bytedance.com> From: "Jinhui Guo" Subject: [PATCH 1/3] driver core: Introduce helper function __device_attach_driver_scan() Date: Thu, 8 Jan 2026 01:55:46 +0800 X-Original-From: Jinhui Guo To: , , , , , , , , , Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Danilo Krummrich --- 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 =3D=3D 0; } =20 +static int __device_attach_driver_scan(struct device_attach_data *data, + bool *need_async) +{ + int ret =3D 0; + struct device *dev =3D data->dev; + + if (dev->parent) + pm_runtime_get_sync(dev->parent); + + ret =3D 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 =3D 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 =3D _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; =20 - if (dev->parent) - pm_runtime_get_sync(dev->parent); + __device_attach_driver_scan(&data, NULL); =20 - 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); =20 @@ -1025,28 +1055,7 @@ static int __device_attach(struct device *dev, bool = allow_async) .want_async =3D false, }; =20 - if (dev->parent) - pm_runtime_get_sync(dev->parent); - - ret =3D 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 =3D true; - } else { - pm_request_idle(dev); - } - - if (dev->parent) - pm_runtime_put(dev->parent); + ret =3D __device_attach_driver_scan(&data, &async); } out_unlock: device_unlock(dev); --=20 2.20.1