From: Guenter Roeck <linux@roeck-us.net>
To: Lars-Peter Clausen <lars@metafoo.de>,
Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
enjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
linux-watchdog@vger.kernel.org
Subject: Re: [PATCH] watchdog: Use DIV_ROUND_UP() instead of open-coding it
Date: Sat, 20 Mar 2021 08:32:36 -0700 [thread overview]
Message-ID: <e3ce4e26-7797-42f1-816d-e470fac1b660@roeck-us.net> (raw)
In-Reply-To: <20210320082956.27689-1-lars@metafoo.de>
On 3/20/21 1:29 AM, Lars-Peter Clausen wrote:
> 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
> 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@metafoo.de>
> ---
> 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
>
prev parent reply other threads:[~2021-03-20 15:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-20 8:29 [PATCH] watchdog: Use DIV_ROUND_UP() instead of open-coding it Lars-Peter Clausen
2021-03-20 15:32 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3ce4e26-7797-42f1-816d-e470fac1b660@roeck-us.net \
--to=linux@roeck-us.net \
--cc=benh@kernel.crashing.org \
--cc=lars@metafoo.de \
--cc=linux-watchdog@vger.kernel.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).