Article View: linux.kernel.netdev
Article #13037[PATCH v2 08/19] driver core: Add a compatibility API for manual driver attachment
From: Leon Romanovsky
Date: Mon, 09 Nov 2026 07:33
Date: Mon, 09 Nov 2026 07:33
132 lines
11949 bytes
11949 bytes
From: Leon Romanovsky <leonro@nvidia.com>
Existing manual binding paths probe drivers under subsystem locks before
publishing their bindings. Normal attachment would add device locking to
these paths.
Add device_driver_attach_full() to preserve their serialization while
centralizing probe and binding cleanup. This compatibility API must not
be used in any new code: it prevents devices from using the device trust
authorization infrastructure. New code must use device_driver_attach().
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/base/dd.c | 74 +++++++++++++++++++++++++++++++++++++++++++++-----
include/linux/device.h | 2 ++
2 files changed, 69 insertions(+), 7 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 52123251965de..0f56c3d825731 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -526,6 +526,21 @@ static void driver_sysfs_remove(struct device *dev)
}
}
+static int __device_bind_driver(struct device *dev)
+{
+ int ret;
+
+ ret = driver_sysfs_add(dev);
+ if (ret) {
+ bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
+ return ret;
+ }
+
+ device_links_force_bind(dev);
+ driver_bound(dev);
+ return 0;
+}
+
/**
* device_bind_driver - bind a driver to one device.
* @dev: device.
@@ -542,19 +557,64 @@ static void driver_sysfs_remove(struct device *dev)
* Callers should prefer to use device_driver_attach() instead.
*/
int device_bind_driver(struct device *dev)
+{
+ return __device_bind_driver(dev);
+}
+EXPORT_SYMBOL_GPL(device_bind_driver);
+
+/**
+ * device_driver_attach_full - attach a driver using subsystem serialization
+ * @drv: driver to attach
+ * @dev: device to attach it to
+ *
+ * This compatibility API must not be used in any new code. It prevents
+ * devices from using the device trust authorization infrastructure.
+ * New code must use device_driver_attach().
+ *
+ * Callers must serialize attachment and removal using their subsystem's
+ * existing locks. This function does not acquire the device or parent lock.
+ * It calls the bus or driver probe callback and publishes the binding without
+ * performing the normal driver-core DMA, pinctrl or power-domain setup.
+ *
+ * Return: 0 on success, or a negative error before binding.
+ */
+int device_driver_attach_full(const struct device_driver *drv, struct device *dev)
{
int ret;
- ret = driver_sysfs_add(dev);
- if (!ret) {
- device_links_force_bind(dev);
- driver_bound(dev);
- }
+ if (!device_is_registered(dev) || dev->p->dead)
+ return -ENODEV;
+ if (dev->driver)
+ return -EBUSY;
+
+ device_set_driver(dev, drv);
+ if (dev->bus->probe)
+ ret = dev->bus->probe(dev);
else
- bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
+ ret = drv->probe(dev);
+ if (ret)
+ goto clear_driver;
+
+ ret = __device_bind_driver(dev);
+ if (ret)
+ goto bus_remove;
+
+ return 0;
+
+bus_remove:
+ if (dev->bus->remove)
+ dev->bus->remove(dev);
+ else
+ drv->remove(dev);
+clear_driver:
+ devres_release_all(dev);
+ device_set_driver(dev, NULL);
+ dev_set_drvdata(dev, NULL);
+ if (ret == -EPROBE_DEFER)
+ return -EAGAIN;
return ret;
}
-EXPORT_SYMBOL_GPL(device_bind_driver);
+EXPORT_SYMBOL_GPL(device_driver_attach_full);
static atomic_t probe_count = ATOMIC_INIT(0);
static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
diff --git a/include/linux/device.h b/include/linux/device.h
index 429e39f647cf9..42e966ebaa2d3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1314,6 +1314,8 @@ static inline void *dev_get_platdata(const struct device *dev)
*/
int __must_check device_driver_attach(const struct device_driver *drv,
struct device *dev);
+int __must_check device_driver_attach_full(const struct device_driver *drv,
+ struct device *dev);
int __must_check device_bind_driver(struct device *dev);
void device_release_driver(struct device *dev);
int __must_check device_attach(struct device *dev);
--
2.56.0
Technical Details
Message-ID:
<20261109-device-trust-core-v2-8-3b12d9a9f861@nvidia.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359084-linux-kernel-netdev=dewy.ruReferences:
<20261109-device-trust-core-v2-0-3b12d9a9f861@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359084-linux-kernel-netdev=dewy.ru From: leon@kernel.org (Leon Romanovsky) Newsgroups: linux.kernel.netdev Subject: [PATCH v2 08/19] driver core: Add a compatibility API for manual driver attachment Date: Mon, 9 Nov 2026 09:33:38 +0200 Organization: Usenet Network Message-ID: <20261109-device-trust-core-v2-8-3b12d9a9f861@nvidia.com> References: <20261109-device-trust-core-v2-0-3b12d9a9f861@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="299671"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:pQ/0a1vUp4M8hzSfUTSxc7FchHY= sha256:H51Zhp5GuOaFTZ767c02ymn9Le9zgah/9E0GfSAGmf0= sha1:WYdQSDURUDrmO47wO15M5yNvWus= sha256:CA/OxUyHTCDjoZHoRraVTHFYRaAPKoDmBXmtfYrLaVQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 0072E11370C; Mon, 9 Nov 2026 10:41:09 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.301 X-Spam-Status: No, score=-2.301 tagged_above=-9999 required=6.31 tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZHVpuyTk39Fu; Mon, 9 Nov 2026 10:41:06 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359084-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id EEA5D113705; Mon, 9 Nov 2026 10:40:55 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 6CECDA1110; Mon, 9 Nov 2026 07:37:46 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1794209684; b=E6MUcnd15JPJuJGqD4W8FhpMLL+4nHH7Z/jLBWHcREnWXrL4RvrYEsqm7CO7yWjlnQAM PrfqVlduaJ6ucZ3towQffnp6PA3V0jfG+N6VFkmrGmqLuVg7eAL26k3buT0BUFcdeWFws 9csjBx641KERzo5DuxEI52AySqFFbvme2nfNijW8AGFAauoQsGxCOUQ3L9t0+lUlENqbU nH2AmvxCY32NgWeji0OVje5gNK0fX3410Tzk4a5iMwSB8iBqjMQlvr2b6v0O1OEi0rRmd rpxoTj0X7TEPVWyKPLLe0sQND/q4CNvLk6fKGJoJIvRR4/JLTUawVt86VUnAfpesfzw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794209684; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type:X-Mailer: Content-Transfer-Encoding; bh=MpimnCg02HZciFk2g0S8/wZfNZukhRQXczEg3LroMuI=; b=G1lbNVZ+ac1opwcaLxW5AoV0o0XJoi92BWdCU/Ip4rBlitWtWYu9FZVMsMFD0wKKHB7A azhA5C6mRDSaoXfD33sqx+Tk/6+2SpAeSL3LUm6+Cc+qGXndsGmadHeIJNwR7sRl3z8kn qsaqXlCQph5VDGQQI6X102owcaaBq6ECQmLw/NN4wioOuhZRJ9s6z7qqx1yaY2lhRSfXl Pdc1DJXNm7M6PdhbNh8cmmKrQAGaSIwsjtTE4iWADLnrKhsMdzZINRyuXt2KssfRjY144 yc3a/hbpLh//mYUCvZRUlr5kf4mvhM6RsDt7BOOvmufeu7aJv5kixXUCwDw+PGAw8Lg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MKr63xQC; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EDC36071862; Mon, 9 Nov 2026 07:34:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MKr63xQC X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794209683; b=Y1Mpyyu/18XzItb0KBe1OmtIPfmqf62NNGBN32vETTb+ZXvqW5bwJ8qIC9TOpgSb1pN4 L/M6th77zj83FdwBGgjdQOkhY/aKAODw6VvupkwHDIN+IIusjpR4FNSlz6RMxEHOYAIm1 xu/UBeq81LxRadteuC29vCwVPIKFPpXDhaF2p2H0zWjgu5zxkrxzJtDGsXut4NTnaK5hD XX5fnmCMNw0f3IgJ+610R1tdCAHjpf5dVDSQfFdVF30OhVyX6SVTru30WMCaDkj3E16nr Vzrb+oonmQl7+m2hwJJa0HotFbvGgVFUSW4xvBIYjUs3nZZS1M6eLlFDnx4GPZrrY3g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794209683; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type:X-Mailer: Content-Transfer-Encoding; bh=MpimnCg02HZciFk2g0S8/wZfNZukhRQXczEg3LroMuI=; b=MQZ8IN8nL8er0qkiGpObIn1danznM2igVNBoi6zxn8kAx05lGpyPhvyiBYGY9wd2TiKk z85ctYbFIG/jXVJvAg7uxAmhsOavVvlDdZO172GlBhI5Cloj0xkgCR1U1K+vp0goO8PW/ 4LhSuw6iTVPTtsEWjIQLH9YMQFeoBm1dRoLW9lKSqLzFUCh1X8h15kwQ+hJPMG4ThxisT 9Sq+pbKiWx7yMFq7qLLhAY7HQjvcar6EZZHia3H+ywPpzdRzcDmp0jsDXpQjlc/KccSSt UqBcioA4TRFUpxyJMQzk3cQmiuhxY41Zl6W4nsXUBiT3TwbFK31NofVTIwzsj+yhyFw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MKr63xQC; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2972A60A6F7E; Mon, 9 Nov 2026 07:34:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0FD71F008A5; Mon, 9 Nov 2026 07:34:41 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794209682; bh=MpimnCg02HZciFk2g0S8/wZfNZukhRQXczEg3LroMuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MKr63xQCZG0Kx/uDf562/8osJmX+c3VIP3ZLP2fy+N3p2uMLmr261yWJN04SAid33 4qJxdMBJEuJjdAYJgwhRUQoVw6QBjlAGGjoc7Y54KLCCEhufLWIW048UgQ4IzodCVv wU6UbWG/JabptBOI2k3O1pXRAAZc3jfaVJ1HMHVghqwOsOIlcicfIxkciYOpZyn3mj QotY5+kzCshox9OAqzDTEATR1ApsmuZxkEzUdHzUfiOkCIjb/ySQqk81vs6EyoFaZo bdSaWl9jfQIvtVJDkJZBmj4xW209iqY7h7Bs68bjZ6U9e2NDfpuBJWxUOIjNVD6CXx F0QG94RhDBeWw== X-Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-input@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-pci@vger.kernel.org, iommu@lists.linux.dev, Jason Gunthorpe <jgg@ziepe.ca> X-Mailer: git-send-email 2.56.0 X-In-Reply-To: <20261109-device-trust-core-v2-0-3b12d9a9f861@nvidia.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Mailer: b4 0.15-dev-18f8f