devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xingyu Wu <xingyu.wu@starfivetech.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: <linux-riscv@lists.infradead.org>, <devicetree@vger.kernel.org>,
	<linux-watchdog@vger.kernel.org>,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	Samin Guo <samin.guo@starfivetech.com>,
	<linux-kernel@vger.kernel.org>, Conor Dooley <conor@kernel.org>
Subject: Re: [PATCH v3 2/2] drivers: watchdog: Add StarFive Watchdog driver
Date: Mon, 27 Feb 2023 14:45:52 +0800	[thread overview]
Message-ID: <2b79e1ac-3399-075d-1d1d-e6d7f88351fc@starfivetech.com> (raw)
In-Reply-To: <547a469d-eeaa-750c-4fe5-cc82d92493a6@roeck-us.net>

On 2023/2/27 14:36, Guenter Roeck wrote:
> On 2/26/23 22:26, Xingyu Wu wrote:
>> On 2023/2/24 23:18, Guenter Roeck wrote:
>>> On 2/23/23 23:42, Xingyu Wu wrote:
>>>> On 2023/2/24 2:23, Guenter Roeck wrote:
>>>>> On Mon, Feb 20, 2023 at 04:19:26PM +0800, Xingyu Wu wrote:
>>>>>> [...]
>>>>>> +
>>>>>> +    wdt->wdt_device.min_timeout = 1;
>>>>>> +    wdt->wdt_device.max_timeout = starfive_wdt_max_timeout(wdt);
>>>>>
>>>>>      wdt->wdt_device.timeout = STARFIVE_WDT_DEFAULT_TIME;
>>>>>
>>>>> should be set here. Otherwise the warning below would always be seen
>>>>> if the module parameter is not set.
>>>>>
>>>>>> +
>>>>>> +    watchdog_set_drvdata(&wdt->wdt_device, wdt);
>>>>>> +
>>>>>> +    /*
>>>>>> +     * see if we can actually set the requested heartbeat,
>>>>>> +     * and if not, try the default value.
>>>>>> +     */
>>>>>> +    watchdog_init_timeout(&wdt->wdt_device, heartbeat, dev);
>>>>>> +    if (wdt->wdt_device.timeout == 0 ||
>>>>>
>>>>> If wdt->wdt_device.timeout is pre-initialized, it will never be 0 here.
>>>>>
>>>>>> +        wdt->wdt_device.timeout > wdt->wdt_device.max_timeout) {
>>>>>
>>>>> That won't happen because watchdog_init_timeout() validates it and does
>>>>> not update the value if it is out of range.
>>>>>
>>>>>> +        dev_warn(dev, "heartbeat value out of range, default %d used\n",
>>>>>> +             STARFIVE_WDT_DEFAULT_TIME);
>>>>>> +        wdt->wdt_device.timeout = STARFIVE_WDT_DEFAULT_TIME;
>>>>>
>>>>> And this is then unnecessary. wdt->wdt_device.timeout will always be
>>>>> valid if it was pre-initialized.
>>>>
>>>> It is changed to be this at beginning of the driver:
>>>>
>>>> static int heartbeat = STARFIVE_WDT_DEFAULT_TIME;
>>>>
>>>
>>> No, this is wrong. The static variable should be set to 0 to indicate
>>> "use default".
>>>
>>>> and it is changed to be this here:
>>>>
>>>> ret = watchdog_init_timeout(&wdt->wdt_device, heartbeat, dev);
>>>> if (ret)
>>>>      return ret;
>>>>
>>>> Would that be better?
>>>>
>>>
>>> No, it is worse, because it would not instantiate the watchdog at all
>>> if a bad heartbeat is provided.
>>>
>>
>> So instantiate the watchdog with hearbeat first. And if this wrong, use default timeout.
>> :
>> if (watchdog_init_timeout(&wdt->wdt_device, heartbeat, dev))
>>     wdt->wdt_device.timeout = STARFIVE_WDT_DEFAULT_TIME;
>>
> 
> I am kind of lost why you have to make it that complicated.
> Just pre-initialize wdt->wdt_device.timeout like all the other drivers do,
> and as I had suggested earlier.
> 

So you mean just use :
wdt->wdt_device.timeout = STARFIVE_WDT_DEFAULT_TIME;
to initialize watchdog directly?

Best regards,
Xingyu Wu

  reply	other threads:[~2023-02-27  6:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-20  8:19 [PATCH v3 0/2] Add watchdog driver for StarFive JH7110 RISC-V SoC Xingyu Wu
2023-02-20  8:19 ` [PATCH v3 1/2] dt-bindings: watchdog: Add watchdog for StarFive JH7110 Xingyu Wu
2023-02-20 11:46   ` Krzysztof Kozlowski
2023-02-20  8:19 ` [PATCH v3 2/2] drivers: watchdog: Add StarFive Watchdog driver Xingyu Wu
2023-02-23 18:23   ` Guenter Roeck
2023-02-24  7:42     ` Xingyu Wu
2023-02-24 15:18       ` Guenter Roeck
2023-02-27  6:26         ` Xingyu Wu
2023-02-27  6:36           ` Guenter Roeck
2023-02-27  6:45             ` Xingyu Wu [this message]
2023-02-27 14:50               ` Guenter Roeck
2023-02-28  2:07                 ` Xingyu Wu
2023-02-26 14:14   ` Emil Renner Berthing
2023-02-26 14:33     ` Conor Dooley
2023-02-27  1:47       ` Xingyu Wu
2023-02-28  9:44     ` Xingyu Wu
2023-02-28 10:36       ` Emil Renner Berthing
2023-02-28 10:51         ` Conor Dooley
2023-02-28 10:57           ` Krzysztof Kozlowski
2023-02-28 11:11             ` Conor Dooley
2023-02-28 13:16               ` Xingyu Wu
2023-02-28 14:03                 ` Krzysztof Kozlowski
2023-02-28 15:10                 ` Guenter Roeck
2023-02-28 15:32                   ` Emil Renner Berthing
2023-03-01  3:40                     ` Xingyu Wu
2023-02-28 14:59         ` 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=2b79e1ac-3399-075d-1d1d-e6d7f88351fc@starfivetech.com \
    --to=xingyu.wu@starfivetech.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=p.zabel@pengutronix.de \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=robh+dt@kernel.org \
    --cc=samin.guo@starfivetech.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).