[PATCH 6/6] watchdog: rzv2h: Avoid 32-bit overflow in max_hw_heartbeat_ms calculation
From: Lee Jones
Date: Thu Dec 03 2026 - 12:31:43 EST
For RZ/T2H SoCs, MILLI * timeout_cycles * cks_div equals 33,554,432,000,
which overflows 32-bit unsigned long on 32-bit builds.
Perform the multiplication in 64-bit arithmetic and divide using
div64_ul().
Fixes: 2b2069763527 ("watchdog: rzv2h: Add support for RZ/T2H")
Closes: https://sashiko.dev/#/bug/linux-441577c6-bf0c-46ed-bc43-676afdcc85bf
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/watchdog/rzv2h_wdt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/rzv2h_wdt.c b/drivers/watchdog/rzv2h_wdt.c
index 67869468edd8..81bf6a36b139 100644
--- a/drivers/watchdog/rzv2h_wdt.c
+++ b/drivers/watchdog/rzv2h_wdt.c
@@ -8,6 +8,7 @@
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/kernel.h>
+#include <linux/math64.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
@@ -310,8 +311,9 @@ static int rzv2h_wdt_probe(struct platform_device *pdev)
if (!rate)
return dev_err_probe(dev, -EINVAL, "Invalid clock rate\n");
- priv->wdev.max_hw_heartbeat_ms = (MILLI * priv->of_data->timeout_cycles *
- priv->of_data->cks_div) / rate;
+ priv->wdev.max_hw_heartbeat_ms =
+ div64_ul((u64)MILLI * priv->of_data->timeout_cycles *
+ priv->of_data->cks_div, rate);
dev_dbg(dev, "max hw timeout of %dms\n", priv->wdev.max_hw_heartbeat_ms);
ret = devm_pm_runtime_enable(dev);
--
2.56.1.911.g883d8bcb20-goog