* [PATCH v2] staging: greybus: audio: fix uninitialized value issue
@ 2020-08-14 7:37 Vaibhav Agarwal
2020-08-14 10:56 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Vaibhav Agarwal @ 2020-08-14 7:37 UTC (permalink / raw)
To: Greg Kroah-Hartman, Alex Elder, Johan Hovold, Mark Greer
Cc: greybus-dev, devel, linux-kernel, Vaibhav Agarwal, Colin Ian King
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: 6339d2322c47 ("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>
---
Changelog:
v2: Fix the missing check for return value after get_control.
---
drivers/staging/greybus/audio_topology.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 2f9fdbdcd547..9f98691b2f5f 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -456,6 +456,18 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
val = ucontrol->value.integer.value[0] & mask;
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) {
+ dev_err_ratelimited(codec_dev, "%d:Error in %s for %s\n", ret,
+ __func__, kcontrol->id.name);
+ return ret;
+ }
+
/* update ucontrol */
if (gbvalue.value.integer_value[0] != val) {
for (wi = 0; wi < wlist->num_widgets; wi++) {
@@ -466,16 +478,10 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
gbvalue.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,
data->ctl_id,
GB_AUDIO_INVALID_INDEX, &gbvalue);
- gb_pm_runtime_put_autosuspend(bundle);
-
if (ret) {
dev_err_ratelimited(codec_dev,
"%d:Error in %s for %s\n", ret,
@@ -483,6 +489,7 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
return ret;
}
}
+ gb_pm_runtime_put_autosuspend(bundle);
return 0;
}
base-commit: fc80c51fd4b23ec007e88d4c688f2cac1b8648e7
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] staging: greybus: audio: fix uninitialized value issue
2020-08-14 7:37 [PATCH v2] staging: greybus: audio: fix uninitialized value issue Vaibhav Agarwal
@ 2020-08-14 10:56 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2020-08-14 10:56 UTC (permalink / raw)
To: Vaibhav Agarwal
Cc: Greg Kroah-Hartman, Alex Elder, Johan Hovold, Mark Greer, devel,
greybus-dev, Colin Ian King, linux-kernel
On Fri, Aug 14, 2020 at 01:07:20PM +0530, Vaibhav Agarwal wrote:
> 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: 6339d2322c47 ("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>
> ---
> Changelog:
> v2: Fix the missing check for return value after get_control.
> ---
> drivers/staging/greybus/audio_topology.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
> index 2f9fdbdcd547..9f98691b2f5f 100644
> --- a/drivers/staging/greybus/audio_topology.c
> +++ b/drivers/staging/greybus/audio_topology.c
> @@ -456,6 +456,18 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
> val = ucontrol->value.integer.value[0] & mask;
> 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) {
> + dev_err_ratelimited(codec_dev, "%d:Error in %s for %s\n", ret,
> + __func__, kcontrol->id.name);
gb_pm_runtime_put_autosuspend(bundle) on this error path?
> + return ret;
> + }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-14 10:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-14 7:37 [PATCH v2] staging: greybus: audio: fix uninitialized value issue Vaibhav Agarwal
2020-08-14 10:56 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).