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> Signed-off-by: Lars-Peter Clausen <lars@xxxxxxxxxx> --- 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(-) diff --git a/drivers/watchdog/riowd.c b/drivers/watchdog/riowd.c index 7008596a575f..aa8a929505b5 100644 --- a/drivers/watchdog/riowd.c +++ b/drivers/watchdog/riowd.c @@ -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; diff --git a/drivers/watchdog/w83977f_wdt.c b/drivers/watchdog/w83977f_wdt.c index fd64ae77780a..fbc31c4a1e0b 100644 --- a/drivers/watchdog/w83977f_wdt.c +++ b/drivers/watchdog/w83977f_wdt.c @@ -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; diff --git a/drivers/watchdog/wdrtas.c b/drivers/watchdog/wdrtas.c index c00627825de8..0c21ee535a74 100644 --- a/drivers/watchdog/wdrtas.c +++ b/drivers/watchdog/wdrtas.c @@ -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); diff --git a/drivers/watchdog/wdt977.c b/drivers/watchdog/wdt977.c index c9b8e863f70f..7cff1300be3e 100644 --- a/drivers/watchdog/wdt977.c +++ b/drivers/watchdog/wdt977.c @@ -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 -- 2.20.1