Skip to content

Commit

Permalink
ASoC: dapm: Fix uninitialized variable in snd_soc_dapm_get_enum_double()
Browse files Browse the repository at this point in the history
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 ce0fc93 ("ASoC:
Add DAPM support at the component level").

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@linaro.org>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
  • Loading branch information
Geert Uytterhoeven authored and Mark Brown committed Aug 11, 2014
1 parent ae34a78 commit 6912831
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions sound/soc/soc-dapm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &reg_val);
else
if (e->reg != SND_SOC_NOPM) {
int ret = soc_dapm_read(dapm, e->reg, &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);
Expand All @@ -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);

Expand Down

0 comments on commit 6912831

Please sign in to comment.