mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] greybus: audio: fix uninitialized variable errors found by cppcheck
@ 2016-09-24 17:36 Vaibhav Agarwal
  2016-09-27  9:32 ` Viresh Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Vaibhav Agarwal @ 2016-09-24 17:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Alex Elder, Johan Hovold, linux-kernel, Colin King, devel,
	Vaibhav Agarwal

Currently, if info is null, the dev_err message is dereferencing an
uninitialized module pointer.  Instead, it should use codec->dev pointer
in dev_err call and better align with other err msg in this function.

Also, ret variable might be used uninitialized in a specific case.
Avoid using it this way.

Found using static analysis with cppcheck:
Checking drivers/staging/greybus/audio_topology.c...
[drivers/staging/greybus/audio_topology.c:175]: (error) Uninitialized
variable: module
[drivers/staging/greybus/audio_topology.c:495]: (error) Uninitialized
variable: ret

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
---
 drivers/staging/greybus/audio_topology.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index f9f33817a092..b6251691a33d 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -172,7 +172,7 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
 	info = (struct gb_audio_ctl_elem_info *)data->info;
 
 	if (!info) {
-		dev_err(module->dev, "NULL info for %s\n", uinfo->id.name);
+		dev_err(codec->dev, "NULL info for %s\n", uinfo->id.name);
 		return -EINVAL;
 	}
 
@@ -489,10 +489,11 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
 			dev_err_ratelimited(codec->dev,
 					    "%d:Error in %s for %s\n", ret,
 					    __func__, kcontrol->id.name);
+			return ret;
 		}
 	}
 
-	return ret;
+	return 0;
 }
 
 #define SOC_DAPM_MIXER_GB(xname, kcount, data) \
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] greybus: audio: fix uninitialized variable errors found by cppcheck
  2016-09-24 17:36 [PATCH] greybus: audio: fix uninitialized variable errors found by cppcheck Vaibhav Agarwal
@ 2016-09-27  9:32 ` Viresh Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2016-09-27  9:32 UTC (permalink / raw)
  To: Vaibhav Agarwal
  Cc: Greg Kroah-Hartman, Alex Elder, Johan Hovold, linux-kernel,
	Colin King, devel

On Sat, Sep 24, 2016 at 11:06 PM, Vaibhav Agarwal <vaibhav.sr@gmail.com> wrote:
> Currently, if info is null, the dev_err message is dereferencing an
> uninitialized module pointer.  Instead, it should use codec->dev pointer
> in dev_err call and better align with other err msg in this function.
>
> Also, ret variable might be used uninitialized in a specific case.
> Avoid using it this way.
>
> Found using static analysis with cppcheck:
> Checking drivers/staging/greybus/audio_topology.c...
> [drivers/staging/greybus/audio_topology.c:175]: (error) Uninitialized
> variable: module
> [drivers/staging/greybus/audio_topology.c:495]: (error) Uninitialized
> variable: ret
>
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
> ---
>  drivers/staging/greybus/audio_topology.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
> index f9f33817a092..b6251691a33d 100644
> --- a/drivers/staging/greybus/audio_topology.c
> +++ b/drivers/staging/greybus/audio_topology.c
> @@ -172,7 +172,7 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
>         info = (struct gb_audio_ctl_elem_info *)data->info;
>
>         if (!info) {
> -               dev_err(module->dev, "NULL info for %s\n", uinfo->id.name);
> +               dev_err(codec->dev, "NULL info for %s\n", uinfo->id.name);
>                 return -EINVAL;
>         }
>
> @@ -489,10 +489,11 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
>                         dev_err_ratelimited(codec->dev,
>                                             "%d:Error in %s for %s\n", ret,
>                                             __func__, kcontrol->id.name);
> +                       return ret;
>                 }
>         }
>
> -       return ret;
> +       return 0;
>  }
>
>  #define SOC_DAPM_MIXER_GB(xname, kcount, data) \

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-27  9:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-24 17:36 [PATCH] greybus: audio: fix uninitialized variable errors found by cppcheck Vaibhav Agarwal
2016-09-27  9:32 ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®