watchdog: atcwdt200: fix return value when watchdog is enabled
Subsystems (2)
PATCH v2 1/1 watchdog: atcwdt200: fix return value when watchdog is enabled
From: Surendra Singh Chouhan <[email protected]>
atcwdt_get_int_timer_type() returned TMR_UNKNOWN (enum value 3) when CTRL_WDT_EN was set in the control register.
Because atcwdt_probe() checks "ret = atcwdt_get_int_timer_type(drv_data); if (ret) return ret;", returning TMR_UNKNOWN caused probe() to return 3 instead of a valid negative error code.
Fix this by returning -EBUSY via dev_err_probe() when the watchdog is already enabled and update the kernel-doc description accordingly.
--- drivers/watchdog/atcwdt200_wdt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/watchdog/atcwdt200_wdt.c +4 -3
@@ -260,9 +260,9 @@ static void atcwdt_get_timeout_params(struct atcwdt_drv *drv_data,* register to determine the interrupt timer type supported by the hardware. * * Note: This function must only be called when the ATCWDT200 watchdog is -* disabled. If the watchdog is enabled, this function returns TMR_UNKNOWN. +* disabled. If the watchdog is enabled, this function returns -EBUSY. * -* Returns: The interrupt timer type supported by the hardware. +* Returns: 0 on success or negative error code on failure. */ static int atcwdt_get_int_timer_type (struct atcwdt_drv *drv_data) {
@@ -274,7 +274,8 @@ static int atcwdt_get_int_timer_type(struct atcwdt_drv *drv_data)regmap_read (drv_data->regmap,REG_CTRL , &val);if (val &CTRL_WDT_EN ) {spin_unlock (&drv_data->lock); -return TMR_UNKNOWN ; +return dev_err_probe (dev, -EBUSY , +"Watchdog is enabled, cannot detect timer type\n" ); }/*
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Watchdog driver refuses to bind if the hardware is already running, breaking watchdog handoff.
- [High] Deadlock risk during system restart due to unconditional spin_lock() in the restart handler.
- [Medium] Incorrect unit scaling in watchdog timeout parameter calculation causes fallback precision loss. --
--- Patch [1]: [PATCH v2] watchdog: atcwdt200: fix return value when watchdog is enabled --- commit 0db51070773de34698520f8f6ccc03a9f5d37ab7
Author: Surendra Singh Chouhan <[email protected]>
watchdog: atcwdt200: fix return value when watchdog is enabled
This commit updates atcwdt_get_int_timer_type() to return -EBUSY via dev_err_probe() when the hardware watchdog is already enabled. It also updates the associated kernel-doc comments to reflect the new return value, preventing an invalid enum value from propagating on probe.
Quoted 4 lines
drivers/watchdog/atcwdt200_wdt.c +0
-0
[ ... ]
drivers/watchdog/atcwdt200_wdt.c static int atcwdt_get_int_timer_type(struct atcwdt_drv *drv_data) · line 278
Quoted 7 lines
drivers/watchdog/atcwdt200_wdt.c +2
-1@@ -274,7 +274,8 @@ static int atcwdt_get_int_timer_type(struct atcwdt_drv *drv_data)regmap_read (drv_data->regmap,REG_CTRL , &val);if (val &CTRL_WDT_EN ) {spin_unlock (&drv_data->lock); -return TMR_UNKNOWN ; +return dev_err_probe (dev, -EBUSY , +"Watchdog is enabled, cannot detect timer type\n" );
[Severity: High]
This is a pre-existing issue, but does returning -EBUSY here break watchdog handoff?
If the bootloader previously started the watchdog, this explicit failure in atcwdt_get_int_timer_type() propagates up and aborts atcwdt_probe().
Should the driver instead adopt the running watchdog by setting WDOG_HW_RUNNING and allowing the watchdog core to keep it pinged?
drivers/watchdog/atcwdt200_wdt.c static int atcwdt_get_int_timer_type(struct atcwdt_drv *drv_data) · line 281
Quoted 3 lines
drivers/watchdog/atcwdt200_wdt.c +0
-0}/*
I also noticed a few other pre-existing issues in this file:
drivers/watchdog/atcwdt200_wdt.c:atcwdt_get_timeout_params() {
...
rest_time_ms = timeout * 1000LL - div64_s64(1000LL << int_index, drv_data->clk_freq); result = atcwdt_get_clock_period(rest_time_ms * drv_data->clk_freq, TMR_RST, &rst_index);
...
}
[Severity: Medium]
This is a pre-existing issue, but is the rest time calculation missing a unit conversion?
Since rest_time_ms is in milliseconds, multiplying it by drv_data->clk_freq without dividing by 1000 produces a value 1000 times larger than the required clock ticks.
Will this predictably force the fallback path where rst_timer_params is clamped to 0?
drivers/watchdog/atcwdt200_wdt.c:atcwdt_restart() {
...
atcwdt_set_timeout(wdt_dev, 0); spin_lock(&drv_data->lock);
...
}
[Severity: High]
This is a pre-existing issue, but can this unconditional spin_lock() cause a system hang during panic or reboot?
When the system initiates a restart, atcwdt_restart() and its sub-function atcwdt_set_timeout() unconditionally acquire drv_data->lock.
Since restart handlers run with interrupts disabled and after other CPUs are halted via smp_send_stop(), will the restart handler spin infinitely if another CPU was stopped while holding this lock?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Guenter Roeck
maintainerQuoted 9 lines · On 7/22/26 19:26, [email protected] wrote:
From: Surendra Singh Chouhan <[email protected]>
atcwdt_get_int_timer_type()returnedTMR_UNKNOWN(enum value 3) whenCTRL_WDT_ENwas set in the control register.Because
atcwdt_probe()checks "ret =atcwdt_get_int_timer_type(drv_data); if (ret) return ret;", returningTMR_UNKNOWNcausedprobe()to return 3 instead of a valid negative error code.
Quoted 6 lines
Fix this by returning
-EBUSYviadev_err_probe()when the watchdog is already enabled and update the kernel-doc description accordingly.Fixes e4e0848ad046 ("watchdog: atcwdt200: Add driver for Andes ATCWDT200")Signed-off-by Surendra Singh Chouhan <[email protected]>---]
Change log goes here. Do you really expect me to look up the patch history to figure out what changed from v1 ?
Sure, this one was recent enough that I happen to remember, but I seriously fail to understand why people can't be bothered to add a couple of lines here to explain the changes they made.
Guenter
Quoted 29 lines
drivers/watchdog/atcwdt200_wdt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/watchdog/atcwdt200_wdt.c +4
-3@@ -260,9 +260,9 @@ static void atcwdt_get_timeout_params(struct atcwdt_drv *drv_data,* register to determine the interrupt timer type supported by the hardware. * * Note: This function must only be called when the ATCWDT200 watchdog is -* disabled. If the watchdog is enabled, this function returns TMR_UNKNOWN. +* disabled. If the watchdog is enabled, this function returns -EBUSY. * -* Returns: The interrupt timer type supported by the hardware. +* Returns: 0 on success or negative error code on failure. */ static int atcwdt_get_int_timer_type (struct atcwdt_drv *drv_data) {@@ -274,7 +274,8 @@ static int atcwdt_get_int_timer_type(struct atcwdt_drv *drv_data)regmap_read (drv_data->regmap,REG_CTRL , &val);if (val &CTRL_WDT_EN ) {spin_unlock (&drv_data->lock); -return TMR_UNKNOWN ; +return dev_err_probe (dev, -EBUSY , +"Watchdog is enabled, cannot detect timer type\n" ); }/*
Quoted 9 lines · On Thu, Jul 23, 2026 at 07:56:34AM +0530, [email protected] wrote:
From: Surendra Singh Chouhan <[email protected]>
atcwdt_get_int_timer_type()returnedTMR_UNKNOWN(enum value 3) whenCTRL_WDT_ENwas set in the control register.Because
atcwdt_probe()checks "ret =atcwdt_get_int_timer_type(drv_data); if (ret) return ret;", returningTMR_UNKNOWNcausedprobe()to return 3 instead of a valid negative error code.
Quoted 5 lines
Fix this by returning
-EBUSYviadev_err_probe()when the watchdog is already enabled and update the kernel-doc description accordingly.Fixes e4e0848ad046 ("watchdog: atcwdt200: Add driver for Andes ATCWDT200")Signed-off-by Surendra Singh Chouhan <[email protected]>
Applied. Next time please provide a change log.
Guenter