* [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double()
@ 2014-08-08 15:29 Geert Uytterhoeven
2014-08-11 11:09 ` Lars-Peter Clausen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2014-08-08 15:29 UTC (permalink / raw)
To: Lars-Peter Clausen, Liam Girdwood, Mark Brown
Cc: alsa-devel, linux-kernel, Geert Uytterhoeven
If soc_dapm_read() fails, reg_val will be uninitialized, and bogus
values will be written later:
sound/soc/soc-dapm.c: In function 'snd_soc_dapm_get_enum_double':
sound/soc/soc-dapm.c:2862:15: warning: 'reg_val' may be used uninitialized in this function [-Wmaybe-uninitialized]
unsigned int reg_val, val;
^
Return early on error to fix this.
Introduced by commit ce0fc93ae56e2ba50ff8c220d69e4e860e889320 ("ASoC:
Add DAPM support at the component level").
---
Is this correct? Please review.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
sound/soc/soc-dapm.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 8348352dc2c6..177bd8639ef9 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2860,12 +2860,14 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
unsigned int reg_val, val;
- int ret = 0;
- if (e->reg != SND_SOC_NOPM)
- ret = soc_dapm_read(dapm, e->reg, ®_val);
- else
+ if (e->reg != SND_SOC_NOPM) {
+ int ret = soc_dapm_read(dapm, e->reg, ®_val);
+ if (ret)
+ return ret;
+ } else {
reg_val = dapm_kcontrol_get_value(kcontrol);
+ }
val = (reg_val >> e->shift_l) & e->mask;
ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val);
@@ -2875,7 +2877,7 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
ucontrol->value.enumerated.item[1] = val;
}
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double()
2014-08-08 15:29 [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double() Geert Uytterhoeven
@ 2014-08-11 11:09 ` Lars-Peter Clausen
2014-08-11 18:59 ` Mark Brown
2014-08-11 19:00 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Lars-Peter Clausen @ 2014-08-11 11:09 UTC (permalink / raw)
To: Geert Uytterhoeven, Liam Girdwood, Mark Brown; +Cc: alsa-devel, linux-kernel
On 08/08/2014 05:29 PM, Geert Uytterhoeven wrote:
> If soc_dapm_read() fails, reg_val will be uninitialized, and bogus
> values will be written later:
>
> sound/soc/soc-dapm.c: In function 'snd_soc_dapm_get_enum_double':
> sound/soc/soc-dapm.c:2862:15: warning: 'reg_val' may be used uninitialized in this function [-Wmaybe-uninitialized]
> unsigned int reg_val, val;
> ^
>
> Return early on error to fix this.
>
> Introduced by commit ce0fc93ae56e2ba50ff8c220d69e4e860e889320 ("ASoC:
> Add DAPM support at the component level").
> ---
> Is this correct? Please review.
Yes, thanks.
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double()
2014-08-08 15:29 [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double() Geert Uytterhoeven
2014-08-11 11:09 ` Lars-Peter Clausen
@ 2014-08-11 18:59 ` Mark Brown
2014-08-11 19:00 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-08-11 18:59 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Lars-Peter Clausen, Liam Girdwood, alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 187 bytes --]
On Fri, Aug 08, 2014 at 05:29:35PM +0200, Geert Uytterhoeven wrote:
> If soc_dapm_read() fails, reg_val will be uninitialized, and bogus
> values will be written later:
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double()
2014-08-08 15:29 [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double() Geert Uytterhoeven
2014-08-11 11:09 ` Lars-Peter Clausen
2014-08-11 18:59 ` Mark Brown
@ 2014-08-11 19:00 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-08-11 19:00 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Lars-Peter Clausen, Liam Girdwood, alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 269 bytes --]
On Fri, Aug 08, 2014 at 05:29:35PM +0200, Geert Uytterhoeven wrote:
> ---
> Is this correct? Please review.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
BTW please remember to put the signoff *before* the --- otherwise it
gets discarded.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-11 19:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-08 15:29 [PATCH] ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double() Geert Uytterhoeven
2014-08-11 11:09 ` Lars-Peter Clausen
2014-08-11 18:59 ` Mark Brown
2014-08-11 19:00 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox