[PATCH v3 2/2] drivers: watchdog: Add StarFive Watchdog driver
Xingyu Wu
xingyu.wu at starfivetech.com
Mon Feb 27 18:07:05 PST 2023
On 2023/2/27 22:50, Guenter Roeck wrote:
> On 2/26/23 22:45, Xingyu Wu wrote:
>> 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?
>>
>
> Yes, as I had suggested before, before calling watchdog_init_timeout().
>
OK, thanks.
Best regard,
Xingyu Wu
More information about the linux-riscv
mailing list