ASoC: dapm: Fix possible uninitialized variable in snd_soc_dapm_get_volsw()
authorChen-Yu Tsai <wens@csie.org>
Sat, 27 Aug 2016 11:27:58 +0000 (19:27 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 1 Sep 2016 20:05:18 +0000 (21:05 +0100)
If soc_dapm_read() fails, val will be uninitialized, and bogus values
will be written later:

ret = soc_dapm_read(dapm, reg, &val);
val = (val >> shift) & mask;

However, the compiler does not give a warning. Return on error before
val is really used to avoid this.

This is similar to the commit 6912831623c5 ("ASoC: dapm: Fix
uninitialized variable in snd_soc_dapm_get_enum_double()")

Fixes: ce0fc93ae56e (ASoC: Add DAPM support at the component level)
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-dapm.c

index d908ff8..edff395 100644 (file)
@@ -3049,6 +3049,9 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
        }
        mutex_unlock(&card->dapm_mutex);
 
+       if (ret)
+               return ret;
+
        if (invert)
                ucontrol->value.integer.value[0] = max - val;
        else