task_wdt: fix silent init failures

The task_wdt_init() API can fail to install a timeout for the fallback
hardware WDT (hw_wdt) without returning an error code.  This patch
enables task_wdt_init() to return the hw_wdt install timeout error code
if the hw_wdt install timeout fails.

Signed-off-by: Nick Ward <nick.ward@setec.com.au>
This commit is contained in:
Nick Ward 2021-09-10 22:50:47 +10:00 committed by Carles Cufí
commit e0f18128bf
3 changed files with 14 additions and 1 deletions

View file

@ -47,6 +47,9 @@ typedef void (*task_wdt_callback_t)(int channel_id, void *user_data);
*
* @retval 0 If successful.
* @retval -ENOTSUP If assigning a hardware watchdog is not supported.
* @retval -Errno Negative errno if the fallback hw_wdt is used and the
* install timeout API fails. See wdt_install_timeout()
* API for possible return values.
*/
int task_wdt_init(const struct device *hw_wdt);

View file

@ -58,6 +58,7 @@ static void task_wdt_callback(int channel_id, void *user_data)
void main(void)
{
int ret;
#ifdef WDT_NODE
const struct device *hw_wdt_dev = DEVICE_DT_GET(WDT_NODE);
#else
@ -72,7 +73,12 @@ void main(void)
hw_wdt_dev = NULL;
}
task_wdt_init(hw_wdt_dev);
ret = task_wdt_init(hw_wdt_dev);
if (ret != 0) {
printk("task wdt init failure: %d\n", ret);
return;
}
/* passing NULL instead of callback to trigger system reset */
int task_wdt_id = task_wdt_add(1100U, NULL, NULL);

View file

@ -136,6 +136,10 @@ int task_wdt_init(const struct device *hw_wdt)
hw_wdt_dev = hw_wdt;
hw_wdt_channel = wdt_install_timeout(hw_wdt_dev, &wdt_config);
if (hw_wdt_channel < 0) {
LOG_ERR("hw_wdt install timeout failed: %d", hw_wdt_channel);
return hw_wdt_channel;
}
#else
return -ENOTSUP;
#endif