mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] watchdog: msc313e: Fix issues Sashiko reported
@ 2026-08-27  4:46 Tzung-Bi Shih
  2026-08-27  4:46 ` [PATCH 1/2] watchdog: msc313e: Fix NULL pointer dereference in PM callbacks Tzung-Bi Shih
  2026-08-27  4:47 ` [PATCH 2/2] watchdog: msc313e: Enable clock before accessing hardware registers Tzung-Bi Shih
  0 siblings, 2 replies; 4+ messages in thread
From: Tzung-Bi Shih @ 2026-08-27  4:46 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: Daniel Palmer, Romain Perier, linux-watchdog, linux-kernel, tzungbi

The series fixes the two issues reported by Sashiko in [1].

[1] https://lore.kernel.org/all/20260826062035.7645D1F000E9@smtp.kernel.org/

Tzung-Bi Shih (2):
  watchdog: msc313e: Fix NULL pointer dereference in PM callbacks
  watchdog: msc313e: Enable clock before accessing hardware registers

 drivers/watchdog/msc313e_wdt.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

-- 
2.55.0.887.g758fc8c411-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] watchdog: msc313e: Fix NULL pointer dereference in PM callbacks
  2026-08-27  4:46 [PATCH 0/2] watchdog: msc313e: Fix issues Sashiko reported Tzung-Bi Shih
@ 2026-08-27  4:46 ` Tzung-Bi Shih
  2026-08-28 14:42   ` Guenter Roeck
  2026-08-27  4:47 ` [PATCH 2/2] watchdog: msc313e: Enable clock before accessing hardware registers Tzung-Bi Shih
  1 sibling, 1 reply; 4+ messages in thread
From: Tzung-Bi Shih @ 2026-08-27  4:46 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: Daniel Palmer, Romain Perier, linux-watchdog, linux-kernel, tzungbi

msc313e_wdt_probe() doesn't set the driver data for the platform device.
As a result, dev_get_drvdata() in msc313e_wdt_suspend() and
msc313e_wdt_resume() will return NULL, leading to a NULL pointer
dereference afterward.

Set the platform device driver data in msc313e_wdt_probe().

Fixes: e9800b799464 ("watchdog: Add Mstar MSC313e WDT driver")
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 drivers/watchdog/msc313e_wdt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c
index d962589e2c55..f69d66971c41 100644
--- a/drivers/watchdog/msc313e_wdt.c
+++ b/drivers/watchdog/msc313e_wdt.c
@@ -124,6 +124,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev)
 		set_bit(WDOG_HW_RUNNING, &priv->wdev.status);
 
 	watchdog_set_drvdata(&priv->wdev, priv);
+	platform_set_drvdata(pdev, priv);
 
 	watchdog_init_timeout(&priv->wdev, timeout, dev);
 	watchdog_stop_on_reboot(&priv->wdev);
-- 
2.55.0.887.g758fc8c411-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] watchdog: msc313e: Enable clock before accessing hardware registers
  2026-08-27  4:46 [PATCH 0/2] watchdog: msc313e: Fix issues Sashiko reported Tzung-Bi Shih
  2026-08-27  4:46 ` [PATCH 1/2] watchdog: msc313e: Fix NULL pointer dereference in PM callbacks Tzung-Bi Shih
@ 2026-08-27  4:47 ` Tzung-Bi Shih
  1 sibling, 0 replies; 4+ messages in thread
From: Tzung-Bi Shih @ 2026-08-27  4:47 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck
  Cc: Daniel Palmer, Romain Perier, linux-watchdog, linux-kernel, tzungbi

msc313e_wdt_probe() reads from hardware registers without ensuring the
required clock is enabled.  Furthermore, if the bootloader leaves the
watchdog running, msc313e_wdt_probe() sets WDOG_HW_RUNNING without
increasing the clock's reference count.

While the clock is currently supplied as a fixed clock by the device
tree (`xtal_div2` in arch/arm/boot/dts/sigmastar/mstar-v7.dtsi) which
masks the physical issue, this still violates the API usage.

Call clk_prepare_enable() before reading WDT registers.  If the WDT is
running, leave the clock enabled so the CCF reference counter is
balanced.

Fixes: ffd264bd152c ("watchdog: msc313e: Check if the WDT was running at boot")
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 drivers/watchdog/msc313e_wdt.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c
index f69d66971c41..b279ef645430 100644
--- a/drivers/watchdog/msc313e_wdt.c
+++ b/drivers/watchdog/msc313e_wdt.c
@@ -97,6 +97,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct msc313e_wdt_priv *priv;
+	int ret;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -119,9 +120,21 @@ static int msc313e_wdt_probe(struct platform_device *pdev)
 	priv->wdev.max_timeout = U32_MAX / clk_get_rate(priv->clk);
 	priv->wdev.timeout = MSC313E_WDT_DEFAULT_TIMEOUT;
 
+	ret = clk_prepare_enable(priv->clk);
+	if (ret)
+		return ret;
+
 	/* If the period is non-zero the WDT is running */
-	if (readw(priv->base + REG_WDT_MAX_PRD_L) | (readw(priv->base + REG_WDT_MAX_PRD_H) << 16))
+	if (readw(priv->base + REG_WDT_MAX_PRD_L) | (readw(priv->base + REG_WDT_MAX_PRD_H) << 16)) {
 		set_bit(WDOG_HW_RUNNING, &priv->wdev.status);
+		/*
+		 * Keep the clock enabled. The watchdog core will skip the next
+		 * start() and a future stop() will balance the CCF reference
+		 * count.
+		 */
+	} else {
+		clk_disable_unprepare(priv->clk);
+	}
 
 	watchdog_set_drvdata(&priv->wdev, priv);
 	platform_set_drvdata(pdev, priv);
-- 
2.55.0.887.g758fc8c411-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] watchdog: msc313e: Fix NULL pointer dereference in PM callbacks
  2026-08-27  4:46 ` [PATCH 1/2] watchdog: msc313e: Fix NULL pointer dereference in PM callbacks Tzung-Bi Shih
@ 2026-08-28 14:42   ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2026-08-28 14:42 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Wim Van Sebroeck, Daniel Palmer, Romain Perier, linux-watchdog,
	linux-kernel

On Thu, Aug 27, 2026 at 04:46:59AM +0000, Tzung-Bi Shih wrote:
> msc313e_wdt_probe() doesn't set the driver data for the platform device.
> As a result, dev_get_drvdata() in msc313e_wdt_suspend() and
> msc313e_wdt_resume() will return NULL, leading to a NULL pointer
> dereference afterward.
> 
> Set the platform device driver data in msc313e_wdt_probe().
> 
> Fixes: e9800b799464 ("watchdog: Add Mstar MSC313e WDT driver")
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

Applied.

Thanks,
Guenter

> ---
>  drivers/watchdog/msc313e_wdt.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c
> index d962589e2c55..f69d66971c41 100644
> --- a/drivers/watchdog/msc313e_wdt.c
> +++ b/drivers/watchdog/msc313e_wdt.c
> @@ -124,6 +124,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev)
>  		set_bit(WDOG_HW_RUNNING, &priv->wdev.status);
>  
>  	watchdog_set_drvdata(&priv->wdev, priv);
> +	platform_set_drvdata(pdev, priv);
>  
>  	watchdog_init_timeout(&priv->wdev, timeout, dev);
>  	watchdog_stop_on_reboot(&priv->wdev);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-28 14:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-27  4:46 [PATCH 0/2] watchdog: msc313e: Fix issues Sashiko reported Tzung-Bi Shih
2026-08-27  4:46 ` [PATCH 1/2] watchdog: msc313e: Fix NULL pointer dereference in PM callbacks Tzung-Bi Shih
2026-08-28 14:42   ` Guenter Roeck
2026-08-27  4:47 ` [PATCH 2/2] watchdog: msc313e: Enable clock before accessing hardware registers Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®