Skip to content

Commit

Permalink
[review] drivers: stm32_iwdg: provide timeout range
Browse files Browse the repository at this point in the history
Prevent division by zero.

Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
etienne-lms committed Dec 18, 2023
1 parent acbadca commit c81b980
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/drivers/stm32_iwdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c81b980

Please sign in to comment.