From: Suraj Sonawane <surajsonawane0215@gmail.com>
To: surajsonawane0215@gmail.com
Cc: broonie@kernel.org, lgirdwood@gmail.com,
linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org,
perex@perex.cz, tiwai@suse.com
Subject: [PATCH v2] sound: fix uninit-value in i2s_dma_isr
Date: Sat, 2 Nov 2024 18:06:30 +0530 [thread overview]
Message-ID: <20241102123630.25446-1-surajsonawane0215@gmail.com> (raw)
In-Reply-To: <20241030170829.36161-1-surajsonawane0215@gmail.com>
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264 i2s_dma_isr()
error: uninitialized symbol 'val_1'.
sound/soc/bcm/bcm63xx-pcm-whistler.c:264 i2s_dma_isr()
error: uninitialized symbol 'val_2'.
These errors were triggered because the variables 'val_1' and 'val_2'
could remain uninitialized if 'offlevel' is zero, meaning the loop
that assigns values to them does not execute. In this case,
'dma_addr_next' would use uninitialized data, potentially leading
to undefined behavior.
To resolve this, a conditional update for 'dma_addr_next' is added,
ensuring it is assigned only when 'val_1' and 'val_2' are read.
A new boolean variable 'val_read' flags when the values have been
retrieved, setting 'dma_addr_next' only if valid data is available.
This solution prevents the use of uninitialized data, maintaining
defined behavior for 'dma_addr_next' in all cases, and aligns with
expected usage of I2S RX descriptor data.
Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
---
V1: Initialize 'val_1' and 'val_2' to 0.
V2: Add conditional update for 'dma_addr_next' based on read status to
skip the update when values haven’t been read.
sound/soc/bcm/bcm63xx-pcm-whistler.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/soc/bcm/bcm63xx-pcm-whistler.c b/sound/soc/bcm/bcm63xx-pcm-whistler.c
index 018f2372e..e3a4fcc63 100644
--- a/sound/soc/bcm/bcm63xx-pcm-whistler.c
+++ b/sound/soc/bcm/bcm63xx-pcm-whistler.c
@@ -256,12 +256,16 @@ static irqreturn_t i2s_dma_isr(int irq, void *bcm_i2s_priv)
offlevel = (int_status & I2S_RX_DESC_OFF_LEVEL_MASK) >>
I2S_RX_DESC_OFF_LEVEL_SHIFT;
+ bool val_read = false;
while (offlevel) {
regmap_read(regmap_i2s, I2S_RX_DESC_OFF_ADDR, &val_1);
regmap_read(regmap_i2s, I2S_RX_DESC_OFF_LEN, &val_2);
+ val_read = true;
offlevel--;
}
- prtd->dma_addr_next = val_1 + val_2;
+ if (val_read)
+ prtd->dma_addr_next = val_1 + val_2;
+
ifflevel = (int_status & I2S_RX_DESC_IFF_LEVEL_MASK) >>
I2S_RX_DESC_IFF_LEVEL_SHIFT;
--
2.34.1
next prev parent reply other threads:[~2024-11-02 12:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-30 17:08 [PATCH] sound: fix uninit-value in i2s_dma_isr Suraj Sonawane
2024-10-30 17:14 ` Mark Brown
2024-10-31 6:47 ` Suraj Sonawane
2024-10-31 16:17 ` Mark Brown
2024-11-01 9:02 ` Suraj Sonawane
2024-11-01 13:15 ` Mark Brown
2024-11-02 12:40 ` Suraj Sonawane
2024-11-02 12:36 ` Suraj Sonawane [this message]
2024-11-04 12:41 ` [PATCH v2] " Mark Brown
2024-11-05 11:03 ` Suraj Sonawane
2024-11-05 16:38 ` Mark Brown
2024-11-06 8:24 ` Suraj Sonawane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241102123630.25446-1-surajsonawane0215@gmail.com \
--to=surajsonawane0215@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox