From: Luo Yifan Date: Wed, 6 Nov 2024 01:46:54 +0000 (+0800) Subject: ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() X-Git-Tag: v5.10.231~414 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ddd61392263d87cd94ce2337fa13eda8c8ac612b;p=thirdparty%2Fkernel%2Fstable.git ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() [ Upstream commit 63c1c87993e0e5bb11bced3d8224446a2bc62338 ] 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 Link: https://patch.msgid.link/20241106014654.206860-1-luoyifan@cmss.chinamobile.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 3aa1cf2624020..3a7f0102b4c5c 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -380,8 +380,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;