linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Melin Tomas <tomas.melin@vaisala.com>
Cc: "wim@linux-watchdog.org" <wim@linux-watchdog.org>,
	"linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>
Subject: Re: [PATCH v2 2/4] watchdog: cadence_wdt: Calculate actual timeout limits
Date: Mon, 8 Jul 2019 11:06:03 -0700	[thread overview]
Message-ID: <20190708180603.GA14509@roeck-us.net> (raw)
In-Reply-To: <20190705114522.42565-3-tomas.melin@vaisala.com>

On Fri, Jul 05, 2019 at 11:46:02AM +0000, Melin Tomas wrote:
> Maximum and minimum timeout values depend on the actual input clock
> frequency and prescaler selection.
> 
> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
> ---
>  drivers/watchdog/cadence_wdt.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c
> index 415bd6dd1edb..87b767c87bb6 100644
> --- a/drivers/watchdog/cadence_wdt.c
> +++ b/drivers/watchdog/cadence_wdt.c
> @@ -18,9 +18,6 @@
>  #include <linux/watchdog.h>
>  
>  #define CDNS_WDT_DEFAULT_TIMEOUT	10
> -/* Supports 1 - 516 sec */
> -#define CDNS_WDT_MIN_TIMEOUT	1
> -#define CDNS_WDT_MAX_TIMEOUT	516
>  
>  /* Restart key */
>  #define CDNS_WDT_RESTART_KEY 0x00001999
> @@ -28,6 +25,10 @@
>  /* Counter register access key */
>  #define CDNS_WDT_REGISTER_ACCESS_KEY 0x00920000
>  
> +/* Counter control register, counter restart values */
> +#define CDNS_WDT_CCR_CRV_MIN 0xFFF
> +#define CDNS_WDT_CCR_CRV_MAX 0xFFFFFF
> +
>  /* Counter value divisor */
>  #define CDNS_WDT_COUNTER_VALUE_DIVISOR 0x1000
>  
> @@ -315,8 +316,10 @@ static int cdns_wdt_probe(struct platform_device *pdev)
>  	cdns_wdt_device->info = &cdns_wdt_info;
>  	cdns_wdt_device->ops = &cdns_wdt_ops;
>  	cdns_wdt_device->timeout = CDNS_WDT_DEFAULT_TIMEOUT;
> -	cdns_wdt_device->min_timeout = CDNS_WDT_MIN_TIMEOUT;
> -	cdns_wdt_device->max_timeout = CDNS_WDT_MAX_TIMEOUT;
> +	cdns_wdt_device->min_timeout =
> +		CDNS_WDT_CCR_CRV_MIN * wdt->prescaler / clock_f;
> +	cdns_wdt_device->max_timeout =
> +		CDNS_WDT_CCR_CRV_MAX * wdt->prescaler / clock_f;

clock_f can at least in theory be 0. So far that didn't matter as
much, but now it would crash the kernel. Please add a respective
check into the code.

>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	wdt->regs = devm_ioremap_resource(&pdev->dev, res);

  reply	other threads:[~2019-07-08 18:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-05 11:46 [PATCH v2 0/4] watchdog: cadence_wdt: Support all available prescaler values Melin Tomas
2019-07-05 11:46 ` [PATCH v2 1/4] watchdog: cadence_wdt: Move clock detection eariler in probe Melin Tomas
2019-07-08 18:03   ` Guenter Roeck
2019-07-05 11:46 ` [PATCH v2 2/4] watchdog: cadence_wdt: Calculate actual timeout limits Melin Tomas
2019-07-08 18:06   ` Guenter Roeck [this message]
2019-07-05 11:46 ` [PATCH v2 3/4] watchdog: cadence_wdt: Group struct member init statements Melin Tomas
2019-07-08 18:09   ` Guenter Roeck
2019-07-05 11:46 ` [PATCH v2 4/4] watchdog: cadence_wdt: Support all available prescaler values Melin Tomas
2019-07-08 18:14   ` Guenter Roeck

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=20190708180603.GA14509@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=tomas.melin@vaisala.com \
    --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).