linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0
@ 2017-12-09  0:34 Colin King
  2017-12-11  2:41 ` 黃清隆
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Colin King @ 2017-12-09  0:34 UTC (permalink / raw)
  To: James E . J . Bottomley, Martin K . Petersen, Ching Huang, linux-scsi
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The check for secs being less than zero is redundant for two reasons.
Firstly, secs is unsigned so the check is always going to be false.
Secondly, if secs was signed the proceeding calculation of secs is
never going to be negative.  Hence we can remove this redundant check
and day and secs re-adjustment.

Detected by static analysis with smatch:
arcmsr_set_iop_datetime() warn: unsigned 'secs' is never less than zero.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/arcmsr/arcmsr_hba.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 0707a60bf5c0..e4258b69f4be 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -3679,10 +3679,6 @@ static void arcmsr_set_iop_datetime(struct timer_list *t)
 	secs = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60));
 	days = secs / 86400;
 	secs = secs - 86400 * days;
-	if (secs < 0) {
-		days = days - 1;
-		secs = secs + 86400;
-	}
 	j = days / 146097;
 	i = days - 146097 * j;
 	a = i + 719468;
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0
  2017-12-09  0:34 [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0 Colin King
@ 2017-12-11  2:41 ` 黃清隆
  2017-12-12  2:37 ` Martin K. Petersen
  2017-12-15 17:52 ` walter harms
  2 siblings, 0 replies; 4+ messages in thread
From: 黃清隆 @ 2017-12-11  2:41 UTC (permalink / raw)
  To: Colin King
  Cc: James E . J . Bottomley, Martin K . Petersen, linux-scsi,
	kernel-janitors, linux-kernel, Dan Carpenter

Colin,

You are right. That's checking is redundant. secs is never be negative.
Thanks for your correction and patch.

Regards,
Ching

2017-12-09 8:34 GMT+08:00 Colin King <colin.king@canonical.com>:
> From: Colin Ian King <colin.king@canonical.com>
>
> The check for secs being less than zero is redundant for two reasons.
> Firstly, secs is unsigned so the check is always going to be false.
> Secondly, if secs was signed the proceeding calculation of secs is
> never going to be negative.  Hence we can remove this redundant check
> and day and secs re-adjustment.
>
> Detected by static analysis with smatch:
> arcmsr_set_iop_datetime() warn: unsigned 'secs' is never less than zero.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/scsi/arcmsr/arcmsr_hba.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 0707a60bf5c0..e4258b69f4be 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -3679,10 +3679,6 @@ static void arcmsr_set_iop_datetime(struct timer_list *t)
>         secs = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60));
>         days = secs / 86400;
>         secs = secs - 86400 * days;
> -       if (secs < 0) {
> -               days = days - 1;
> -               secs = secs + 86400;
> -       }
>         j = days / 146097;
>         i = days - 146097 * j;
>         a = i + 719468;
> --
> 2.14.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0
  2017-12-09  0:34 [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0 Colin King
  2017-12-11  2:41 ` 黃清隆
@ 2017-12-12  2:37 ` Martin K. Petersen
  2017-12-15 17:52 ` walter harms
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2017-12-12  2:37 UTC (permalink / raw)
  To: Colin King
  Cc: James E . J . Bottomley, Martin K . Petersen, Ching Huang,
	linux-scsi, kernel-janitors, linux-kernel


Colin,

> The check for secs being less than zero is redundant for two reasons.
> Firstly, secs is unsigned so the check is always going to be false.
> Secondly, if secs was signed the proceeding calculation of secs is
> never going to be negative.  Hence we can remove this redundant check
> and day and secs re-adjustment.

Applied to 4.16/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0
  2017-12-09  0:34 [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0 Colin King
  2017-12-11  2:41 ` 黃清隆
  2017-12-12  2:37 ` Martin K. Petersen
@ 2017-12-15 17:52 ` walter harms
  2 siblings, 0 replies; 4+ messages in thread
From: walter harms @ 2017-12-15 17:52 UTC (permalink / raw)
  To: Colin King
  Cc: James E . J . Bottomley, Martin K . Petersen, Ching Huang,
	linux-scsi, kernel-janitors, linux-kernel



Am 09.12.2017 01:34, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The check for secs being less than zero is redundant for two reasons.
> Firstly, secs is unsigned so the check is always going to be false.
> Secondly, if secs was signed the proceeding calculation of secs is
> never going to be negative.  Hence we can remove this redundant check
> and day and secs re-adjustment.
> 
> Detected by static analysis with smatch:
> arcmsr_set_iop_datetime() warn: unsigned 'secs' is never less than zero.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/scsi/arcmsr/arcmsr_hba.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 0707a60bf5c0..e4258b69f4be 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -3679,10 +3679,6 @@ static void arcmsr_set_iop_datetime(struct timer_list *t)
>  	secs = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60));
>  	days = secs / 86400;
>  	secs = secs - 86400 * days;

mmh, what they want to do is:
	secs = secs % 86400 ;

> -	if (secs < 0) {
> -		days = days - 1;
> -		secs = secs + 86400;
> -	}
>  	j = days / 146097;
>  	i = days - 146097 * j;
>  	a = i + 719468;

see above.
btw: are the numbers documented ?

re,
 wh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-15 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-09  0:34 [PATCH][next] scsi: arcmsr: remove redundant check for secs < 0 Colin King
2017-12-11  2:41 ` 黃清隆
2017-12-12  2:37 ` Martin K. Petersen
2017-12-15 17:52 ` walter harms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).