diff mbox series

[2/2] watchdog: imx7ulp_wdt: Add TOVAL range check

Message ID 20241027105323.93699-3-wahrenst@gmx.net
State New
Headers show
Series watchdog: imx7ulp_wdt: Improve readability | expand

Commit Message

Stefan Wahren Oct. 27, 2024, 10:53 a.m. UTC
The WDOG Timeout Value (TOVAL) is a 16 bit value, which is stored
at the beginning of a 32 bit register. So add a range check to
prevent writing in the reserved register area.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/watchdog/imx7ulp_wdt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

--
2.34.1
diff mbox series

Patch

diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c
index 0f92d2217088..a7574f9c9150 100644
--- a/drivers/watchdog/imx7ulp_wdt.c
+++ b/drivers/watchdog/imx7ulp_wdt.c
@@ -48,6 +48,8 @@ 

 #define RETRY_MAX 5

+#define TOVAL_MAX	0xFFFF
+
 static bool nowayout = WATCHDOG_NOWAYOUT;
 module_param(nowayout, bool, 0000);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
@@ -192,6 +194,9 @@  static int imx7ulp_wdt_set_timeout(struct watchdog_device *wdog,
 	int ret;
 	u32 loop = RETRY_MAX;

+	if (toval > TOVAL_MAX)
+		return -EINVAL;
+
 	do {
 		ret = _imx7ulp_wdt_set_timeout(wdt, toval);
 		val = readl(wdt->base + WDOG_TOVAL);
@@ -286,6 +291,9 @@  static int imx7ulp_wdt_init(struct imx7ulp_wdt_device *wdt,
 	int ret;
 	u32 loop = RETRY_MAX;

+	if (timeout_clks > TOVAL_MAX)
+		return -EINVAL;
+
 	if (wdt->hw->prescaler_enable)
 		val |= WDOG_CS_PRES;