Skip to content

Commit 63c1c87

Browse files
Luo Yifanbroonie
authored andcommitted
ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_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 <luoyifan@cmss.chinamobile.com> Link: https://patch.msgid.link/20241106014654.206860-1-luoyifan@cmss.chinamobile.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 8c21e40 commit 63c1c87

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sound/soc/stm/stm32_sai_sub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ static long stm32_sai_mclk_round_rate(struct clk_hw *hw, unsigned long rate,
378378
int div;
379379

380380
div = stm32_sai_get_clk_div(sai, *prate, rate);
381-
if (div < 0)
382-
return div;
381+
if (div <= 0)
382+
return -EINVAL;
383383

384384
mclk->freq = *prate / div;
385385

0 commit comments

Comments
 (0)