[PATCH 1/3] usb: uas: complete inflight commands on status URB error

From: Sarthak Kukreti

Date: Thu Nov 12 2026 - 21:19:46 EST


When a UAS device is unplugged while hub_wq is frozen during system
suspend, usb_disconnect() is deferred and sd_sync_cache() issues
SYNCHRONIZE_CACHE to the disconnected target. If the status URB fails in
uas_stat_cmplt() with a non-unlink error (such as -EPROTO, -EILSEQ,
-ETIME, or -ESHUTDOWN), uas_stat_cmplt() logs the error and frees the
URB without completing inflight commands, leaving SYNCHRONIZE_CACHE
pending until the 60s SCSI timeout and triggering the 25s DPM watchdog.

Complete inflight commands with DID_NO_CONNECT in uas_stat_cmplt() on
non-unlink status URB errors while not resetting, and unlink inflight
data URBs outside devinfo->lock. Preserve non-DID_OK host bytes in
uas_data_cmplt() when the unlinked data URB completes.

Signed-off-by: Sarthak Kukreti <sarthakkukreti@xxxxxxxxxx>
---
drivers/usb/storage/uas.c | 47 ++++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 265162981269..5aa369087295 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -310,9 +310,49 @@ static void uas_stat_cmplt(struct urb *urb)
bool success;

if (status) {
- if (status != -ENOENT && status != -ECONNRESET && status != -ESHUTDOWN)
+ if (status == -ENOENT || status == -ECONNRESET)
+ goto bail;
+ if (status != -ESHUTDOWN)
dev_err(&urb->dev->dev, "stat urb: status %d\n", status);
- goto bail;
+
+ spin_lock_irqsave(&devinfo->lock, flags);
+ if (devinfo->resetting)
+ goto out;
+
+ for (idx = 0; idx < devinfo->qdepth; idx++) {
+ cmnd = devinfo->cmnd[idx];
+ if (!cmnd)
+ continue;
+ cmdinfo = scsi_cmd_priv(cmnd);
+ if (!(cmdinfo->state & COMMAND_INFLIGHT))
+ continue;
+
+ if (cmdinfo->state & DATA_IN_URB_INFLIGHT)
+ data_in_urb = usb_get_urb(cmdinfo->data_in_urb);
+ if (cmdinfo->state & DATA_OUT_URB_INFLIGHT)
+ data_out_urb = usb_get_urb(cmdinfo->data_out_urb);
+ cmdinfo->state &= ~COMMAND_INFLIGHT;
+ set_host_byte(cmnd, DID_NO_CONNECT);
+ uas_try_complete(cmnd, __func__);
+
+ if (data_in_urb || data_out_urb) {
+ spin_unlock_irqrestore(&devinfo->lock, flags);
+ if (data_in_urb) {
+ usb_unlink_urb(data_in_urb);
+ usb_put_urb(data_in_urb);
+ data_in_urb = NULL;
+ }
+ if (data_out_urb) {
+ usb_unlink_urb(data_out_urb);
+ usb_put_urb(data_out_urb);
+ data_out_urb = NULL;
+ }
+ spin_lock_irqsave(&devinfo->lock, flags);
+ if (devinfo->resetting)
+ break;
+ }
+ }
+ goto out;
}

idx = be16_to_cpup(&iu->tag) - 1;
@@ -428,7 +468,8 @@ static void uas_data_cmplt(struct urb *urb)
uas_log_cmd_state(cmnd, "data cmplt err", status);
/* error: no data transfered */
scsi_set_resid(cmnd, sdb->length);
- set_host_byte(cmnd, DID_ERROR);
+ if (host_byte(cmnd->result) == DID_OK)
+ set_host_byte(cmnd, DID_ERROR);
} else {
scsi_set_resid(cmnd, sdb->length - urb->actual_length);
}
--
2.56.0.611.g1030f0b940-goog