Skip to contentSkip to conversation

scsi: sd: Fix an incorrect type in 'sd_spinup_disk()'

PATCH In review Jiapeng Chong 2 participants 2 messages Jul 9, 2024

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

PATCH v3 1/1 scsi: sd: Fix an incorrect type in 'sd_spinup_disk()'

The return value from the call to scsi_execute_cmd() is int. In the 'else if' branch of the function scsi_execute_cmd, it will return -EINVAL. But the type of "the_result" is "unsigned int", causing the error code to reverse. Modify the type of "the_result" to solve this problem.

The code featuring the_result as the return value of the function scsi_execute_cmd is as follows:

the_result = scsi_execute_cmd(sdkp->device, cmd, REQ_OP_DRV_IN, NULL, 0,

			      SD_TIMEOUT, sdkp->max_retries, &exec_args);

if (the_result > 0) {
...
}

./drivers/scsi/sd.c:2333:6-16: WARNING: Unsigned expression compared with zero: the_result > 0.

Fixes c1acf38cd11e ("scsi: sd: Have midlayer retry sd_spinup_disk() errors")

---
Changes in v3:
-Amend the commit message, Add "Fixes:" and "Cc: stable" tags.

 drivers/scsi/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sd.c +1 -1
index 979795dad62b..ade8c6cca295 100644
@@ -2396,7 +2396,7 @@ sd_spinup_disk(struct scsi_disk *sdkp)
 	static const u8 cmd[10] = { TEST_UNIT_READY };
 	unsigned long spintime_expire = 0;
 	int spintime, sense_valid = 0;
-	unsigned int the_result;
+	int the_result;
 	struct scsi_sense_hdr sshdr;
 	struct scsi_failure failure_defs[] = {
 		/* Do not retry Medium Not Present */
Signature · 1 line
2.20.1.7.g153144c
#1 lore raw
Quoted 1 line · Jiapeng Chong

The return value from the call to scsi_execute_cmd() is int. In the

             ^^^^^
              type
Quoted 3 lines

'else if' branch of the function scsi_execute_cmd, it will return -EINVAL. But the type of "the_result" is "unsigned int", causing the error code to reverse. Modify the type of "the_result" to solve this problem.

^^^^^^^

What is "reversing an error code"? Did you perhaps mean that the return value is changed from a negative integer to a positive integer?

Quoted 2 lines

./drivers/scsi/sd.c:2333:6-16: WARNING: Unsigned expression compared with zero: the_result > 0.

Doesn't this patch fix reading uninitialized data? If so, shouldn't that be mentioned in the patch description?

Quoted 1 line
Fixes c1acf38cd11e ("scsi: sd: Have midlayer retry sd_spinup_disk() errors")

Hmm ... that seems incorrect to me. Commit c1acf38cd11e changed the indentation of "the_result > 0" expressions but did not introduce these. Is this perhaps the commit that introduced the "the_result > 0"
expressions: ced202f7bd78 ("scsi: core: Stop using DRIVER_ERROR")?

Thanks,

Bart.