]> www.infradead.org Git - users/hch/misc.git/commitdiff
ASoC: stm: Prevent potential division by zero in stm32_sai_get_clk_div()
authorLuo Yifan <luoyifan@cmss.chinamobile.com>
Thu, 7 Nov 2024 01:59:36 +0000 (09:59 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 7 Nov 2024 13:07:17 +0000 (13:07 +0000)
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>
sound/soc/stm/stm32_sai_sub.c

index 2570daa3e225c90d4a7447f9e581abf26376a2f8..5828f9dd866e4d7f7eb3c9456c25b6149062209d 100644 (file)
@@ -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;
        }