Unverified Commit 23569c8b authored by Luo Yifan's avatar Luo Yifan Committed by Mark Brown
Browse files

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: default avatarLuo Yifan <luoyifan@cmss.chinamobile.com>
Reviewed-by: default avatarOlivier Moysan <olivier.moysan@foss.st.com>
Link: https://patch.msgid.link/20241107015936.211902-1-luoyifan@cmss.chinamobile.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 63c1c879
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -317,7 +317,7 @@ static int stm32_sai_get_clk_div(struct stm32_sai_sub_data *sai,
	int div;

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