linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Brandt <Chris.Brandt@renesas.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	"linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-renesas-soc@vger.kernel.org"
	<linux-renesas-soc@vger.kernel.org>,
	Simon Horman <horms+renesas@verge.net.au>
Subject: RE: [PATCH v2 1/2] watchdog: rza_wdt: Support longer timeouts
Date: Thu, 6 Sep 2018 20:45:50 +0000	[thread overview]
Message-ID: <TY1PR01MB15624B6461C2E00D08C54AFB8A010@TY1PR01MB1562.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <20180906185247.GA25433@roeck-us.net>

On Thursday, September 06, 2018, Guenter Roeck wrote:
> > +static void rza_wdt_calc_timeout(struct rza_wdt *priv, int timeout)
> > +{
> > +	int rate = clk_get_rate(priv->clk);
> 
> clk_get_rate() returns unsigned long.

OK, I'll change it.

> > +	u16 counter;
> > +
> > +	if (priv->cks == CKS_4BIT) {
> > +		counter = DIV_ROUND_UP((timeout * rate),  4194304) + 1;
> 
> two spaces ?

Oh, did see that.

> Also, I am not sure how this prevents overflows. Was't the concern
> that timeout * rate might overflow an int ?

Actually, since 32 second is the max timeout for this WDT, I think at 
first I'll check to see if "timeout" is greater than 32. If it is, there 
is no reason to do any math. Then I won't have to worry about any 
overflows from math.

	if (timeout > 32) 
		counter = 256;
	else
		counter = DIV_ROUND_UP((timeout * rate), 4194304) + 1;


> Also, why still "+ 1" ? Wasn't DIV_ROUND_UP() supposed to take care
> of that ?

Ooops, I forgot to remove the "+ 1"

> > +		if (counter > 255)
> > +			counter = 0;
> 
> This is difficult to understand.

As you suggested, I'll change this to:
	if (counter > 256)
		counter = 256;

Chris

  parent reply	other threads:[~2018-09-07  1:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-06 18:37 [PATCH v2 0/2] watchdog: Add support for RZ/A2 wdt Chris Brandt
2018-09-06 18:37 ` [PATCH v2 1/2] watchdog: rza_wdt: Support longer timeouts Chris Brandt
2018-09-06 18:52   ` Guenter Roeck
2018-09-06 18:56     ` Guenter Roeck
2018-09-06 19:40       ` Chris Brandt
2018-09-06 19:40         ` Chris Brandt
2018-09-06 21:39       ` Chris Brandt
2018-09-06 20:45     ` Chris Brandt [this message]
2018-09-06 18:37 ` [PATCH v2 2/2] dt-bindings: watchdog: renesas-wdt: Add support for R7S9210 Chris Brandt

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=TY1PR01MB15624B6461C2E00D08C54AFB8A010@TY1PR01MB1562.jpnprd01.prod.outlook.com \
    --to=chris.brandt@renesas.com \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=horms+renesas@verge.net.au \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.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).