watchdog: Use DIV_ROUND_UP() instead of open-coding it
Subsystems (2)
PATCH 1/1 watchdog: Use DIV_ROUND_UP() instead of open-coding it
Use DIV_ROUND_UP() instead of open-coding it. This makes it more clear what is going on for the casual reviewer.
Generated using the following the Coccinelle semantic patch.
// <smpl>
@r1@
expression x;
constant C1;
constant C2;
@@
((x) + C1) / C2
@script:python@
C1 << r1.C1;
C2 << r1.C2;
@@
print C1, C2
try:
if int(C1) != int(C2) - 1 or int(C1) == 1: cocci.include_match(False)
except:
cocci.include_match(False)
@@
expression r1.x;
constant r1.C1;
constant r1.C2;
@@
-(((x) + C1) / C2)
+DIV_ROUND_UP(x, C2)
// </smpl>
--- drivers/watchdog/riowd.c | 2 +- drivers/watchdog/w83977f_wdt.c | 2 +- drivers/watchdog/wdrtas.c | 2 +- drivers/watchdog/wdt977.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/watchdog/riowd.c +1 -1
@@ -132,7 +132,7 @@ static long riowd_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EFAULT ;if ((new_margin <60 ) || (new_margin > (255 *60 )))return -EINVAL ; - riowd_timeout = (new_margin +59 ) /60 ; + riowd_timeout =DIV_ROUND_UP (new_margin,60 );riowd_writereg (p, riowd_timeout,WDTO_INDEX ); fallthrough;
drivers/watchdog/w83977f_wdt.c +1 -1
@@ -231,7 +231,7 @@ static int wdt_set_timeout(int t)if (t <15 )return -EINVAL ; - tmrval = ((t +15 ) +29 ) /30 ; + tmrval =DIV_ROUND_UP (t +15 ,30 );if (tmrval >255 )return -EINVAL ;
drivers/watchdog/wdrtas.c +1 -1
@@ -75,7 +75,7 @@ static int wdrtas_set_interval(int interval)static int print_msg =10 ;/* rtas uses minutes */ - interval = (interval +59 ) /60 ; + interval =DIV_ROUND_UP (interval,60 ); result =rtas_call (wdrtas_token_set_indicator,3 ,1 ,NULL ,WDRTAS_SURVEILLANCE_IND ,0 , interval);
drivers/watchdog/wdt977.c +1 -1
@@ -201,7 +201,7 @@ static int wdt977_set_timeout(int t)int tmrval;/* convert seconds to minutes, rounding up */ - tmrval = (t +59 ) /60 ; + tmrval =DIV_ROUND_UP (t,60 );if (machine_is_netwinder ()) {/* we have a hw bug somewhere, so each 977 minute is actually
Signature · 1 line
2.20.1
Guenter Roeck
maintainerQuoted 3 lines · Lars-Peter Clausen
Use
DIV_ROUND_UP()instead of open-coding it. This makes it more clear what is going on for the casual reviewer.
Those are all old watchdog drivers, which are not worth cleaning up.
As I said before, those drivers should only be touched to either fix a real bug, to convert them to new style watchdog drivers, or to drop them.
Thanks,
Guenter
Quoted 91 lines
Generated using the following the Coccinelle semantic patch.
// <smpl>
@r1@
expression x;
constant C1;
constant C2;
@@
((x) + C1) / C2@script:python@
C1 << r1.C1;
C2 << r1.C2;
@@
print C1, C2
try:if int(C1) != int(C2) - 1 or int(C1) == 1: cocci.include_match(False)except:
cocci.include_match(False)@@
expression r1.x;
constant r1.C1;
constant r1.C2;
@@(quoted diff) +1
-1-(((x) + C1) / C2) +DIV_ROUND_UP(x, C2)// </smpl>
Signed-off-by Lars-Peter Clausen <[email protected]>--- drivers/watchdog/riowd.c | 2 +- drivers/watchdog/w83977f_wdt.c | 2 +- drivers/watchdog/wdrtas.c | 2 +- drivers/watchdog/wdt977.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)drivers/watchdog/riowd.c +1
-1@@ -132,7 +132,7 @@ static long riowd_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EFAULT ;if ((new_margin <60 ) || (new_margin > (255 *60 )))return -EINVAL ; - riowd_timeout = (new_margin +59 ) /60 ; + riowd_timeout =DIV_ROUND_UP (new_margin,60 );riowd_writereg (p, riowd_timeout,WDTO_INDEX ); fallthrough;drivers/watchdog/w83977f_wdt.c +1
-1@@ -231,7 +231,7 @@ static int wdt_set_timeout(int t)if (t <15 )return -EINVAL ; - tmrval = ((t +15 ) +29 ) /30 ; + tmrval =DIV_ROUND_UP (t +15 ,30 );if (tmrval >255 )return -EINVAL ;drivers/watchdog/wdrtas.c +1
-1@@ -75,7 +75,7 @@ static int wdrtas_set_interval(int interval)static int print_msg =10 ;/* rtas uses minutes */ - interval = (interval +59 ) /60 ; + interval =DIV_ROUND_UP (interval,60 ); result =rtas_call (wdrtas_token_set_indicator,3 ,1 ,NULL ,WDRTAS_SURVEILLANCE_IND ,0 , interval);drivers/watchdog/wdt977.c +1
-1@@ -201,7 +201,7 @@ static int wdt977_set_timeout(int t)int tmrval;/* convert seconds to minutes, rounding up */ - tmrval = (t +59 ) /60 ; + tmrval =DIV_ROUND_UP (t,60 );if (machine_is_netwinder ()) {/* we have a hw bug somewhere, so each 977 minute is actually