🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26332

[PATCH v5 20/33] USB: Drain usbfs when a device is unregistered

#26332
From: Leon Romanovsky
Date: Thu, 03 Dec 2026 12:03
73 lines
10780 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 1491ba015bcd..a881f06361bf 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 199d3f535a89..372bd6368cc9 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 1b2de58fd6ce..cbee73183747 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: <20261203-device-trust-core-v5-20-485cc6eddd46@nvidia.com>
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376554-linux-kernel-netdev=dewy.ru
References: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376554-linux-kernel-netdev=dewy.ru
From: leon@kernel.org (Leon Romanovsky)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v5 20/33] USB: Drain usbfs when a device is unregistered
Date: Thu,  3 Dec 2026 14:03:42 +0200
Organization: Usenet Network
Message-ID: <20261203-device-trust-core-v5-20-485cc6eddd46@nvidia.com>
References: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2481093"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3tM4Yr3bH3yJMFA1EXqpH87ZeaY= sha256:znIhw2OPEoF44d44FLcL2mi2EuPFURQ9DSK+2LDZRYg=
	sha1:7sP3miZxX9NalNoYmTaB1NspVYg= sha256:gB98Nycbh9+QpNQ6gIgJtMI0N06ZTZK1d8sUonhz268=
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 75B1D117914; Thu,  3 Dec 2026 15:08:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.64
X-Spam-Status: No, score=-2.64 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DKIMWL_WL_HIGH=-0.24, 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 ItDPatArG2f5;
	Thu,  3 Dec 2026 15:08:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376554-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 04AD911790F; Thu,  3 Dec 2026 15:08:19 +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 8F8BF2C682; Thu,  3 Dec 2026 12:07:35 +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=1796299508;
	b=IT7Sl9Lkb5yP/wXg06Yv9tctRLOeQEPrr8ksS7+dqrREdVmt7dws9T56xmtLfPRSnJie
	 xMnL3zPNtiQbeoyjVn4hi/ytDVP0cNi2GGv/KPiW2wvX4Rs7OsRvBgUPU7+n/YFC0QLaP
	 9cTcQWDTJ6qSgzMKqFTeUZD0ViBBhK/2sj7/jsOjZh7hqtm3xAF/o0dCJMW77LCqVRLeC
	 idGI7xfz6W+GdnUnj3RFtz2HpxFxlXxcXlPYF74vCWPY+7dWJc/aU2VO3o4OP2lAy/2Vt
	 0KEMTImX4NH88xbQbjWLX0dcykpPafMzvrAF2VvPXvuZ19EEU1ILSKjeli4s5sl7SGQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796299508;
	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=WCIQAzfZxk+3wH9rDl/boTJuHKegfsbvJfOLIy6r3VI=;
	b=JSXCLKT4wCEvnzL/DtUP68rhsvmZHodqKAFLXQjMx1+qzJ9YpHLM+r1UIZlJh68OxfGR
	 ekWV/zdTw65o5LMpg22nKWWHXtznExtbd8FnrkuFz42mJZfrreHX95xcrp8XihU7W3hzJ
	 UwLCr41wGJ1pK9gLtzghb3sSWMxbNBr6IEB35dxRvnhJ0UzQbaA4uD/YWklptX/2MOI/y
	 BarEXpQZ49AUe69csW7reFSyprS75O/SUltJ6yTxqiF8w6HDEkX0NwcZGpwQ6ZC/I8ES4
	 lcWkkPBPPBus91lzMFTbMRUnKD+LPDMUCIM0y2JKXro4W5nOBtWceRqBodWg1ZILaXg==
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=C2n90U1A;
	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 8F6CB606AA5F;
	Thu,  3 Dec 2026 12:05:08 +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=C2n90U1A
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=1796299502;
	b=m6mlUvpJ5jOglzqe3Gd+CyM3f+AnoqFu/QOA7ejILTaE3RBMGvgH6ojeBeIbt+G+6Rhi
	 E+WSOrFeAu1FNQEo41Eb+pPIdMd4ZpexeQ/Ju3ArG7Di4GDNJEf8g/22w1xNKv2G0+cvr
	 c3H1yL5LFa6S8v/M49saBd88BKeKLJwlRsQDq4B4m7Xx5PmTDfYLobyaHn9AFrmbYrEMW
	 xDNFlfFsOhn5+pvRNsc4qRH72aOa10jE3AhlU95SN0SZ3CwzarjAahvi4DZpSNGLwAa0B
	 Wr4uquZEYTxzjE24tSpEgHn/oOq25XmfQjZGMo9wllYfKeqcths9NHDfZSaKblbJ/1w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796299502;
	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=WCIQAzfZxk+3wH9rDl/boTJuHKegfsbvJfOLIy6r3VI=;
	b=aUPylzYAVNHWFHQ0ukUCdgpf9wRbwWEpto5RPnpJA3sYRNQYbPazGYYGGzLThuv8Z0QQ
	 qB+75+3Y9WfcTAyVWpiMQHCBdqNXU9615OOjcMKNlFEI/uFLWYzehOq5WGjDnrm95dLDV
	 pAcCU+02Fd244+nN+uUnp+8MMfV5jjE0e7JJlBfwJV5BiQJq6/ejyO0p8xe21gZxAUqkr
	 uJYVfbmvO1sQnnd8CZ8o5qk4R7nuCm4sZHmKJYKdOtNvzvGowXhcUmy6g8hZB1eLHBjEt
	 toL5lCMNUJqXBmK7TOSAObrg94zNGnDto0QoaQI7jYW+usH3CXfUL5004+79Pd6yvhg==
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=C2n90U1A;
	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 AAA36606FD30;
	Thu,  3 Dec 2026 12:05:02 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB8D61F00893;
	Thu,  3 Dec 2026 12:05:01 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796299502;
	bh=WCIQAzfZxk+3wH9rDl/boTJuHKegfsbvJfOLIy6r3VI=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=C2n90U1AUiI/sEEZ27PzEDEVM+KRe+k/4ShjZebkJYAXcEPfiYKo5bPYDd2wZwFzm
	 TRhih5m846lP8IBIFQFHm95/9xw0sifCciZ8BSu6HJMySqdtaUc9//kKJL8qHAJrJJ
	 HV1XjlT8zjM1PH8ldCduyRJMPMmecQBiF/mKsG/Pt2+dNYcaWhzBIEA7jqex+s4ShU
	 Q6/+iJA2D6gJkFUa45ASnMaN6xb7F2Mdgm1/x3VsU/YvZQWo0W1C9DxSBU55y9Y58f
	 VXuJGgkyGunz2y93GP2IF833Lzwp0+zyzEOsES/SDQLYXekvm3C0CsqYpuzK3Cv2Xr
	 KZmdnmf5QXIYg==
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: <20261203-device-trust-core-v5-0-485cc6eddd46@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.17-dev-d2b70