Article View: linux.kernel.netdev
Article #21669[PATCH v4 20/33] USB: Drain usbfs when a device is unregistered
From: Leon Romanovsky
Date: Tue, 24 Nov 2026 09:43
Date: Tue, 24 Nov 2026 09:43
73 lines
10691 bytes
10691 bytes
From: Leon Romanovsky <leonro@nvidia.com>
Only the generic USB device driver tells usbfs that a device is gone.
A device without that driver bound, such as one unbound through sysfs,
is unplugged without any notification. usbdev_open() does not check for
a driver, so a process can open such a device and sleep in poll() on its
idle descriptor. The unplug never wakes it or sends its disconnect
signal.
Drain usbfs from usb_disconnect() before device_del(). The device is
already marked as not attached, so no new user can open it. The later
drain from the generic driver finds nothing left.
Fixes: 782da727b0d59 ("usbcore: make usb_generic a usb_device_driver")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/usb/core/devio.c | 4 ++--
drivers/usb/core/hub.c | 3 +++
drivers/usb/core/usb.h | 1 +
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 1491ba015bcd8..a881f06361bfa 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -2862,7 +2862,7 @@ const struct file_operations usbdev_file_operations = {
.release = usbdev_release,
};
-static void usbdev_remove(struct usb_device *udev)
+void usbfs_notify_remove(struct usb_device *udev)
{
struct usb_dev_state *ps;
@@ -2889,7 +2889,7 @@ static int usbdev_notify(struct notifier_block *self,
case USB_DEVICE_ADD:
break;
case USB_DEVICE_REMOVE:
- usbdev_remove(dev);
+ usbfs_notify_remove(dev);
break;
}
return NOTIFY_OK;
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 199d3f535a891..372bd6368cc94 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2379,6 +2379,9 @@ void usb_disconnect(struct usb_device **pdev)
if (udev->usb4_link)
device_link_del(udev->usb4_link);
+ /* usbfs is otherwise notified only by a bound generic driver */
+ usbfs_notify_remove(udev);
+
/* Unregister the device. The device driver is responsible
* for de-configuring the device and invoking the remove-device
* notifier chain (used by usbfs and possibly others).
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 1b2de58fd6cef..cbee731837471 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -195,6 +195,7 @@ extern const struct file_operations usbdev_file_operations;
extern int usb_devio_init(void);
extern void usb_devio_cleanup(void);
+void usbfs_notify_remove(struct usb_device *udev);
/*
* Firmware specific cookie identifying a port's location. '0' == no location
--
2.56.1
Technical Details
Message-ID:
<20261124-device-trust-core-v4-20-037eb0d17b1f@nvidia.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370188-linux-kernel-netdev=dewy.ruReferences:
<20261124-device-trust-core-v4-0-037eb0d17b1f@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370188-linux-kernel-netdev=dewy.ru From: leon@kernel.org (Leon Romanovsky) Newsgroups: linux.kernel.netdev Subject: [PATCH v4 20/33] USB: Drain usbfs when a device is unregistered Date: Tue, 24 Nov 2026 11:43:51 +0200 Organization: Usenet Network Message-ID: <20261124-device-trust-core-v4-20-037eb0d17b1f@nvidia.com> References: <20261124-device-trust-core-v4-0-037eb0d17b1f@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4104727"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:cGpZSmajYCM59k2/MyIv8NJXRWM= sha256:NkGq8dGpRIqS/oFYtPgqI0aLdUzV7vN8hjc74wG3TfM= sha1:XWmRLYALCTyax/t7TuDphy2xZqI= sha256:YPs2nTUH6hEXiELs0NmJkLzRryTQ2yZRIBnfSOvmbCs= 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 BEACF125DEB; Tue, 24 Nov 2026 12:48:44 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[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 Wq0i451BnaMr; Tue, 24 Nov 2026 12:48:42 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-370188-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 884B0125DE8; Tue, 24 Nov 2026 12:48:31 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 2E0E62D088; Tue, 24 Nov 2026 09:48:28 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795513575; b=jq/CWRvX80nSWM7RzPuiYtGdfcuUbT1oH/Wy0FG7ty/hWevMOD+r4SdgUnCEULmUcITF 5iDctTNA9iwgqbbHXwteRa2A4+zOsNtvUIBcZWxrQkdYHtXmC0AYkKf4VBRpapMteLh2Q JOwOxVY3UlDZvUNwJuLQ6QE1ODgK5NiJV7Joy+i+mkP8Um5w3qrWxegcglzX+A2XYIA9a HT0vGp/syut6xY+AnMvfpDs/gVSAVlP6pz7I1EbToMxyesTSCEgONhX4tyAMz+cZmBhHO bySUDz2peSLM1b0cHJCqVzJc+oZ3zTDxd7RDU4gxv8FF4Q/XsDlaSaojhkMnTvdxTgg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795513575; 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=0ocO3hzxDXP5J+wMv8np8RM3eAnwMTJFFeAUpb5CWAI=; b=wxe4fKpgQZOKOVJComYfpl/6M6u1N4jEE4JXsczO77LSTgwaxwf++b96QeTEUCglsiHb IxAlGBrMIT2TU7EYPwHGEGH7/EuMkTbY34lpDe7F/snfsVO4oZhtCCt5/E+HWNzQyy6ZN eoKKPiH/O2Khb1VlpU4vywYcKfITXiRkbCb1irX/ZSAr2XXrzsuYdj497KSPWvYxYzM6K 3xa8nXrNRK/6l0FcshyD1siFK37A1tnHZcMCINjvXrcrA0SXFCqlibFOfztqLg6oLezri T3j5f5xJrnFyggLiucJpybq0NLc6fP2hGvByE9K2Wckahey7tPoYxUvgBjirA6sKCAQ== 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=AtRBTbcF; arc=pass header.oldest-pass=0 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 74583607402F; Tue, 24 Nov 2026 09:46:15 +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=AtRBTbcF 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=1795513559; b=BQh6sH10T9yfYyGJVJ29jmHEYzBVlsOgzRcKPAFnh3jhbzLqxa1PSOGMkRnMWoWwd4av BhPThkJj7zZcurilANF6rt6GQdiqKBdWyrw0ITMchQTn11BreisIwfBGBrE32/jjWp1lG m8eNtWaAxcNPW5FGyQkcM5oY8bObgzYIL4SiMPWk/fO28bRtNPNC19GKHxDWWSPZQp9IA +YUWY956PA0G1rILcrmShgnPOmWJ4OUbjvJXOzgYduYhW5CE+/HaX7naOpgxUc6IEFF/B ilmcCXhdOw8/Ne9c80Muy7VcXS3xzxI7tBlGe6TRbTaeoOHKVTkefnQdADC8UpVXRcQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795513559; 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=0ocO3hzxDXP5J+wMv8np8RM3eAnwMTJFFeAUpb5CWAI=; b=x0H7YX5e/0dzv8pRGx4dVHVaInTJyWVCoisQk+FFzFKVbvSpmUnu+7LIaDuX6VBNdGC8 ff/nRh5UbBs5vo6Vr413oX2j+kEM4YIMMkplYGEc1nBVcFcPAbszUxahZRVcV0Kd1ViY9 rcpXVS9NNOA3CzD8TIyutwfZzVJ0mshXFP9lgQ5ewXcf7tVdUCmdtT7OpOe7VGsnaiuz0 68s0Y74T0Bylud+v2lGZkx2HzIg0tQHkNyHQfpbyY5fxMcugDN+MAYBwH6SNgjaTTjGYI owSyPQLw5+HZGoTqJ54aiK/KBc9R2WYylG72UUf8xcYLR+eKWiH2Hq/aL9dH0RBb/bQ== 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=AtRBTbcF; 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 82F75606B033; Tue, 24 Nov 2026 09:45:59 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69F391F000D4; Tue, 24 Nov 2026 09:45:58 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795513559; bh=0ocO3hzxDXP5J+wMv8np8RM3eAnwMTJFFeAUpb5CWAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AtRBTbcFtUyiPTchVF40SgM0rK31T4QwRREUs/Yc8+5PG+SU/7QMKuPH3fhhsLDjq 0KwoHAqW5wrwPaiMgSrMdD7uwRBlSWOXsCUUTkyrkyS6fQ58nZpB39E5RgeyIqVDjh ProYd+7lblyTrOA7lkRJ2HvBvL9BoxWNcv/gCzVOfs5W0qvc8OgBwbGmCEQAg2S85m p0F0pYMg44HEHOSEeJMvfw2da2/oCaRHp3ch6mz9LDsvXd7C/LL3dGdCw+ppeL4+eH v1tV0f0XZB5j7ckmku60Rwj4AAlp88jH2WXsLgHGN2EVGA4KUGBbgFBER4EmZGFL6T ctaAi8z6GXEww== 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, linux-coco@lists.linux.dev, Alexey Kardashevskiy <aik@amd.com>, Luiz Augusto von Dentz <luiz.von.dentz@intel.com>, Greg Kroah-Hartman <gregkh@suse.de>, linux-sound@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca> X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261124-device-trust-core-v4-0-037eb0d17b1f@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