lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 26 Feb 2023 22:36:22 -0800
From:   Guenter Roeck <linux@...ck-us.net>
To:     Xingyu Wu <xingyu.wu@...rfivetech.com>
Cc:     linux-riscv@...ts.infradead.org, devicetree@...r.kernel.org,
        linux-watchdog@...r.kernel.org,
        Wim Van Sebroeck <wim@...ux-watchdog.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Rob Herring <robh+dt@...nel.org>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Albert Ou <aou@...s.berkeley.edu>,
        Philipp Zabel <p.zabel@...gutronix.de>,
        Samin Guo <samin.guo@...rfivetech.com>,
        linux-kernel@...r.kernel.org, Conor Dooley <conor@...nel.org>
Subject: Re: [PATCH v3 2/2] drivers: watchdog: Add StarFive Watchdog driver

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.

Guenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ