[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250603214813.197346-1-harshit.m.mogalapalli@oracle.com>
Date: Tue, 3 Jun 2025 14:48:13 -0700
From: Harshit Mogalapalli <harshit.m.mogalapalli@...cle.com>
To: David Rhodes <david.rhodes@...rus.com>,
Richard Fitzgerald <rf@...nsource.cirrus.com>,
Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
Stuart Henderson <stuarth@...nsource.cirrus.com>,
Piotr Stankiewicz <piotrs@...nsource.cirrus.com>,
Qi Zhou <qi.zhou@...rus.com>, linux-sound@...r.kernel.org,
patches@...nsource.cirrus.com, linux-kernel@...r.kernel.org
Cc: dan.carpenter@...aro.org, kernel-janitors@...r.kernel.org,
error27@...il.com, harshit.m.mogalapalli@...cle.com
Subject: [PATCH] ASoC: cs48l32: Fix a signedness bug in cs48l32_hw_params()
There is a type promotion that can happen when freq(u32) variable is
comapared with sclk_target(integer), when sclk_target is a negative
value it promotes to a large postive integer which might not be a
problem in this particular case as the condition evaluates to false
when that happens, but bail out early when sclk_target has negative
error codes.
cs48l32_sclk_rates[i].freq >= sclk_target
Fix this by adding a negative error check when
snd_soc_tdm_params_to_bclk() fails
Fixes: e2bcbf99d045 ("ASoC: cs48l32: Add driver for Cirrus Logic CS48L32 audio DSP")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@...cle.com>
---
This is found using static analysis with Smatch, only compile tested.
---
sound/soc/codecs/cs48l32.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sound/soc/codecs/cs48l32.c b/sound/soc/codecs/cs48l32.c
index 90a795230d27..9bdd48aab42a 100644
--- a/sound/soc/codecs/cs48l32.c
+++ b/sound/soc/codecs/cs48l32.c
@@ -2162,6 +2162,10 @@ static int cs48l32_hw_params(struct snd_pcm_substream *substream,
n_slots_multiple = 1;
sclk_target = snd_soc_tdm_params_to_bclk(params, slotw, n_slots, n_slots_multiple);
+ if (sclk_target < 0) {
+ cs48l32_asp_err(dai, "Invalid parameters\n");
+ return sclk_target;
+ }
for (i = 0; i < ARRAY_SIZE(cs48l32_sclk_rates); i++) {
if ((cs48l32_sclk_rates[i].freq >= sclk_target) &&
--
2.39.3
Powered by blists - more mailing lists