All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
	 Guenter Roeck <linux@roeck-us.net>,
	 linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] watchdog: digicolor: Avoid division by zero
Date: Mon, 14 Sep 2026 08:46:03 +0300	[thread overview]
Message-ID: <87a4pkgzc4.fsf@tarshish> (raw)
In-Reply-To: <20260913064851.8239-2-tzungbi@kernel.org> (Tzung-Bi Shih's message of "Sun, 13 Sep 2026 14:48:49 +0800")

Hi Tzung-Bi Shih,

On Sun, Sep 13 2026, Tzung-Bi Shih wrote:
> clk_get_rate() could return 0.  Avoid a division by zero panic.
>
> Since get_timeleft() cannot propagate errors, check the clock rate early
> in probe() and cache the rate in the driver data as it is unlikely to
> change at runtime.
>
> Fixes: 336694a01dae ("watchdog: digicolor: driver for Conexant Digicolor CX92755 SoC")
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

Acked-by: Baruch Siach <baruch@tkos.co.il>

Thanks,
baruch

> ---
>  drivers/watchdog/digicolor_wdt.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/watchdog/digicolor_wdt.c b/drivers/watchdog/digicolor_wdt.c
> index 073d37867f47..de1a3267a972 100644
> --- a/drivers/watchdog/digicolor_wdt.c
> +++ b/drivers/watchdog/digicolor_wdt.c
> @@ -25,6 +25,7 @@ struct dc_wdt {
>  	void __iomem		*base;
>  	struct clk		*clk;
>  	spinlock_t		lock;
> +	unsigned long		rate;
>  };
>  
>  static unsigned timeout;
> @@ -61,7 +62,7 @@ static int dc_wdt_start(struct watchdog_device *wdog)
>  {
>  	struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
>  
> -	dc_wdt_set(wdt, wdog->timeout * clk_get_rate(wdt->clk));
> +	dc_wdt_set(wdt, wdog->timeout * wdt->rate);
>  
>  	return 0;
>  }
> @@ -79,7 +80,7 @@ static int dc_wdt_set_timeout(struct watchdog_device *wdog, unsigned int t)
>  {
>  	struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
>  
> -	dc_wdt_set(wdt, t * clk_get_rate(wdt->clk));
> +	dc_wdt_set(wdt, t * wdt->rate);
>  	wdog->timeout = t;
>  
>  	return 0;
> @@ -90,7 +91,7 @@ static unsigned int dc_wdt_get_timeleft(struct watchdog_device *wdog)
>  	struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
>  	uint32_t count = readl_relaxed(wdt->base + TIMER_A_COUNT);
>  
> -	return count / clk_get_rate(wdt->clk);
> +	return count / wdt->rate;
>  }
>  
>  static const struct watchdog_ops dc_wdt_ops = {
> @@ -130,7 +131,11 @@ static int dc_wdt_probe(struct platform_device *pdev)
>  	wdt->clk = devm_clk_get(dev, NULL);
>  	if (IS_ERR(wdt->clk))
>  		return PTR_ERR(wdt->clk);
> -	dc_wdt_wdd.max_timeout = U32_MAX / clk_get_rate(wdt->clk);
> +
> +	wdt->rate = clk_get_rate(wdt->clk);
> +	if (!wdt->rate)
> +		return -EINVAL;
> +	dc_wdt_wdd.max_timeout = U32_MAX / wdt->rate;
>  	dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout;
>  	dc_wdt_wdd.parent = dev;

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

  reply	other threads:[~2026-09-14  5:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13  6:48 [PATCH 0/3] watchdog: Avoid division by zero from clk_get_rate() Tzung-Bi Shih
2026-09-13  6:48 ` [PATCH 1/3] watchdog: digicolor: Avoid division by zero Tzung-Bi Shih
2026-09-14  5:46   ` Baruch Siach [this message]
2026-09-17  0:27   ` Guenter Roeck
2026-09-13  6:48 ` [PATCH 2/3] watchdog: rtd119x: " Tzung-Bi Shih
2026-09-17  0:27   ` Guenter Roeck
2026-09-13  6:48 ` [PATCH 3/3] watchdog: rzv2h: " Tzung-Bi Shih
2026-09-17  0:28   ` 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=87a4pkgzc4.fsf@tarshish \
    --to=baruch@tkos.co.il \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=tzungbi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.