Skip to content

Commit b2d2d7e

Browse files
yuan linyugregkh
authored andcommitted
usb: f_mass_storage: forbid async queue when shutdown happen
When write UDC to empty and unbind gadget driver from gadget device, it is possible that there are many queue failures for mass storage function. The root cause is mass storage main thread alaways try to queue request to receive a command from host if running flag is on, on platform like dwc3, if pull down called, it will not queue request again and return -ESHUTDOWN, but it not affect running flag of mass storage function. Check return code from mass storage function and clear running flag if it is -ESHUTDOWN, also indicate start in/out transfer failure to break loops. Cc: stable <stable@kernel.org> Signed-off-by: yuan linyu <yuanlinyu@hihonor.com> Reviewed-by: Alan Stern <stern@rowland.harvard.edu> Link: https://lore.kernel.org/r/20240123034829.3848409-1-yuanlinyu@hihonor.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f17c34f commit b2d2d7e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/usb/gadget/function/f_mass_storage.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,21 +545,37 @@ static int start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
545545

546546
static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
547547
{
548+
int rc;
549+
548550
if (!fsg_is_set(common))
549551
return false;
550552
bh->state = BUF_STATE_SENDING;
551-
if (start_transfer(common->fsg, common->fsg->bulk_in, bh->inreq))
553+
rc = start_transfer(common->fsg, common->fsg->bulk_in, bh->inreq);
554+
if (rc) {
552555
bh->state = BUF_STATE_EMPTY;
556+
if (rc == -ESHUTDOWN) {
557+
common->running = 0;
558+
return false;
559+
}
560+
}
553561
return true;
554562
}
555563

556564
static bool start_out_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
557565
{
566+
int rc;
567+
558568
if (!fsg_is_set(common))
559569
return false;
560570
bh->state = BUF_STATE_RECEIVING;
561-
if (start_transfer(common->fsg, common->fsg->bulk_out, bh->outreq))
571+
rc = start_transfer(common->fsg, common->fsg->bulk_out, bh->outreq);
572+
if (rc) {
562573
bh->state = BUF_STATE_FULL;
574+
if (rc == -ESHUTDOWN) {
575+
common->running = 0;
576+
return false;
577+
}
578+
}
563579
return true;
564580
}
565581

0 commit comments

Comments
 (0)