From patchwork Wed Nov 6 01:46:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luo Yifan X-Patchwork-Id: 13863826 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 2CD62D35E5D for ; Wed, 6 Nov 2024 01:49:10 +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: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:In-Reply-To:References:List-Owner; bh=jbQuAirramH5NKXP170nuUfwphAaBltV1w1eQkgls7o=; b=xabq5oxg+hchK0juSVQ5RtnHrj eHs9mbmiU5kP4lmdgIm7k5St3vFVWemv3dHd1BYSR8WI7qM+h3F+xsJyXKOH9VGQWiRHfthYJsR3R ORVvGjdsNkJe+Dupk/MGxoYFfXqQkXEJOOVH16/R5dKjE8MrVkPwv4bJZ5Unh5Qh5XrHqMM1Srhki hIMrZ85WuDNoXa9j/dgYqKqbMEfi/aC0BnC0mY4pZXeEgZaFEr3AbgSkMrfMz/dkSQnfD+fjHdzNb yOE9VsjTnT296vuefjLSbQ8shGlg9CZBfxPNqDqdRarhNKLhcJkS0YOIe/XjJ97KnmSkCwb5PJhz5 GMVYjJdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8VAE-00000001M6R-0jbU; Wed, 06 Nov 2024 01:48:54 +0000 Received: from cmccmta6.chinamobile.com ([111.22.67.139] helo=cmccmta2.chinamobile.com) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8V8U-00000001Lz4-2qEx for linux-arm-kernel@lists.infradead.org; Wed, 06 Nov 2024 01:47:09 +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-app05-12005 (RichMail) with SMTP id 2ee5672aca91e7e-d8e90; Wed, 06 Nov 2024 09:46:58 +0800 (CST) X-RM-TRANSID: 2ee5672aca91e7e-d8e90 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain (unknown[223.108.79.103]) by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee1672aca907d5-09b81; Wed, 06 Nov 2024 09:46:58 +0800 (CST) X-RM-TRANSID: 2ee1672aca907d5-09b81 From: Luo Yifan To: olivier.moysan@foss.st.com, arnaud.pouliquen@foss.st.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Cc: linux-sound@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Luo Yifan Subject: [PATCH] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() Date: Wed, 6 Nov 2024 09:46:54 +0800 Message-Id: <20241106014654.206860-1-luoyifan@cmss.chinamobile.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_174707_270513_9C28A969 X-CRM114-Status: GOOD ( 10.38 ) 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 (*prate / div) is safe to perform. Signed-off-by: Luo Yifan --- 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;