sound: fix uninit-value in i2s_dma_isr
PATCH 1/1 sound: 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 occurred because the variables 'val_1' and 'val_2' are declared but may not be assigned a value before they are used. Specifically, if the loop that assigns values to 'val_1' and 'val_2' does not execute (for example, when 'offlevel' is zero), these variables remain uninitialized, leading to potential undefined behavior.
To resolve this issue, initialize 'val_1' and 'val_2' to 0 at the point of declaration. This ensures that 'val_1' and 'val_2' have defined values before they are used in subsequent calculations, preventing any warnings or undefined behavior in cases where the loop does not run.
--- sound/soc/bcm/bcm63xx-pcm-whistler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/bcm/bcm63xx-pcm-whistler.c +1 -1
@@ -232,7 +232,7 @@ static int bcm63xx_pcm_close(struct snd_soc_component *component,static irqreturn_t i2s_dma_isr (int irq,void *bcm_i2s_priv) { -unsigned int availdepth, ifflevel, offlevel, int_status, val_1, val_2; +unsigned int availdepth, ifflevel, offlevel, int_status, val_1 =0 , val_2 =0 ;struct bcm63xx_runtime_data *prtd;struct snd_pcm_substream *substream;struct snd_pcm_runtime *runtime;
Signature · 1 line
2.34.1
Mark Brown
maintainerQuoted 14 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_1'.sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_2'.These errors occurred because the variables '
val_1' and 'val_2' are declared but may not be assigned a value before they are used. Specifically, if the loop that assigns values to 'val_1' and 'val_2' does not execute (for example, when 'offlevel' is zero), these variables remain uninitialized, leading to potential undefined behavior.
Quoted 5 lines
To resolve this issue, initialize '
val_1' and 'val_2' to 0 at the point of declaration. This ensures that 'val_1' and 'val_2' have defined values before they are used in subsequent calculations, preventing any warnings or undefined behavior in cases where the loop does not run.
This will shut the warning up, but why are these values valid? Are we handling the cases where the loops do not execute properly?
Quoted 15 lines · Mark Brown
Quoted 14 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_1'.sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_2'.These errors occurred because the variables '
val_1' and 'val_2' are declared but may not be assigned a value before they are used. Specifically, if the loop that assigns values to 'val_1' and 'val_2' does not execute (for example, when 'offlevel' is zero), these variables remain uninitialized, leading to potential undefined behavior.
Quoted 8 lines
Quoted 5 lines
To resolve this issue, initialize '
val_1' and 'val_2' to 0 at the point of declaration. This ensures that 'val_1' and 'val_2' have defined values before they are used in subsequent calculations, preventing any warnings or undefined behavior in cases where the loop does not run.This will shut the warning up, but why are these values valid? Are we handling the cases where the loops do not execute properly?
Thank you for the feedback and your time.
The uninitialized warning for val_1 and val_2 arises because, in some cases, the offlevel value is zero, and as a result, the loop does not execute, leaving these variables potentially undefined. The subsequent code calculates prtd->dma_addr_next using val_1 + val_2, so it's necessary to have val_1 and val_2 initialized to a known value, even when the loop does not run.
Initializing them to zero ensures prtd->dma_addr_next has a defined value without triggering undefined behavior. However, if a zero initialization could cause unintended behavior in dma_addr_next, I could alternatively handle this case by setting dma_addr_next conditionally when offlevel is non-zero.
Let me know if there’s a preferred approach, or if you'd suggest a different initial value for these variables based on the expected use.
Mark Brown
maintainerQuoted 14 lines · Suraj Sonawane
Quoted 2 lines · Mark Brown
This will shut the warning up, but why are these values valid? Are we handling the cases where the loops do not execute properly?
Thank you for the feedback and your time.
The uninitialized warning for
val_1andval_2arises because, in some cases, the offlevel value is zero, and as a result, the loop does not execute, leaving these variables potentially undefined. The subsequent code calculatesprtd->dma_addr_nextusingval_1+val_2, so it's necessary to haveval_1andval_2initialized to a known value, even when the loop does not run.
Quoted 5 lines
Initializing them to zero ensures
prtd->dma_addr_nexthas a defined value without triggering undefined behavior. However, if a zero initialization could cause unintended behavior indma_addr_next, I could alternatively handle this case by settingdma_addr_nextconditionally when offlevel is non-zero.
This is describing again what the patch does, which basically just boils down to shutting up the warning.
Quoted 2 lines
Let me know if there’s a preferred approach, or if you'd suggest a different initial value for these variables based on the expected use.
We need to understand what the change is doing - what do the values mean, is the real issue that we're missing some error handling for the case that lets us fall through without initialisation?
Quoted 24 lines · Mark Brown
Quoted 14 lines · Suraj Sonawane
Quoted 2 lines · Mark Brown
This will shut the warning up, but why are these values valid? Are we handling the cases where the loops do not execute properly?
Thank you for the feedback and your time.
The uninitialized warning for
val_1andval_2arises because, in some cases, the offlevel value is zero, and as a result, the loop does not execute, leaving these variables potentially undefined. The subsequent code calculatesprtd->dma_addr_nextusingval_1+val_2, so it's necessary to haveval_1andval_2initialized to a known value, even when the loop does not run.Quoted 5 lines
Initializing them to zero ensures
prtd->dma_addr_nexthas a defined value without triggering undefined behavior. However, if a zero initialization could cause unintended behavior indma_addr_next, I could alternatively handle this case by settingdma_addr_nextconditionally when offlevel is non-zero.This is describing again what the patch does, which basically just boils down to shutting up the warning.
Quoted 6 lines
Quoted 2 lines
Let me know if there’s a preferred approach, or if you'd suggest a different initial value for these variables based on the expected use.
We need to understand what the change is doing - what do the values mean, is the real issue that we're missing some error handling for the case that lets us fall through without initialisation?
Thank you for clarifying.
I reviewed the context around val_1 and val_2 in dma_addr_next. These values are expected to come from the registers when offlevel is non-zero, representing the next DMA address and length information. If offlevel is zero, it means there’s no offset data to process, and dma_addr_next might not need updating in that case.
A more precise solution would be to conditionally update prtd->dma_addr_next only when offlevel is non-zero, as this would reflect the intended logic without relying on an arbitrary initialization.
Would it be better to revise the patch to conditionally update prtd->dma_addr_next only when offlevel is non-zero?
Let me know if this approach aligns better with the expected behavior.
Thank you again for your time.
Thanks,
Suraj
Mark Brown
maintainerQuoted 6 lines · Suraj Sonawane
I reviewed the context around
val_1andval_2indma_addr_next. These values are expected to come from the registers when offlevel is non-zero, representing the next DMA address and length information. If offlevel is zero, it means there’s no offset data to process, anddma_addr_nextmight not need updating in that case.
Quoted 8 lines
A more precise solution would be to conditionally update
prtd->dma_addr_nextonly when offlevel is non-zero, as this would reflect the intended logic without relying on an arbitrary initialization.Would it be better to revise the patch to conditionally update
prtd->dma_addr_nextonly when offlevel is non-zero?Let me know if this approach aligns better with the expected behavior.
That seems like a reasonable approach, just skip the update when we didn't read the values.
Quoted 12 lines · Mark Brown
Quoted 9 lines · Suraj Sonawane
I reviewed the context around
val_1andval_2indma_addr_next. These values are expected to come from the registers when offlevel is non-zero, representing the next DMA address and length information. If offlevel is zero, it means there’s no offset data to process, anddma_addr_nextmight not need updating in that case.A more precise solution would be to conditionally update
prtd->dma_addr_nextonly when offlevel is non-zero, as this would reflect the intended logic without relying on an arbitrary initialization.
Quoted 7 lines
Quoted 4 lines
Would it be better to revise the patch to conditionally update
prtd->dma_addr_nextonly when offlevel is non-zero?Let me know if this approach aligns better with the expected behavior.
That seems like a reasonable approach, just skip the update when we didn't read the values.
Thanks for the feedback.
I've updated the patch based on your suggestion to conditionally update prtd->dma_addr_next only when offlevel is non-zero, effectively skipping the update if values were not read. This approach aligns with the expected logic, as it ensures dma_addr_next is only updated when valid data is available, preventing any unintended updates.
I’ve just sent the revised patch. Please let me know if any additional adjustments are needed.
Best regards,
Suraj Sonawane
PATCH v2 1/1 sound: fix uninit-value in i2s_dma_isr
In reply to Suraj SonawaneFix 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.
---
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(-)
sound/soc/bcm/bcm63xx-pcm-whistler.c +5 -1
@@ -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 ;
Signature · 1 line
2.34.1
Mark Brown
maintainerQuoted 6 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_1'.sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_2'.
Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.
Please don't send new patches in reply to old patches or serieses, this makes it harder for both people and tools to understand what is going on - it can bury things in mailboxes and make it difficult to keep track of what current patches are, both for the new patches and the old ones.
Quoted 14 lines · Mark Brown
Quoted 6 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_1'.sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_2'.Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.
Quoted 4 lines
Please don't send new patches in reply to old patches or serieses, this makes it harder for both people and tools to understand what is going on - it can bury things in mailboxes and make it difficult to keep track of what current patches are, both for the new patches and the old ones.
Thank you for the guidance. I understand the importance of following the existing format for subject lines to maintain consistency within the subsystem. When I submitted the v2 patch earlier, I had been considering this, but I mistakenly thought that switching subject lines between v1 and v2 wasn’t necessary. Moving forward, I'll make sure my patches align with the the style for the subsystem and will submit them as new threads to avoid confusion.
Thank you again for your feedback.
Mark Brown
maintainerQuoted 8 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_1'.sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_2'.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] sound: fix uninit-value in i2s_dma_isr
commit: 28f7aa0c015036db260adbec37891984a31ed4c2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 32 lines · Mark Brown
Quoted 8 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_1'.sound/soc/bcm/bcm63xx-pcm-whistler.c:264i2s_dma_isr()
error: uninitialized symbol 'val_2'.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] sound: fix uninit-value in
i2s_dma_isrcommit: 28f7aa0c015036db260adbec37891984a31ed4c2All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Quoted 6 lines
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Thank you so much!
I appreciate the update.
I’ll monitor for any follow-up feedback.
Best regards,
Suraj Sonawane