Re: [PATCH v2] usb: uas: wait for pending commands before unbinding

From: Jiayi Li

Date: Tue Oct 27 2026 - 09:05:03 EST


Hi,

Thank you for the follow-up.

On Tue, Oct 27, 2026, Oliver Neukum wrote:
> Even if an error occured? Does it make sense to wish to complete
> commands that have failed while the driver is being unloaded.

I have changed the disconnect preparation to stop retries after
allocation or URB submission failures. After blocking the host, accepted
commands are marked with COMMAND_NO_RETRY. Commands needing a retry are
left for the existing cleanup, while other accepted commands can still
complete normally.

The wait now polls the command table, excluding commands left for cleanup,
rather than waiting for anchors that those commands may still occupy.

> Indeed, but shouldn't we cancel scan_work _before_ we even try to complete
> commands?

I have added cancel_work(&devinfo->scan_work) before blocking the host.
This cancels pending scan work without waiting for a running scan.

> Understood. We need a genuine cancellation code.

Is additional cancellation handling required for this change, or can
it be addressed separately?

> Yes, but that doesn't answer you why you are setting resetting
> only _after_ waiting for commands to complete.

resetting also suppresses normal completion processing:
uas_stat_cmplt() skips processing the received IU, and uas_data_cmplt()
skips uas_try_complete(). Setting it before the wait would therefore
prevent some accepted commands from completing normally.

During preparation, scsi_block_requests() prevents new commands from
being accepted while existing commands retain their completion paths.
I set resetting when the wait ends, including on timeout, before
unblocking the host.

> This answers it, but why do you unblock the device then at all?

The temporary SCSI host block needs to be released so queued requests and
requests issued during device removal can finish. For example,
sd_shutdown() may issue a synchronous cache flush. Leaving the host
blocked can leave that request waiting for dispatch.

With resetting already set, requests reaching that check in
uas_queuecommand_lck() are completed with DID_ERROR without submitting
new URBs. This restores the existing teardown behaviour after the
grace period.

Thanks,
Jiayi