diff --git a/core/drivers/stm32_iwdg.c b/core/drivers/stm32_iwdg.c index 43ef1b1f9be..c7b7ae86bc4 100644 --- a/core/drivers/stm32_iwdg.c +++ b/core/drivers/stm32_iwdg.c @@ -188,11 +188,14 @@ static TEE_Result iwdg_wdt_init(struct wdt_chip *chip, unsigned long *max_timeout) { struct stm32_iwdg_device *iwdg = wdt_chip_to_iwdg(chip); + unsigned long rate = clk_get_rate(iwdg->clk_lsi); + + if (!rate) + return TEE_ERROR_GENERIC; /* Be safe and expect any counter to be above 2 */ - *min_timeout = 3 * IWDG_PRESCALER_256 / clk_get_rate(iwdg->clk_lsi); - *max_timeout = (IWDG_CNT_MASK + 1) * IWDG_PRESCALER_256 / - clk_get_rate(iwdg->clk_lsi); + *min_timeout = 3 * IWDG_PRESCALER_256 / rate; + *max_timeout = (IWDG_CNT_MASK + 1) * IWDG_PRESCALER_256 / rate; return TEE_SUCCESS; }