* [PATCH] scsi: sd: Fix unsigned expression compared with zero
@ 2024-07-01 9:06 Jiapeng Chong
2024-07-01 16:50 ` Bart Van Assche
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jiapeng Chong @ 2024-07-01 9:06 UTC (permalink / raw)
To: James.Bottomley
Cc: martin.petersen, linux-scsi, linux-kernel, Jiapeng Chong,
Abaci Robot
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.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9463
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
drivers/scsi/sd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 979795dad62b..ade8c6cca295 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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 */
--
2.20.1.7.g153144c
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: Fix unsigned expression compared with zero
2024-07-01 9:06 [PATCH] scsi: sd: Fix unsigned expression compared with zero Jiapeng Chong
@ 2024-07-01 16:50 ` Bart Van Assche
2024-07-01 17:08 ` Bart Van Assche
2024-07-02 9:44 ` John Garry
2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2024-07-01 16:50 UTC (permalink / raw)
To: Jiapeng Chong, James.Bottomley
Cc: martin.petersen, linux-scsi, linux-kernel, Abaci Robot
On 7/1/24 2:06 AM, Jiapeng Chong wrote:
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: Fix unsigned expression compared with zero
2024-07-01 9:06 [PATCH] scsi: sd: Fix unsigned expression compared with zero Jiapeng Chong
2024-07-01 16:50 ` Bart Van Assche
@ 2024-07-01 17:08 ` Bart Van Assche
2024-07-02 9:44 ` John Garry
2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2024-07-01 17:08 UTC (permalink / raw)
To: Jiapeng Chong, James.Bottomley
Cc: martin.petersen, linux-scsi, linux-kernel, Abaci Robot
On 7/1/24 2:06 AM, Jiapeng Chong wrote:
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: sd: Fix unsigned expression compared with zero
2024-07-01 9:06 [PATCH] scsi: sd: Fix unsigned expression compared with zero Jiapeng Chong
2024-07-01 16:50 ` Bart Van Assche
2024-07-01 17:08 ` Bart Van Assche
@ 2024-07-02 9:44 ` John Garry
2 siblings, 0 replies; 4+ messages in thread
From: John Garry @ 2024-07-02 9:44 UTC (permalink / raw)
To: Jiapeng Chong, James.Bottomley
Cc: martin.petersen, linux-scsi, linux-kernel, Abaci Robot,
michael.christie
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
> 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?
>
> ./drivers/scsi/sd.c:2333:6-16: WARNING: Unsigned expression compared with zero: the_result > 0.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://urldefense.com/v3/__https://bugzilla.openanolis.cn/show_bug.cgi?id=9463__;!!ACWV5N9M2RV99hQ!MVk0tuPkuuYZTeD-oVg7RYLVba7HwHVUjWCL2CLavSPrJmuO4MSCUNQ0vqjbCSIKBN8eonwTlU4FxKD3vmHQQhN2YUhbLcnJ$
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Looks ok, but Mike can hopefully double-check:
Reviewed-by: John Garry <john.g.garry@oracle.com>
> ---
> drivers/scsi/sd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 979795dad62b..ade8c6cca295 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -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 */
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-02 9:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01 9:06 [PATCH] scsi: sd: Fix unsigned expression compared with zero Jiapeng Chong
2024-07-01 16:50 ` Bart Van Assche
2024-07-01 17:08 ` Bart Van Assche
2024-07-02 9:44 ` John Garry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox