Skip to content

Commit 23569c8

Browse files
Luo Yifanbroonie
authored andcommitted
ASoC: stm: Prevent potential division by zero in stm32_sai_get_clk_div()
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 is safe to perform. Signed-off-by: Luo Yifan <luoyifan@cmss.chinamobile.com> Reviewed-by: Olivier Moysan <olivier.moysan@foss.st.com> Link: https://patch.msgid.link/20241107015936.211902-1-luoyifan@cmss.chinamobile.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 63c1c87 commit 23569c8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sound/soc/stm/stm32_sai_sub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int stm32_sai_get_clk_div(struct stm32_sai_sub_data *sai,
317317
int div;
318318

319319
div = DIV_ROUND_CLOSEST(input_rate, output_rate);
320-
if (div > SAI_XCR1_MCKDIV_MAX(version)) {
320+
if (div > SAI_XCR1_MCKDIV_MAX(version) || div <= 0) {
321321
dev_err(&sai->pdev->dev, "Divider %d out of range\n", div);
322322
return -EINVAL;
323323
}

0 commit comments

Comments
 (0)