Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: bcm63xx-pcm-whistler: fix uninit-value in i2s_dma_isr

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>

authored by

Suraj Sonawane and committed by
Mark Brown
28f7aa0c 11577333

+5 -1
+5 -1
sound/soc/bcm/bcm63xx-pcm-whistler.c
··· 256 256 257 257 offlevel = (int_status & I2S_RX_DESC_OFF_LEVEL_MASK) >> 258 258 I2S_RX_DESC_OFF_LEVEL_SHIFT; 259 + bool val_read = false; 259 260 while (offlevel) { 260 261 regmap_read(regmap_i2s, I2S_RX_DESC_OFF_ADDR, &val_1); 261 262 regmap_read(regmap_i2s, I2S_RX_DESC_OFF_LEN, &val_2); 263 + val_read = true; 262 264 offlevel--; 263 265 } 264 - prtd->dma_addr_next = val_1 + val_2; 266 + if (val_read) 267 + prtd->dma_addr_next = val_1 + val_2; 268 + 265 269 ifflevel = (int_status & I2S_RX_DESC_IFF_LEVEL_MASK) >> 266 270 I2S_RX_DESC_IFF_LEVEL_SHIFT; 267 271