Skip to content

Commit

Permalink
ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round…
Browse files Browse the repository at this point in the history
…_rate()

This patch checks if div is less than or equal to zero (div <= 0). If
div is zero or negative, the function returns -EINVAL, ensuring the
division operation (*prate / div) is safe to perform.

Signed-off-by: Luo Yifan <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
Luo Yifan authored and broonie committed Nov 7, 2024
1 parent 8c21e40 commit 63c1c87
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sound/soc/stm/stm32_sai_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ static long stm32_sai_mclk_round_rate(struct clk_hw *hw, unsigned long rate,
int div;

div = stm32_sai_get_clk_div(sai, *prate, rate);
if (div < 0)
return div;
if (div <= 0)
return -EINVAL;

mclk->freq = *prate / div;

Expand Down

0 comments on commit 63c1c87

Please sign in to comment.