diff mbox series

watchdog: mpc8xxx: Fix timer value

Message ID 31a49f86032687601e617da89f831a162303f283.1719476762.git.christophe.leroy@csgroup.eu
State Accepted
Commit 7a74e31938ad7534452efcf9ce6c82fc75402f59
Delegated to: Tom Rini
Headers show
Series watchdog: mpc8xxx: Fix timer value | expand

Commit Message

Christophe Leroy June 27, 2024, 8:26 a.m. UTC
Timer value is a 16 bits calculated from the wanted timeout and the
system clock. On powerpc/8xx, a timeout of 2s gives a value which
is over U16_MAX so U16_MAX shall be used. But the calculation is
casted to u16 so at the end the result is 63770 instead of 128906.

So the timer gets loaded with 63770 instead of 65535. It is not
a big difference in that case, but lets make the code correct and
cast to u32 instead of u16.

Fixes: 26e8ebcd7cb7 ("watchdog: mpc8xxx: Make it generic")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 drivers/watchdog/mpc8xxx_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tom Rini July 5, 2024, 10:40 p.m. UTC | #1
On Thu, Jun 27, 2024 at 10:26:08AM +0200, Christophe Leroy wrote:

> Timer value is a 16 bits calculated from the wanted timeout and the
> system clock. On powerpc/8xx, a timeout of 2s gives a value which
> is over U16_MAX so U16_MAX shall be used. But the calculation is
> casted to u16 so at the end the result is 63770 instead of 128906.
> 
> So the timer gets loaded with 63770 instead of 65535. It is not
> a big difference in that case, but lets make the code correct and
> cast to u32 instead of u16.
> 
> Fixes: 26e8ebcd7cb7 ("watchdog: mpc8xxx: Make it generic")
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index f28636ca90..67e687a364 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -44,7 +44,7 @@  static int mpc8xxx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
 	struct mpc8xxx_wdt_priv *priv = dev_get_priv(dev);
 	const char *mode = env_get("watchdog_mode");
 	ulong prescaler = dev_get_driver_data(dev);
-	u16 swtc = min_t(u16, timeout * get_board_sys_clk() / 1000 / prescaler, U16_MAX);
+	u16 swtc = min_t(u32, timeout * get_board_sys_clk() / 1000 / prescaler, U16_MAX);
 	u32 val;
 
 	mpc8xxx_wdt_reset(dev);