Article View: linux.kernel.netdev
Article #18706[PATCH v3 11/31] USB: Unwind interface claims after registration or binding failure
From: Leon Romanovsky
Date: Wed, 18 Nov 2026 19:26
Date: Wed, 18 Nov 2026 19:26
130 lines
12800 bytes
12800 bytes
From: Leon Romanovsky <leonro@nvidia.com>
A successful USB-audio control probe can claim unregistered playback and
capture interfaces. If playback registration fails, releasing its claim
alone leaves the card active, its disconnect callback returns immediately.
usb_set_configuration()
device_add(control)
usb_audio_probe()
snd_usb_create_streams()
snd_usb_create_stream(playback)
usb_driver_claim_interface(playback)
snd_usb_create_stream(capture)
usb_driver_claim_interface(capture)
device_add(playback) [fails]
Configuration removal skips unregistered claims and binding failure can
also clear dev->driver without disconnecting the claimant.
Release the failed claim, remove the configuration if sibling claims
remain, and disconnect unpublished claims before freeing interfaces or
dropping the module reference.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes: 86d30741e480f ("[PATCH] USB: Usbcore: Don't try to delete unregistered interfaces")
Fixes: c6a46696f97ff ("driver core: don't fail attaching the device if it cannot be bound")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/usb/core/driver.c | 3 ++-
drivers/usb/core/message.c | 41 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 3beed56fabf3d..e2a120c64f6e1 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -488,7 +488,8 @@ static int usb_unbind_interface(struct device *dev)
/* Already in altsetting 0 so skip Set-Interface.
* Just re-enable it without affecting the endpoint toggles.
*/
- usb_enable_interface(udev, intf, false);
+ if (!intf->unregistering)
+ usb_enable_interface(udev, intf, false);
} else if (!error && !intf->dev.power.is_prepared) {
r = usb_set_interface(udev, intf->altsetting[0].
desc.bInterfaceNumber, 0);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 306978caaf1ef..b2e5ed35a4a59 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1489,6 +1489,9 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
device_del(&interface->dev);
}
+ for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
+ usb_release_unregistered_interface(dev->actconfig->interface[i]);
+
/* Now that the interfaces are unbound, nobody should
* try to access them.
*/
@@ -2020,6 +2023,25 @@ int usb_set_wireless_status(struct usb_interface *iface,
}
EXPORT_SYMBOL_GPL(usb_set_wireless_status);
+static bool usb_has_claimant(struct usb_device *dev,
+ const struct device_driver *claimant)
+{
+ struct usb_host_config *config = dev->actconfig;
+ int i;
+
+ for (i = 0; i < config->desc.bNumInterfaces; i++) {
+ struct device *intf = &config->interface[i]->dev;
+ bool claimed;
+
+ device_lock(intf);
+ claimed = intf->driver == claimant;
+ device_unlock(intf);
+ if (claimed)
+ return true;
+ }
+ return false;
+}
+
/*
* usb_set_configuration - Makes a particular device setting be current
* @dev: the device whose configuration is being updated
@@ -2270,6 +2292,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
*/
for (i = 0; i < nintf; ++i) {
struct usb_interface *intf = cp->interface[i];
+ struct device_driver *claimant;
struct module *claim_owner;
if (intf->dev.of_node &&
@@ -2285,6 +2308,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
intf->cur_altsetting->desc.bInterfaceNumber);
device_enable_async_suspend(&intf->dev);
device_lock(&intf->dev);
+ claimant = intf->dev.driver;
claim_owner = xchg(&intf->claim_owner, NULL);
device_unlock(&intf->dev);
ret = device_add(&intf->dev);
@@ -2293,7 +2317,22 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
intf->unregistering = 1;
device_unlock(&intf->dev);
}
- module_put(claim_owner);
+ if (claimant && (ret || !intf->dev.driver) &&
+ usb_driver_release_refused_claim(intf, claimant)) {
+ bool unconfigure = usb_has_claimant(dev, claimant);
+
+ get_device(&intf->dev);
+ if (unconfigure)
+ usb_set_configuration(dev, -1);
+ module_put(claim_owner);
+ put_device(&intf->dev);
+ if (unconfigure) {
+ usb_autosuspend_device(dev);
+ return ret ? ret : -ENODEV;
+ }
+ } else {
+ module_put(claim_owner);
+ }
if (ret != 0) {
dev_err(&dev->dev, "device_add(%s) --> %d\n",
dev_name(&intf->dev), ret);
--
2.56.1
Technical Details
Message-ID:
<20261118-device-trust-core-v3-11-d655875c4bfb@nvidia.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366383-linux-kernel-netdev=dewy.ruReferences:
<20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366383-linux-kernel-netdev=dewy.ru From: leon@kernel.org (Leon Romanovsky) Newsgroups: linux.kernel.netdev Subject: [PATCH v3 11/31] USB: Unwind interface claims after registration or binding failure Date: Wed, 18 Nov 2026 21:26:41 +0200 Organization: Usenet Network Message-ID: <20261118-device-trust-core-v3-11-d655875c4bfb@nvidia.com> References: <20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2680733"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ChBcwJid/Z+Q9cYvnXT40lq9+tc= sha256:pii3T9ogn+o/nGlT5Nhcr3vKOVIKipMUYF7xTo+ap1o= sha1:1FfpofYzN39DkakksMRoQQrd9Lo= sha256:siYP8tOI6vUVEwy9KskbG31Lv13h4yrvwQLMeARS0e4= 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 C1B4B115398; Wed, 18 Nov 2026 22:29:48 +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 OuAkvW66j2Mx; Wed, 18 Nov 2026 22:29:46 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-366383-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 B425611536C; Wed, 18 Nov 2026 22:29:37 +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 A3E04127F9E; Wed, 18 Nov 2026 19:29:17 +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=1795030078; b=nQ49bOiwu16Dko02XFhxMX3CWKi7TI2wkN13Oorwu5CL7X2qBVydzQXkhfKBaxR3rr7r EnJf6mq5lny6ItnI1WjB8KcJ/9cyMoVz0cr+dmcZC804UIG8S9i4uTdT2stQjXNcEFiBC wqWJC0Od/If9vE3FLqr8rWT1dowm3EB0Y6Il2+Ip8BbbLBGZ42BvtprVZ6w5fS39jBX5F +Io2hrudbqUlplgBlmzy2vv/E0yKwSoBLJVGUDX/Ko45o8tS6w5jjdKgyytoc4kfYMELM TwG/1dqD4twE5K6bkoZdsoww0DJ8O7KPa2fe+GujJwFqQfu8mp9XeqpEyTXhmvIh26Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795030078; 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=anRl7XzxmWAd4I65xBnGqpxFVe3h8V+5KB72VF6S6NQ=; b=DSbTG2Znbtz5kOcgG8/ysPlsMemFWu7c6grsK51EcukO4lh21cczmLqMFMf95lpkqPJB iuRdqAo6odR06mMrdrvuUkvQFMFBKHvpLUpHzPIAUCPgfvOTzUcoC4hqeNi/OQXZouSEz EQoKOsu+HgCaOEI1SksLJg1KvvpG0vXF4x5haf8Tc46IbzMk0E9svMQrWZCztMhyYfd/u CbwG6Nyt9oS6JEmtpof2l4VhiNLbk2gaAxtEtd8lPoskG1MeYdYhsQ3OYUSILzkZmuXWD e+jATxc6mDh5iDqzmbBxSG0i2drHLLUEZ4+EUoB40HGM2AI9kLGYoJKGOtf6EZpZBtA== 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="e/eyfjil"; 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 D6613606C710; Wed, 18 Nov 2026 19:27:58 +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=e/eyfjil 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=1795030078; b=tCLDYYrC6gbIvMsybsDQrQZONgU++BFzm2vPAYQtcJ3e/h5wCiYD9tkQDdfft4SqN2La qelWx8vmkGEXY58yt3vpLM4VkdKVePOrI6EoUSBhlP7ZX3uv4Crc4/QxJ8QLUh63RAvQ+ wUNaUUy+VxU84DfnTw2MiirCQeUwjbcCmMeK6012w+vdmzD10scYYyrsdAJ9jzN5JPk5h 9Mmit8z6a1hD6FxsQ4gJqf5nN+PxWq/tG8uefI3YVJGwHTUeJizHs4CmRLpru8o6M29Vh lYKxbO3F87sCC2ddqnnE72b48JSRBr3T2dHNzIWERkfkXLCQmz0d8AUiHf9uDKL4z5Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795030078; 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=anRl7XzxmWAd4I65xBnGqpxFVe3h8V+5KB72VF6S6NQ=; b=eDMeOB2p6by1ukgaurpwRK/RYiymCOwTPNTNhIRjtUGnHcP217oTe5AhEGjsbHntCsjJ h09WSnVUdYkyhER5pw8mG9ae8V2EiCcFg5Sed2hlssT6iNg0VC+dsb4r37ulxFgjGKH1r EtcRy36F2rVRdeDja1f1OVocbHO1dlp7c0VxsuroPIfvVYLzUbRlkkDjhtSQF0qBtDcu4 1PcFqfNaD6HEkkoxmObGWi7tMWk3xXUFHfdaO3tT74xC9krDyWiVodhZsZP3BW1bShwwv viICwoBAvdQBCddKheph0rDuSAB5Uh/tBWOpr55c/RCaw+vjYQS/tGdZfqp81/dJSVg== 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="e/eyfjil"; 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 F07F1606BB7F; Wed, 18 Nov 2026 19:27:57 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2B6A1F000CA; Wed, 18 Nov 2026 19:27:56 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795030077; bh=anRl7XzxmWAd4I65xBnGqpxFVe3h8V+5KB72VF6S6NQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e/eyfjilUUstnvPzcYoDzASy0RPKzQsGaViyRBBOGePQ+Iuxs73dYZ5tDM+NmiNtK +/D+Z8ufPIGyqcHz+FnMlOvbzd/o6X14iLkhfhKwjsiOHhyHSDODYnduZEEmfPcI96 NsryVnKHLf9WzxdC2LVJbYlyPFn/LBpgN/sFRUi2B6UQDrfPabGCNNMLZUxsIklzAS ibHYfRAGALN/EGQE+GoL/8gisbKLvL4EfyuNGCYrGfmDWdoad95d4hNQlEhMv9HT1e xDEdmeO9RBo741cwzNyjqtZLFbiep8sCpCsvD+Ezq8rvTR8nTQP1f/L4HNYV0f0JRA 24/Ma14tSgc/Q== 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: <20261118-device-trust-core-v3-0-d655875c4bfb@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