From ab390021b2a3bb4cc875f28a6f76d13de90d7457 Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Sat, 29 Aug 2026 00:13:45 +0800 Subject: [PATCH] watchdog: msc313e: Fix undefined behavior readw() returns a u16. Left shifting a u16 by 16 bits yields undefined behavior. Cast to u32 explicitly before the shift. Fixes: ffd264bd152c ("watchdog: msc313e: Check if the WDT was running at boot") Signed-off-by: Tzung-Bi Shih Link: https://patch.msgid.link/20260828161348.13212-7-tzungbi@kernel.org Signed-off-by: Guenter Roeck --- drivers/watchdog/msc313e_wdt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/msc313e_wdt.c b/drivers/watchdog/msc313e_wdt.c index c7d558fefc86..e28261c7a8d4 100644 --- a/drivers/watchdog/msc313e_wdt.c +++ b/drivers/watchdog/msc313e_wdt.c @@ -31,6 +31,16 @@ struct msc313e_wdt_priv { struct clk *clk; }; +static u32 msc313e_wdt_get_hw_timeout(struct msc313e_wdt_priv *priv) +{ + u16 low, high; + + low = readw(priv->base + REG_WDT_MAX_PRD_L); + high = readw(priv->base + REG_WDT_MAX_PRD_H); + + return ((u32)high << 16) | low; +} + static void msc313e_wdt_set_hw_timeout(struct msc313e_wdt_priv *priv, unsigned int timeout) { @@ -139,7 +149,7 @@ static int msc313e_wdt_probe(struct platform_device *pdev) 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 (msc313e_wdt_get_hw_timeout(priv)) { set_bit(WDOG_HW_RUNNING, &priv->wdev.status); /* * Keep the clock enabled. The watchdog core will skip the next