From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 13/13] usb: storage: stop talking to a device that is gone
Date: Mon, 31 Aug 2026 15:20:20 +0200 [thread overview]
Message-ID: <20260831-usb-device-lifetime-v1-13-6adf4054b909@pengutronix.de> (raw)
In-Reply-To: <20260831-usb-device-lifetime-v1-0-6adf4054b909@pengutronix.de>
usb_stor_transport() retries a failed command ten times, and every
attempt runs usb_stor_Bulk_reset(), which issues three more control
transfers to the device. For a device that has been unplugged all of
these run into their timeouts, so a single read takes minutes and fills
the console with endpoint reset messages.
Now that the USB core notices that a device has been unplugged, check
for it: skip the reset, which cannot work without a device, and give up
instead of retrying. A read of an unplugged stick fails after the first
timeout and every further one fails immediately.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Assisted-by: Claude:claude-opus-5
---
drivers/usb/storage/transport.c | 4 ++++
drivers/usb/storage/usb.c | 7 +++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index be3b18dc66..bda8f93c7a 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -220,6 +220,10 @@ int usb_stor_Bulk_reset(struct us_data *us)
dev_dbg(dev, "%s called\n", __func__);
+ /* Nothing to reset if the device isn't there anymore */
+ if (usb_device_disconnected(us->pusb_dev))
+ return -ENODEV;
+
/* issue the command */
result = usb_control_msg(us->pusb_dev,
usb_sndctrlpipe(us->pusb_dev, 0),
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 7c19207a8d..55facf8a60 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -86,6 +86,13 @@ static int usb_stor_transport(struct us_blk_dev *usb_blkdev,
if (ret == USB_STOR_TRANSPORT_GOOD)
return 0;
+ /* Retrying is pointless once the device has been unplugged */
+ if (usb_device_disconnected(us->pusb_dev)) {
+ dev_dbg(dev, "%s: device is gone\n",
+ usb_stor_opcode_name(cmd[0]));
+ return -ENODEV;
+ }
+
if (request_sense_delay_ms == USB_STOR_NO_REQUEST_SENSE)
continue;
--
2.47.3
prev parent reply other threads:[~2026-08-31 13:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 13:20 [PATCH 00/13] USB: Make USB devices removable Sascha Hauer
2026-08-31 13:20 ` [PATCH 01/13] usb: don't report device removal after the device name is gone Sascha Hauer
2026-08-31 13:20 ` [PATCH 02/13] fs: devfs: count an open partition as an open device Sascha Hauer
2026-08-31 13:20 ` [PATCH 03/13] block: propagate errors from blockdevice_unregister() Sascha Hauer
2026-08-31 13:20 ` [PATCH 04/13] fs: add cdev_umount_all() Sascha Hauer
2026-08-31 13:20 ` [PATCH 05/13] block: add blockdevice_unregister_removed() Sascha Hauer
2026-08-31 13:20 ` [PATCH 06/13] usb: storage: tear the disk down properly on disconnect Sascha Hauer
2026-08-31 13:20 ` [PATCH 07/13] usb: hub: cancel pending port scans of a removed device Sascha Hauer
2026-08-31 13:20 ` [PATCH 08/13] usb: reuse the addresses of removed devices Sascha Hauer
2026-08-31 13:20 ` [PATCH 09/13] usb: hub: detect disconnected devices Sascha Hauer
2026-08-31 13:20 ` [PATCH 10/13] usb: don't keep a dangling root device on enumeration failure Sascha Hauer
2026-08-31 13:20 ` [PATCH 11/13] usb: hub: limit the number of ports to USB_MAXCHILDREN Sascha Hauer
2026-08-31 13:20 ` [PATCH 12/13] usb: detect unplugged devices on transfer errors Sascha Hauer
2026-08-31 13:20 ` Sascha Hauer [this message]
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=20260831-usb-device-lifetime-v1-13-6adf4054b909@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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