[PATCH v4 01/15] watchdog: stm32_iwdg: set driver data before requesting interrupt
From: Antonio Borneo
Date: Mon Nov 16 2026 - 08:25:03 EST
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@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20261106163429.618392-1-antonio.borneo%40foss.st.com?part=3
Signed-off-by: Antonio Borneo <antonio.borneo@xxxxxxxxxxx>
---
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