summaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/stm32_iwdg.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-09-30 09:19:57 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-10-02 05:59:55 +0200
commitf245581eb865c1ed62fb6b8a382ab7bf6b0f6d38 (patch)
treee7e502c07b94862bcb697fa82aa2277ed60dc9cc /drivers/watchdog/stm32_iwdg.c
parentd52d80666a54b8fa5ae1d52506b9638c512f130e (diff)
downloadbarebox-f245581eb865c1ed62fb6b8a382ab7bf6b0f6d38.tar.gz
barebox-f245581eb865c1ed62fb6b8a382ab7bf6b0f6d38.tar.xz
watchdog: fix division-by-zero when clock rate == 0
Instead of storing the clk into the driver's device-specific private data, just store the rate and make sure it's != 0 on probe. This aligns us with what Linux does for the STM32 IWDG and DW WDT. Reported-by: clang-analyzer-10 Cc: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/watchdog/stm32_iwdg.c')
-rw-r--r--drivers/watchdog/stm32_iwdg.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index 9e38f1a669..4d7a263b7e 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -157,6 +157,8 @@ static int stm32_iwdg_probe(struct device_d *dev)
return ret;
wd->rate = clk_get_rate(clk);
+ if (wd->rate == 0)
+ return -EINVAL;
if (data->has_pclk) {
clk = clk_get(dev, "pclk");