Thread (1 message) 1 message, 1 author, 2024-11-12

[PATCH AUTOSEL 5.4 3/5] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate()

flat view
STALE698d

From: Sasha Levin <sashal@kernel.org>
Date: 2024-11-12 10:38:23
Also in: alsa-devel, linux-sound, lkml, stable
Subsystem: sound, sound - soc layer / dynamic audio power management (asoc), stm32 audio (asoc) drivers, the rest · Maintainers: Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown, Olivier Moysan, Arnaud Pouliquen, Linus Torvalds

From: Luo Yifan <redacted>

[ 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 <redacted>
Link: https://patch.msgid.link/20241106014654.206860-1-luoyifan@cmss.chinamobile.com (local)
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/stm/stm32_sai_sub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c
index 7e965848796c3..b7dc9d3192597 100644
--- a/sound/soc/stm/stm32_sai_sub.c
+++ b/sound/soc/stm/stm32_sai_sub.c
@@ -379,8 +379,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;
 
-- 
2.43.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help