]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ASoC: bcm63xx-pcm-whistler: fix uninit-value in i2s_dma_isr
authorSuraj Sonawane <surajsonawane0215@gmail.com>
Sat, 2 Nov 2024 12:36:30 +0000 (18:06 +0530)
committerMark Brown <broonie@kernel.org>
Tue, 5 Nov 2024 12:53:28 +0000 (12:53 +0000)
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>
Link: https://patch.msgid.link/20241102123630.25446-1-surajsonawane0215@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/bcm/bcm63xx-pcm-whistler.c

index 018f2372e892c2d46081ccf6a8c16400504efca7..e3a4fcc63a56dcf3a98cbafadd6ba837378f0bf5 100644 (file)
@@ -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;