hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/usb/storage/scsiglue.c
....@@ -411,22 +411,25 @@
411411 ***********************************************************************/
412412
413413 /* Command timeout and abort */
414
-static int command_abort(struct scsi_cmnd *srb)
414
+static int command_abort_matching(struct us_data *us, struct scsi_cmnd *srb_match)
415415 {
416
- struct us_data *us = host_to_us(srb->device->host);
417
-
418
- usb_stor_dbg(us, "%s called\n", __func__);
419
-
420416 /*
421417 * us->srb together with the TIMED_OUT, RESETTING, and ABORTING
422418 * bits are protected by the host lock.
423419 */
424420 scsi_lock(us_to_host(us));
425421
426
- /* Is this command still active? */
427
- if (us->srb != srb) {
422
+ /* is there any active pending command to abort ? */
423
+ if (!us->srb) {
428424 scsi_unlock(us_to_host(us));
429425 usb_stor_dbg(us, "-- nothing to abort\n");
426
+ return SUCCESS;
427
+ }
428
+
429
+ /* Does the command match the passed srb if any ? */
430
+ if (srb_match && us->srb != srb_match) {
431
+ scsi_unlock(us_to_host(us));
432
+ usb_stor_dbg(us, "-- pending command mismatch\n");
430433 return FAILED;
431434 }
432435
....@@ -449,6 +452,14 @@
449452 return SUCCESS;
450453 }
451454
455
+static int command_abort(struct scsi_cmnd *srb)
456
+{
457
+ struct us_data *us = host_to_us(srb->device->host);
458
+
459
+ usb_stor_dbg(us, "%s called\n", __func__);
460
+ return command_abort_matching(us, srb);
461
+}
462
+
452463 /*
453464 * This invokes the transport reset mechanism to reset the state of the
454465 * device
....@@ -460,6 +471,9 @@
460471
461472 usb_stor_dbg(us, "%s called\n", __func__);
462473
474
+ /* abort any pending command before reset */
475
+ command_abort_matching(us, NULL);
476
+
463477 /* lock the device pointers and do the reset */
464478 mutex_lock(&(us->dev_mutex));
465479 result = us->transport_reset(us);