Skip to contentSkip to conversation

scsi: core: Fix handling of SCMD_FAIL_IF_RECOVERING

PATCH In review Bart Van Assche 1 participant 2 messages Mar 25, 2024 – Apr 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: core: Fix handling of SCMD_FAIL_IF_RECOVERING

There is code in the SCSI core that sets the SCMD_FAIL_IF_RECOVERING flag but there is no code that clears this flag. Instead of only clearing SCMD_INITIALIZED in scsi_end_request(), clear all flags. It is never necessary to preserve any command flags inside scsi_end_request().

Fixes 310bcaef6d7e ("scsi: core: Support failing requests while recovering")
---
 drivers/scsi/scsi_lib.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/scsi_lib.c +3 -4
index ca48ba9a229a..2fc2b97777ca 100644
@@ -633,10 +633,9 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
 	if (blk_queue_add_random(q))
 		add_disk_randomness(req->q->disk);
 
-	if (!blk_rq_is_passthrough(req)) {
-		WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED));
-		cmd->flags &= ~SCMD_INITIALIZED;
-	}
+	WARN_ON_ONCE(!blk_rq_is_passthrough(req) &&
+		     !(cmd->flags & SCMD_INITIALIZED));
+	cmd->flags = 0;
 
 	/*
 	 * Calling rcu_barrier() is not necessary here because the
#1 lore raw
Quoted 20 lines · Bart Van Assche

There is code in the SCSI core that sets the SCMD_FAIL_IF_RECOVERING flag but there is no code that clears this flag. Instead of only clearing SCMD_INITIALIZED in scsi_end_request(), clear all flags. It is never necessary to preserve any command flags inside scsi_end_request().

Fixes 310bcaef6d7e ("scsi: core: Support failing requests while recovering")
---
  drivers/scsi/scsi_lib.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/scsi_lib.c +0 -0
index ca48ba9a229a..2fc2b97777ca 100644
@@ -633,10 +633,9 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
  	if (blk_queue_add_random(q))
  		add_disk_randomness(req->q->disk);
 

drivers/scsi/scsi_lib.c static bool scsi_end_request(struct request *req, blk_status_t error, · line 641

Quoted 10 lines
drivers/scsi/scsi_lib.c +3 -4
-	if (!blk_rq_is_passthrough(req)) {
-		WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED));
-		cmd->flags &= ~SCMD_INITIALIZED;
-	}
+	WARN_ON_ONCE(!blk_rq_is_passthrough(req) &&
+		     !(cmd->flags & SCMD_INITIALIZED));
+	cmd->flags = 0;
 
  	/*
  	 * Calling rcu_barrier() is not necessary here because the

Also for this patch, please help with reviewing this patch.

Thanks,

Bart.