scsi: srp_transport: Fix 'always false comparison' in srp_tmo_valid()
PATCH 1/1 scsi: srp_transport: Fix 'always false comparison' in srp_tmo_valid()
In a 64bit system (where long is 64bit wide), even dividing LONG_MAX by HZ will always be bigger than the max value that an int variable can hold.
This has been detected by building the driver with W=1:
drivers/scsi/scsi_transport_srp.c: In function ‘srp_tmo_valid’:drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false due to limited range of data type [-Wtype-limits]
if (dev_loss_tmo >= LONG_MAX / HZ)
^
--- drivers/scsi/scsi_transport_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_transport_srp.c +1 -1
@@ -89,7 +89,7 @@ int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)if (fast_io_fail_tmo <0 && dev_loss_tmo >SCSI_DEVICE_BLOCK_MAX_TIMEOUT )return -EINVAL ; -if (dev_loss_tmo >=LONG_MAX /HZ ) +if (dev_loss_tmo >=INT_MAX /HZ )return -EINVAL ;if (fast_io_fail_tmo >=0 && dev_loss_tmo >=0 && fast_io_fail_tmo >= dev_loss_tmo)
Signature · 1 line
2.7.4
Quoted 22 lines · Augusto Mecking Caringi
In a 64bit system (where long is 64bit wide), even dividing
LONG_MAXby HZ will always be bigger than the max value that an int variable can hold.This has been detected by building the driver with W=1:
drivers/scsi/scsi_transport_srp.c: In function ‘srp_tmo_valid’:drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false due to limited range of data type [-Wtype-limits]
if (dev_loss_tmo>=LONG_MAX/ HZ)^Signed-off-by Augusto Mecking Caringi <[email protected]>--- drivers/scsi/scsi_transport_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/scsi_transport_srp.c +0
-0
drivers/scsi/scsi_transport_srp.c int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo) · line 95
Quoted 8 lines
drivers/scsi/scsi_transport_srp.c +1
-1@@ -89,7 +89,7 @@ int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)if (fast_io_fail_tmo <0 && dev_loss_tmo >SCSI_DEVICE_BLOCK_MAX_TIMEOUT )return -EINVAL ; -if (dev_loss_tmo >=LONG_MAX /HZ ) +if (dev_loss_tmo >=INT_MAX /HZ )return -EINVAL ;if (fast_io_fail_tmo >=0 && dev_loss_tmo >=0 && fast_io_fail_tmo >= dev_loss_tmo)
This patch is wrong. The purpose of the dev_loss_tmo >= LONG_MAX / HZ check is to avoid that the expression 1UL * dev_loss_tmo * HZ further down overflows. Can you check whether changing the if-statement into if (1UL * dev_loss_tmo >= LONG_MAX / HZ) also suppresses the compiler warning?
Bart.
Quoted 4 lines · Bart Van Assche
This patch is wrong. The purpose of the
dev_loss_tmo>=LONG_MAX/ HZ check is to avoid that the expression 1UL *dev_loss_tmo* HZ further down overflows. Can you check whether changing the if-statement into if (1UL *dev_loss_tmo>=LONG_MAX/ HZ) also suppresses the compiler warning?
Hi Bart,
Right, now a I see...
Doing your proposed change the warning go away...
Do you want me to send a new patch for that?
Signature · 1 line
Augusto Mecking Caringi
Quoted 7 lines · Augusto Mecking Caringi
Quoted 4 lines · Bart Van Assche
This patch is wrong. The purpose of the
dev_loss_tmo>=LONG_MAX/ HZ check is to avoid that the expression 1UL *dev_loss_tmo* HZ further down overflows. Can you check whether changing the if-statement into if (1UL *dev_loss_tmo>=LONG_MAX/ HZ) also suppresses the compiler warning?
Quoted 7 lines
Hi Bart,
Right, now a I see...
Doing your proposed change the warning go away...
Do you want me to send a new patch for that?
Hello Augusto,
If you want your patch to go upstream you will have to repost it.
Bart.