From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AFB521FD97; Tue, 12 Nov 2024 10:37:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731407830; cv=none; b=OLePTDqZJJYVd9v0MqFBhlwwzONtsRAkPMPQKPMnRps68rVmJ3/KpoQCUteYZpgjeoObV7eUwACwb7Iw/8at3ncf2yjyguYm66HsWTtfJ+vnE1aBDOLsY54C1H09VkY9I1nKgtP3U8n8TXUsbDGK4jvwBjewNvB1NUB9ebEcBOI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731407830; c=relaxed/simple; bh=lwcLfxHDCbI5v4tmwHL5qTHq967KNG5hV3UIWalHG6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U3P9UysGHlWb7aMo02+PD2TvqA/V2/1P6qy/s0fJzg/ikBE602Ait7w8JYENulllT5H1ksGSzpQa0lTtpkjx54UwGSGyXGSBa+Pz599XImFbGU57blrmLey+hXHnh0oJBFQ66WgPOfygI55X/iwYDVCte6+ke5XCGTAmF6+K9x0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fBpFlRIE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fBpFlRIE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F037C4CECD; Tue, 12 Nov 2024 10:37:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731407830; bh=lwcLfxHDCbI5v4tmwHL5qTHq967KNG5hV3UIWalHG6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fBpFlRIExIQodbOvLA+j0/tdyEKIabdaFcIAEQQ8/+cQ+uz9bZ+twW/h36HmJpdGp XjBd4epixj3ksvTAe6Y/TN31GkOp0jhPn+nZ5gHIYKcq21Mg8G14kLuYY/LytPets2 ihmzGMEbx5s7C+M0aQu2Xv/LhV8mx6GCoeCuNlOFWpP5ahntNElnTFzkg5KdEDZ3lf EYfcLsKMSkibxqkd2sT98Rnw6NgiKg6DIPqwQz5yAEQKBL5NdNWpI4IxSOsVhEMx/2 d3S6pdZie7kpKo9zfL2tz/WYQxffGmIGG6605GDCKAAAieyDoeGnmuiRfayYwC1NND T3JL9JwIwzrOQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luo Yifan , Olivier Moysan , Mark Brown , Sasha Levin , arnaud.pouliquen@foss.st.com, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 6.6 13/15] ASoC: stm: Prevent potential division by zero in stm32_sai_get_clk_div() Date: Tue, 12 Nov 2024 05:36:34 -0500 Message-ID: <20241112103643.1653381-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241112103643.1653381-1-sashal@kernel.org> References: <20241112103643.1653381-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.60 Content-Transfer-Encoding: 8bit From: Luo Yifan [ Upstream commit 23569c8b314925bdb70dd1a7b63cfe6100868315 ] 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 Link: https://patch.msgid.link/20241107015936.211902-1-luoyifan@cmss.chinamobile.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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 1b61110cb9174..dcbcd1a59a3aa 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; } -- 2.43.0