staging: greybus: audio: fix uninitialized value issue

The current implementation for gbcodec_mixer_dapm_ctl_put() uses
uninitialized gbvalue for comparison with updated value. This was found
using static analysis with coverity.

Uninitialized scalar variable (UNINIT)
11. uninit_use: Using uninitialized value
gbvalue.value.integer_value[0].
460        if (gbvalue.value.integer_value[0] != val) {

This patch fixes the issue with fetching the gbvalue before using it for
    comparision.

Fixes: 6339d2322c ("greybus: audio: Add topology parser for GB codec")
Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/bc4f29eb502ccf93cd2ffd98db0e319fa7d0f247.1597408126.git.vaibhav.sr@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Vaibhav Agarwal 2020-08-14 18:03:15 +05:30 committed by Greg Kroah-Hartman
parent fea22e159d
commit 1dffeb8b8b
1 changed files with 15 additions and 14 deletions

View File

@ -456,6 +456,15 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
val = ucontrol->value.integer.value[0] & mask; val = ucontrol->value.integer.value[0] & mask;
connect = !!val; connect = !!val;
ret = gb_pm_runtime_get_sync(bundle);
if (ret)
return ret;
ret = gb_audio_gb_get_control(module->mgmt_connection, data->ctl_id,
GB_AUDIO_INVALID_INDEX, &gbvalue);
if (ret)
goto exit;
/* update ucontrol */ /* update ucontrol */
if (gbvalue.value.integer_value[0] != val) { if (gbvalue.value.integer_value[0] != val) {
for (wi = 0; wi < wlist->num_widgets; wi++) { for (wi = 0; wi < wlist->num_widgets; wi++) {
@ -466,26 +475,18 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
gbvalue.value.integer_value[0] = gbvalue.value.integer_value[0] =
cpu_to_le32(ucontrol->value.integer.value[0]); cpu_to_le32(ucontrol->value.integer.value[0]);
ret = gb_pm_runtime_get_sync(bundle);
if (ret)
return ret;
ret = gb_audio_gb_set_control(module->mgmt_connection, ret = gb_audio_gb_set_control(module->mgmt_connection,
data->ctl_id, data->ctl_id,
GB_AUDIO_INVALID_INDEX, &gbvalue); GB_AUDIO_INVALID_INDEX, &gbvalue);
}
exit:
gb_pm_runtime_put_autosuspend(bundle); gb_pm_runtime_put_autosuspend(bundle);
if (ret)
if (ret) { dev_err_ratelimited(codec_dev, "%d:Error in %s for %s\n", ret,
dev_err_ratelimited(codec_dev,
"%d:Error in %s for %s\n", ret,
__func__, kcontrol->id.name); __func__, kcontrol->id.name);
return ret; return ret;
} }
}
return 0;
}
#define SOC_DAPM_MIXER_GB(xname, kcount, data) \ #define SOC_DAPM_MIXER_GB(xname, kcount, data) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \