* [PATCH 1/5] watchdog: dw_wdt: move reset control deassertion before register access
2026-03-20 13:56 [PATCH 0/5] watchdog: dw_wdt: reset clean up and pm Artem Shimko
@ 2026-03-20 13:56 ` Artem Shimko
2026-03-20 13:56 ` [PATCH 2/5] watchdog: dw_wdt: add error handling for reset control deassertion Artem Shimko
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Artem Shimko @ 2026-03-20 13:56 UTC (permalink / raw)
To: wim, linux, p.zabel, Sergey.Semin, mika.westerberg, andi.shyti
Cc: Artem Shimko, linux-watchdog, linux-kernel
The watchdog controller must be taken out of reset before any register
access is attempted. Currently reset_control_deassert() is called after
dw_wdt_update_mode() which performs register read/write operations. If
the reset line is asserted, accessing registers may result in undefined
behavior or bus hangs.
Move reset_control_deassert() before dw_wdt_update_mode() to ensure the
controller is properly deasserted before the first register access. The
reset_control_assert() in the error path remains to properly revert the
reset state on probe failure.
Fixes: 46a1946314bf ("watchdog: dw_wdt: Add pre-timeouts support")
Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
---
drivers/watchdog/dw_wdt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index c3fbb6068c52..3450402b7707 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -592,6 +592,8 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
if (IS_ERR(dw_wdt->rst))
return PTR_ERR(dw_wdt->rst);
+ reset_control_deassert(dw_wdt->rst);
+
/* Enable normal reset without pre-timeout by default. */
dw_wdt_update_mode(dw_wdt, DW_WDT_RMOD_RESET);
@@ -617,8 +619,6 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
dw_wdt->wdd.info = &dw_wdt_ident;
}
- reset_control_deassert(dw_wdt->rst);
-
ret = dw_wdt_init_timeouts(dw_wdt, dev);
if (ret)
goto out_assert_rst;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/5] watchdog: dw_wdt: add error handling for reset control deassertion
2026-03-20 13:56 [PATCH 0/5] watchdog: dw_wdt: reset clean up and pm Artem Shimko
2026-03-20 13:56 ` [PATCH 1/5] watchdog: dw_wdt: move reset control deassertion before register access Artem Shimko
@ 2026-03-20 13:56 ` Artem Shimko
2026-03-20 13:56 ` [PATCH 3/5] watchdog: dw_wdt: Use devm_reset_control_get_optional_shared_deasserted Artem Shimko
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Artem Shimko @ 2026-03-20 13:56 UTC (permalink / raw)
To: wim, linux, p.zabel, Sergey.Semin, mika.westerberg, andi.shyti
Cc: Artem Shimko, linux-watchdog, linux-kernel
The reset_control_deassert() call was performed without checking its
return value. This could lead to probe continuing even when the device
reset wasn't properly deasserted, potentially causing register access
failures or undefined behavior later.
Add proper error checking for reset_control_deassert() and return the
error code if deassertion fails. Also replace &pdev->dev with the local
dev pointer for consistency with the rest of the probe function.
Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
---
drivers/watchdog/dw_wdt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 3450402b7707..724ba435b3c8 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -588,11 +588,13 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
if (IS_ERR(dw_wdt->pclk))
return PTR_ERR(dw_wdt->pclk);
- dw_wdt->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL);
+ dw_wdt->rst = devm_reset_control_get_optional_shared(dev, NULL);
if (IS_ERR(dw_wdt->rst))
return PTR_ERR(dw_wdt->rst);
- reset_control_deassert(dw_wdt->rst);
+ ret = reset_control_deassert(dw_wdt->rst);
+ if (ret)
+ return ret;
/* Enable normal reset without pre-timeout by default. */
dw_wdt_update_mode(dw_wdt, DW_WDT_RMOD_RESET);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/5] watchdog: dw_wdt: Use devm_reset_control_get_optional_shared_deasserted
2026-03-20 13:56 [PATCH 0/5] watchdog: dw_wdt: reset clean up and pm Artem Shimko
2026-03-20 13:56 ` [PATCH 1/5] watchdog: dw_wdt: move reset control deassertion before register access Artem Shimko
2026-03-20 13:56 ` [PATCH 2/5] watchdog: dw_wdt: add error handling for reset control deassertion Artem Shimko
@ 2026-03-20 13:56 ` Artem Shimko
2026-03-20 13:56 ` [PATCH 4/5] watchdog: dw_wdt: manage reset line during system suspend/resume Artem Shimko
2026-03-20 13:56 ` [PATCH 5/5] watchdog: dw_wdt: clean up error paths in resume function Artem Shimko
4 siblings, 0 replies; 6+ messages in thread
From: Artem Shimko @ 2026-03-20 13:56 UTC (permalink / raw)
To: wim, linux, p.zabel, Sergey.Semin, mika.westerberg, andi.shyti
Cc: Artem Shimko, linux-watchdog, linux-kernel
The driver currently manually manages reset control by calling
reset_control_deassert() during probe and reset_control_assert() in
error paths and remove. This approach is error-prone and requires
explicit cleanup in multiple places.
Replace devm_reset_control_get_optional_shared() with
devm_reset_control_get_optional_shared_deasserted() which automatically
deasserts the reset line on acquisition and ensures it will be asserted
again when the device is removed. This eliminates the need for manual
reset control in probe error paths, remove, and allows simplifying the
code by removing out_assert_rst label and related assertions. Use
dev_err_probe() for consistent error reporting.
Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
---
drivers/watchdog/dw_wdt.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 724ba435b3c8..27b5098832d5 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -588,13 +588,9 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
if (IS_ERR(dw_wdt->pclk))
return PTR_ERR(dw_wdt->pclk);
- dw_wdt->rst = devm_reset_control_get_optional_shared(dev, NULL);
+ dw_wdt->rst = devm_reset_control_get_optional_shared_deasserted(dev, NULL);
if (IS_ERR(dw_wdt->rst))
- return PTR_ERR(dw_wdt->rst);
-
- ret = reset_control_deassert(dw_wdt->rst);
- if (ret)
- return ret;
+ return dev_err_probe(dev, PTR_ERR(dw_wdt->rst), "failed to acquire reset\n");
/* Enable normal reset without pre-timeout by default. */
dw_wdt_update_mode(dw_wdt, DW_WDT_RMOD_RESET);
@@ -623,7 +619,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
ret = dw_wdt_init_timeouts(dw_wdt, dev);
if (ret)
- goto out_assert_rst;
+ return ret;
wdd = &dw_wdt->wdd;
wdd->ops = &dw_wdt_ops;
@@ -657,15 +653,11 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
ret = watchdog_register_device(wdd);
if (ret)
- goto out_assert_rst;
+ return ret;
dw_wdt_dbgfs_init(dw_wdt);
return 0;
-
-out_assert_rst:
- reset_control_assert(dw_wdt->rst);
- return ret;
}
static void dw_wdt_drv_remove(struct platform_device *pdev)
@@ -675,7 +667,6 @@ static void dw_wdt_drv_remove(struct platform_device *pdev)
dw_wdt_dbgfs_clear(dw_wdt);
watchdog_unregister_device(&dw_wdt->wdd);
- reset_control_assert(dw_wdt->rst);
}
#ifdef CONFIG_OF
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] watchdog: dw_wdt: manage reset line during system suspend/resume
2026-03-20 13:56 [PATCH 0/5] watchdog: dw_wdt: reset clean up and pm Artem Shimko
` (2 preceding siblings ...)
2026-03-20 13:56 ` [PATCH 3/5] watchdog: dw_wdt: Use devm_reset_control_get_optional_shared_deasserted Artem Shimko
@ 2026-03-20 13:56 ` Artem Shimko
2026-03-20 13:56 ` [PATCH 5/5] watchdog: dw_wdt: clean up error paths in resume function Artem Shimko
4 siblings, 0 replies; 6+ messages in thread
From: Artem Shimko @ 2026-03-20 13:56 UTC (permalink / raw)
To: wim, linux, p.zabel, Sergey.Semin, mika.westerberg, andi.shyti
Cc: Artem Shimko, linux-watchdog, linux-kernel
The watchdog controller reset line is not currently managed during system
suspend/resume. This can lead to an inconsistent hardware state when
resuming from suspend, as the controller may not be properly reinitialized.
Assert the reset line before disabling clocks during suspend to ensure
the controller is held in reset while power is gated. During resume,
deassert the reset after clocks are enabled and before restoring register
state to guarantee the controller is properly initialized. Add proper
error handling for reset control operations during resume with appropriate
cleanup path on failure.
Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
---
drivers/watchdog/dw_wdt.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 27b5098832d5..c2c5dc6e54e7 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -382,6 +382,8 @@ static int dw_wdt_suspend(struct device *dev)
dw_wdt->control = readl(dw_wdt->regs + WDOG_CONTROL_REG_OFFSET);
dw_wdt->timeout = readl(dw_wdt->regs + WDOG_TIMEOUT_RANGE_REG_OFFSET);
+ reset_control_assert(dw_wdt->rst);
+
clk_disable_unprepare(dw_wdt->pclk);
clk_disable_unprepare(dw_wdt->clk);
@@ -402,12 +404,22 @@ static int dw_wdt_resume(struct device *dev)
return err;
}
+ err = reset_control_deassert(dw_wdt->rst);
+ if (err)
+ goto unprepare_pclk;
+
writel(dw_wdt->timeout, dw_wdt->regs + WDOG_TIMEOUT_RANGE_REG_OFFSET);
writel(dw_wdt->control, dw_wdt->regs + WDOG_CONTROL_REG_OFFSET);
dw_wdt_ping(&dw_wdt->wdd);
return 0;
+
+unprepare_clk:
+ clk_disable_unprepare(dw_wdt->pclk);
+ clk_disable_unprepare(dw_wdt->clk);
+
+ return err;
}
static DEFINE_SIMPLE_DEV_PM_OPS(dw_wdt_pm_ops, dw_wdt_suspend, dw_wdt_resume);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 5/5] watchdog: dw_wdt: clean up error paths in resume function
2026-03-20 13:56 [PATCH 0/5] watchdog: dw_wdt: reset clean up and pm Artem Shimko
` (3 preceding siblings ...)
2026-03-20 13:56 ` [PATCH 4/5] watchdog: dw_wdt: manage reset line during system suspend/resume Artem Shimko
@ 2026-03-20 13:56 ` Artem Shimko
4 siblings, 0 replies; 6+ messages in thread
From: Artem Shimko @ 2026-03-20 13:56 UTC (permalink / raw)
To: wim, linux, p.zabel, Sergey.Semin, mika.westerberg, andi.shyti
Cc: Artem Shimko, linux-watchdog, linux-kernel
Clean up of dw_wdt_resume() function.
Rework the error handling to use properly named labels that match the
cleanup order. Use unprepare_clk for clock disable and unprepare_pclk
for pclk disable path.
Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
---
drivers/watchdog/dw_wdt.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index c2c5dc6e54e7..c89e1fb91b1f 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -393,16 +393,15 @@ static int dw_wdt_suspend(struct device *dev)
static int dw_wdt_resume(struct device *dev)
{
struct dw_wdt *dw_wdt = dev_get_drvdata(dev);
- int err = clk_prepare_enable(dw_wdt->clk);
+ int err;
+ err = clk_prepare_enable(dw_wdt->clk);
if (err)
return err;
err = clk_prepare_enable(dw_wdt->pclk);
- if (err) {
- clk_disable_unprepare(dw_wdt->clk);
- return err;
- }
+ if (err)
+ goto unprepare_clk;
err = reset_control_deassert(dw_wdt->rst);
if (err)
@@ -415,8 +414,9 @@ static int dw_wdt_resume(struct device *dev)
return 0;
-unprepare_clk:
+unprepare_pclk:
clk_disable_unprepare(dw_wdt->pclk);
+unprepare_clk:
clk_disable_unprepare(dw_wdt->clk);
return err;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread