mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate()
@ 2024-11-06  1:46 Luo Yifan
  2024-11-06  9:27 ` Olivier MOYSAN
  2024-11-07 15:35 ` [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() Mark Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Luo Yifan @ 2024-11-06  1:46 UTC (permalink / raw)
  To: olivier.moysan, arnaud.pouliquen, lgirdwood, broonie, perex, tiwai
  Cc: linux-sound, linux-stm32, linux-arm-kernel, linux-kernel, Luo Yifan

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>
---
 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 7bc4a96b7..2570daa3e 100644
--- a/sound/soc/stm/stm32_sai_sub.c
+++ b/sound/soc/stm/stm32_sai_sub.c
@@ -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;
 
-- 
2.27.0




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-11-07 15:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-06  1:46 [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() Luo Yifan
2024-11-06  9:27 ` Olivier MOYSAN
2024-11-07  1:45   ` Luo Yifan
2024-11-07  1:59   ` [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_get_clk_div() Luo Yifan
2024-11-07  9:48     ` Olivier MOYSAN
2024-11-07 15:35 ` [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®