[PATCH v4 01/15] watchdog: stm32_iwdg: set driver data before requesting interrupt

Antonio Borneo antonio.borneo at foss.st.com
Mon Nov 16 05:24:02 PST 2026


The interrupt handler accesses the driver data, which is currently
set after devm_request_irq() returns.

If the watchdog was started by the bootloader and a pretimeout
interrupt is pending, the handler can run before the driver data
is set, resulting in a NULL pointer dereference.

Move the IRQ request after setting the driver data to ensure it
is available when the interrupt handler runs.

Fixes: 3ab1663af6c1 ("watchdog: stm32_iwdg: Add pretimeout support")
Reported-by: Sashiko <sashiko-bot at kernel.org>
Link: https://sashiko.dev/#/patchset/20261106163429.618392-1-antonio.borneo%40foss.st.com?part=3
Signed-off-by: Antonio Borneo <antonio.borneo at foss.st.com>
---
 drivers/watchdog/stm32_iwdg.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index a8d2db2d3cf8b..2bac4ce5ed3f8 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -346,15 +346,15 @@ static int stm32_iwdg_probe(struct platform_device *pdev)
 	wdd->max_hw_heartbeat_ms = ((RLR_MAX + 1) * wdt->data->max_prescaler *
 				    1000) / wdt->rate;
 
+	watchdog_set_drvdata(wdd, wdt);
+	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
+	watchdog_init_timeout(wdd, 0, dev);
+
 	/* Initialize IRQ, this might override wdd->info, hence it is here. */
 	ret = stm32_iwdg_irq_init(pdev, wdt);
 	if (ret)
 		return ret;
 
-	watchdog_set_drvdata(wdd, wdt);
-	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
-	watchdog_init_timeout(wdd, 0, dev);
-
 	/*
 	 * In case of CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
 	 * (Means U-Boot/bootloaders leaves the watchdog running)
-- 
2.34.1




More information about the linux-arm-kernel mailing list