mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Cherian <gcherian@marvell.com>
To: Guenter Roeck <linux@roeck-us.net>,
	"wim@linux-watchdog.org" <wim@linux-watchdog.org>,
	"zhangshaokun@hisilicon.com" <zhangshaokun@hisilicon.com>
Cc: "linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] watchdog: sbsa_wdog: Fix the timeout calculation while programming
Date: Tue, 7 Feb 2023 17:01:04 +0000	[thread overview]
Message-ID: <BYAPR18MB26799C60A6AE457B26CBF602C5DB9@BYAPR18MB2679.namprd18.prod.outlook.com> (raw)
In-Reply-To: <db0eda3d-65a7-8d8a-e9a3-7f7617d242ef@roeck-us.net>



> -----Original Message-----
> From: Guenter Roeck <groeck7@gmail.com> On Behalf Of Guenter Roeck
> Sent: Tuesday, February 7, 2023 9:34 PM
> To: George Cherian <gcherian@marvell.com>; wim@linux-watchdog.org;
> zhangshaokun@hisilicon.com
> Cc: linux-watchdog@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 1/2] watchdog: sbsa_wdog: Fix the timeout
> calculation while programming
> 
> 
> ----------------------------------------------------------------------
> On 2/6/23 20:46, George Cherian wrote:
> > The time out calculation done in sbsa_gwdt_set_timeout() would always
> > return a 32-bit value. Use proper typecasting to make sure the overflow
> > values are captured.
> >
> > Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
> >
> > Signed-off-by: George Cherian <george.cherian@marvell.com>
> > ---
> >   drivers/watchdog/sbsa_gwdt.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/watchdog/sbsa_gwdt.c
> b/drivers/watchdog/sbsa_gwdt.c
> > index 9791c74aebd4..aaa3f5631f29 100644
> > --- a/drivers/watchdog/sbsa_gwdt.c
> > +++ b/drivers/watchdog/sbsa_gwdt.c
> > @@ -152,14 +152,14 @@ static int sbsa_gwdt_set_timeout(struct
> watchdog_device *wdd,
> >   	wdd->timeout = timeout;
> >
> >   	if (action)
> > -		sbsa_gwdt_reg_write(gwdt->clk * timeout, gwdt);
> > +		sbsa_gwdt_reg_write((u64)gwdt->clk * (u64)timeout, gwdt);
> >   	else
> >   		/*
> >   		 * In the single stage mode, The first signal (WS0) is ignored,
> >   		 * the timeout is (WOR * 2), so the WOR should be
> configured
> >   		 * to half value of timeout.
> >   		 */
> > -		sbsa_gwdt_reg_write(gwdt->clk / 2 * timeout, gwdt);
> > +		sbsa_gwdt_reg_write((u64)gwdt->clk / 2 * (u64)timeout,
> gwdt);
> >
> >   	return 0;
> >   }
> 
> The driver sets max_hw_heartbeat_ms. It is its responsibility to clamp
> the timeout value written into the controller to the configured limit
> to avoid confusing the watchdog core. Something like
> 
> 	timeout = clamp(timeout, 0, wdd->max_hw_heartbeat_ms / 1000);
> 
> This also solves the problem in patch 2 since it guarantees that the
> resulting register value is <= U32_MAX for version 0.

 Thanks for the review.  I will update accordingly and post a v2.

> 
> Guenter

Regards,
-George

      reply	other threads:[~2023-02-07 17:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  4:46 George Cherian
2023-02-07  4:46 ` [PATCH 2/2] watchdog: sbsa_wdog: Make sure to program a larger timeout value George Cherian
2023-02-07 16:03 ` [PATCH 1/2] watchdog: sbsa_wdog: Fix the timeout calculation while programming Guenter Roeck
2023-02-07 17:01   ` George Cherian [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=BYAPR18MB26799C60A6AE457B26CBF602C5DB9@BYAPR18MB2679.namprd18.prod.outlook.com \
    --to=gcherian@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@linux-watchdog.org \
    --cc=zhangshaokun@hisilicon.com \
    /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

all inboxes | Powered by JetHome®