Skip to contentSkip to conversation

scsi: sd: Fix unsigned expression compared with zero

PATCH Superseded Jiapeng Chong 3 participants 4 messages Jul 1, 2024 – Jul 2, 2024 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sd: Fix unsigned expression compared with zero

The return value from the call to scsi_execute_cmd() is int. However, the return value is being assigned to an unsigned int variable 'the_result', so making 'the_result' an int.

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

---
 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 5 lines · Jiapeng Chong

The return value from the call to scsi_execute_cmd() is int. However, the return value is being assigned to an unsigned int variable 'the_result', so making 'the_result' an int.

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

Since this is a bug fix, please add Cc: stable and Fixes: tags.

Thanks,

Bart.

#2 lore raw
In reply to Jiapeng Chong
Quoted 3 lines · Jiapeng Chong

The return value from the call to scsi_execute_cmd() is int. However, the return value is being assigned to an unsigned int variable 'the_result', so making 'the_result' an int.

Please explain the full effect of this patch in the patch description. I think this patch causes a potential read of uninitialized data (sshdr) to be skipped if scsi_execute_cmd() returns a negative value. Do you agree with this?

Thanks,

Bart.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jiapeng Chong

This title should really be more precise, like "Fix unsigned expression compared with zero in sd_spinup_disk()"

On 01/07/2024 10:06, Jiapeng Chong wrote:

+ Mike

Quoted 3 lines

The return value from the call to scsi_execute_cmd() is int. However, the return value is being assigned to an unsigned int variable 'the_result', so making 'the_result' an int.

an "so making 'the_result' effectively an unsigned int", right?

Quoted 6 lines

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

Looks ok, but Mike can hopefully double-check:

Quoted 17 lines
---
  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 */