From: James Clark <jjc@jclark.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>
Cc: Johan Hovold <johan@kernel.org>,
Bastien Nocera <hadess@hadess.net>,
Matthias Kaehlcke <mka@chromium.org>,
Arnd Bergmann <arnd@arndb.de>,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Douglas Anderson <dianders@chromium.org>,
Robert Nelson <robertcnelson@gmail.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-gpio@vger.kernel.org, regressions@lists.linux.dev
Subject: [PATCH v3 1/2] usb: core: clean up before handing a device to the generic driver
Date: Tue, 3 Nov 2026 10:34:12 +0700 [thread overview]
Message-ID: <74b3f919f214a8ece24161a2c904d8a5744b703e.1793669297.git.jjc@jclark.com> (raw)
In-Reply-To: <cover.1793669297.git.jjc@jclark.com>
When a USB device driver's probe returns -ENODEV, usb_probe_device()
hands the device to the generic driver. It does not first undo what it
did before calling the probe. This causes two problems.
First, if the driver sets generic_subclass, the generic probe has
already run. It configured the device and sent a USB_DEVICE_ADD
notification. The generic driver then does both again. Notifier users
such as the usbport LED trigger see two USB_DEVICE_ADDs with no
USB_DEVICE_REMOVE in between.
Second, if the driver does not set supports_autosuspend, a runtime PM
reference was taken before the probe. Nothing drops it, so the device
can never be runtime suspended.
Clean up before handing the device over, in the same way as
usb_unbind_device() does when a driver is unbound: first, for a driver
that sets generic_subclass, call usb_generic_driver_disconnect();
second, for a driver that does not set supports_autosuspend, drop the
runtime PM reference with usb_autosuspend_device().
This leaves one limitation. Until the generic driver binds, the device
has no driver. If it is runtime suspended in that time, it can't be
resumed. This is transient: the generic driver resumes the device when
it binds.
This change does not alter what happens when the probe fails with any
other error. The device stays configured, so its interfaces keep
working. It keeps the runtime PM reference, because a device without a
driver can't be resumed. Its USB_DEVICE_ADD stays unpaired, because
sending USB_DEVICE_REMOVE would mean unconfiguring the device.
Fixes: 88b7381a939d ("USB: Select better matching USB drivers when available")
Signed-off-by: James Clark <jjc@jclark.com>
---
drivers/usb/core/driver.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index d3a61ebc6afb..9b8cd0e4219e 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -295,6 +295,10 @@ static int usb_probe_device(struct device *dev)
error = -EINVAL;
if (error == -ENODEV && udriver != &usb_generic_driver &&
(udriver->id_table || udriver->match)) {
+ if (udriver->generic_subclass)
+ usb_generic_driver_disconnect(udev);
+ if (!udriver->supports_autosuspend)
+ usb_autosuspend_device(udev);
udev->use_generic_driver = 1;
return -EPROBE_DEFER;
}
--
2.56.0
next prev parent reply other threads:[~2026-11-03 3:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 3:34 [PATCH v3 0/2] usb: core: fix failed device driver probes, add pre_probe James Clark
2026-11-03 3:34 ` James Clark [this message]
2026-11-05 20:30 ` [PATCH v3 1/2] usb: core: clean up before handing a device to the generic driver Alan Stern
2026-11-03 3:34 ` [PATCH v3 2/2] usb: core: add a pre_probe callback for device drivers that may defer James Clark
[not found] ` <sashiko-outbox-194542@kernel.org>
2026-11-03 5:39 ` James Clark
2026-11-05 20:31 ` Alan Stern
2026-11-23 11:37 ` [PATCH v3 0/2] usb: core: fix failed device driver probes, add pre_probe Thorsten Leemhuis
2026-11-23 12:12 ` James Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74b3f919f214a8ece24161a2c904d8a5744b703e.1793669297.git.jjc@jclark.com \
--to=jjc@jclark.com \
--cc=arnd@arndb.de \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=hadess@hadess.net \
--cc=johan@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mka@chromium.org \
--cc=regressions@lists.linux.dev \
--cc=robertcnelson@gmail.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®