From patchwork Thu Nov 7 01:59:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luo Yifan X-Patchwork-Id: 13865741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6615CD29FBC for ; Thu, 7 Nov 2024 02:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kScesYIA+RDPrFaRjvMhRDMsnbRBSG3s+fi7AIMag7I=; b=LhGextiyXogxSpwkRwPwXYr/wu B+xVbVAAdFyEXEAh0rDOwnw1CneJFfvyn5Xq759UpCreNe3XJ4dFM6eVjrYUWZkhk+lqnC4mgFzE+ W3aA94rFxcm3M+cMwb+pOYUUsVVw+GPjj06KZSr73kI28ISyssAcHXzYQxXyBr0eSTVSOLvkk1BaL CPVDUbEQs7a+9FVnO0UHx7Ma/3vWEhLxen0uoA54mxkTJh0yeL1iJbztCSK7x6Kz5pdTpd2EF0pkS tSE+lN6+sCrXz1MHOcXUzPlxehpsNY1mWKh3Ldxm4PlWBTL0QMPoMJDYi1neq7iPPdol23BtarTEG 56qHk8+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8s4m-00000005R2e-0bWZ; Thu, 07 Nov 2024 02:16:48 +0000 Received: from cmccmta8.chinamobile.com ([111.22.67.151] helo=cmccmta2.chinamobile.com) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8roL-00000005Muk-15gx for linux-arm-kernel@lists.infradead.org; Thu, 07 Nov 2024 02:00:02 +0000 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app06-12006 (RichMail) with SMTP id 2ee6672c1f0b1ad-b1a79; Thu, 07 Nov 2024 09:59:39 +0800 (CST) X-RM-TRANSID: 2ee6672c1f0b1ad-b1a79 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain (unknown[223.108.79.103]) by rmsmtp-syy-appsvr03-12003 (RichMail) with SMTP id 2ee3672c1f0aa48-4d18e; Thu, 07 Nov 2024 09:59:39 +0800 (CST) X-RM-TRANSID: 2ee3672c1f0aa48-4d18e From: Luo Yifan To: olivier.moysan@foss.st.com Cc: arnaud.pouliquen@foss.st.com, broonie@kernel.org, lgirdwood@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, luoyifan@cmss.chinamobile.com, perex@perex.cz, tiwai@suse.com Subject: [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_get_clk_div() Date: Thu, 7 Nov 2024 09:59:36 +0800 Message-Id: <20241107015936.211902-1-luoyifan@cmss.chinamobile.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241106_175949_879592_C31D079E X-CRM114-Status: GOOD ( 10.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Olivier Moysan --- sound/soc/stm/stm32_sai_sub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 7bc4a96b7..43fb1dcb9 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -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; }