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: ffd264bd15 ("watchdog: msc313e: Check if the WDT was running at boot")
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20260828161348.13212-7-tzungbi@kernel.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Tzung-Bi Shih 2026-08-29 00:13:45 +08:00 committed by Guenter Roeck
parent 4f6817c9ef
commit ab390021b2

View File

@ -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