RE: [PATCH v2 1/2] watchdog: rza_wdt: Support longer timeouts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux