Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: HariKrishna Sagala <hariconscious@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	perex@perex.cz, tiwai@suse.com, cristian.ciocaltea@collabora.com,
	cryolitia@uniontech.com, franta-linux@frantovo.cz,
	khalid@kernel.org, shuah@kernel.org,
	david.hunter.linux@gmail.com, linux-sound@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: usb-audio: Initialize status1 to fix uninitialized symbol errors
Date: Wed, 03 Dec 2025 12:50:16 +0100	[thread overview]
Message-ID: <87v7inss1z.wl-tiwai@suse.de> (raw)
In-Reply-To: <54d0ac3b-6a10-7319-338c-80f52e62af58@gmail.com>

On Wed, 03 Dec 2025 12:22:27 +0100,
HariKrishna Sagala wrote:
> 
> On Wed, 3 Dec 2025, Takashi Iwai wrote:
> 
> > On Wed, 03 Dec 2025 12:01:35 +0100,
> > HariKrishna Sagala wrote:
> > >
> > > On Wed, 3 Dec 2025, Takashi Iwai wrote:
> > >
> > > > On Wed, 03 Dec 2025 09:33:20 +0100,
> > > > hariconscious@gmail.com wrote:
> > > > >
> > > > > From: HariKrishna Sagala <hariconscious@gmail.com>
> > > > >
> > > > > Initialize 'status1' with a default value to resolve the static analysis
> > > > > smatch reported error "uninitialized symbol 'status1'".
> > > > > The 'status1' variable is used to create a buff using "kmemdup".
> > > > > So, ensure to initialize the value before it is read.
> > > > >
> > > > > Signed-off-by: HariKrishna Sagala <hariconscious@gmail.com>
> > > > > ---
> > > > > This patch fixes the below smatch reported errors.
> > > > > sound/usb/mixer_quirks.c:2462 snd_rme_rate_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2467 snd_rme_rate_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2472 snd_rme_rate_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2495 snd_rme_sync_state_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2501 snd_rme_sync_state_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2522 snd_rme_spdif_if_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2535 snd_rme_spdif_format_get() error: uninitialized symbol 'status1'.
> > > > > sound/usb/mixer_quirks.c:2548 snd_rme_sync_source_get() error: uninitialized symbol 'status1'.
> > > > >
> > > > > The below is the flow of 'status1' it is used before initialization.
> > > > >
> > > > > snd_rme_rate_get -> status1 is uninitialized and passed
> > > > > 	snd_rme_get_status1 -> passed as is
> > > > > 		snd_rme_read_value -> passed as is
> > > > > 			snd_usb_ctl_msg -> created buf from status1 using kmemdup
> > > > > 				usb_control_msg -> sent buf for reading/writing
> > > > >
> > > > > Description of "usb_control_msg", states as
> > > > > " * @data: pointer to the data to send"
> > > > >
> > > > > Later from Usb control request, dst buf is copied to src buf but usb
> > > > > control msg request is made before initialization.
> > > > >
> > > > > Thank you.
> > > > >
> > > > >  sound/usb/mixer_quirks.c | 10 +++++-----
> > > > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > > > >
> > > > > diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
> > > > > index 828af3095b86..06903c5de087 100644
> > > > > --- a/sound/usb/mixer_quirks.c
> > > > > +++ b/sound/usb/mixer_quirks.c
> > > > > @@ -2449,7 +2449,7 @@ static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
> > > > >  static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
> > > > >  			    struct snd_ctl_elem_value *ucontrol)
> > > > >  {
> > > > > -	u32 status1;
> > > > > +	u32 status1 = 0;
> > > > >  	u32 rate = 0;
> > > > >  	int idx;
> > > > >  	int err;
> > > > > @@ -2483,7 +2483,7 @@ static int snd_rme_rate_get(struct snd_kcontrol *kcontrol,
> > > > >  static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
> > > > >  				  struct snd_ctl_elem_value *ucontrol)
> > > > >  {
> > > > > -	u32 status1;
> > > > > +	u32 status1 = 0;
> > > > >  	int idx = SND_RME_CLOCK_NOLOCK;
> > > > >  	int err;
> > > > >
> > > > > @@ -2513,7 +2513,7 @@ static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol,
> > > > >  static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
> > > > >  				struct snd_ctl_elem_value *ucontrol)
> > > > >  {
> > > > > -	u32 status1;
> > > > > +	u32 status1 = 0;
> > > > >  	int err;
> > > > >
> > > > >  	err = snd_rme_get_status1(kcontrol, &status1);
> > > > > @@ -2526,7 +2526,7 @@ static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol,
> > > > >  static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
> > > > >  				    struct snd_ctl_elem_value *ucontrol)
> > > > >  {
> > > > > -	u32 status1;
> > > > > +	u32 status1 = 0;
> > > > >  	int err;
> > > > >
> > > > >  	err = snd_rme_get_status1(kcontrol, &status1);
> > > > > @@ -2539,7 +2539,7 @@ static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol,
> > > > >  static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol,
> > > > >  				   struct snd_ctl_elem_value *ucontrol)
> > > > >  {
> > > > > -	u32 status1;
> > > > > +	u32 status1 = 0;
> > > > >  	int err;
> > > > >
> > > > >  	err = snd_rme_get_status1(kcontrol, &status1);
> > > > >
> > > >
> > > > The warning itself is rather dubious.  But it'd certainly give a safer
> > > > feeling to cover the uninitialized variables, so it would still make
> > > > some sense.
> > > >
> > > > But, the code change can be improved.  e.g. initialize the value in
> > > > the callee side, instead of callers; then it'll reduce all changes to
> > > > a one-liner.
> > > >
> > > > At the next time, please look at the patterns you changed more closely
> > > > and think again whether it's the best change or not before submission.
> > > > On the second look, often you see things from a different perspective
> > > > :)
> > > >
> > > >
> > > > thanks,
> > > >
> > > > Takashi
> > > >
> > >
> > > Hi Takashi,
> > >
> > > Thank you for the feedback and complement.
> > > Yes, will check the pattern and avoid this going forward.
> > > As all the functions call "snd_rme_get_status1",
> > > initialized here but smatch didn't silence them.
> > >
> > > I prefer initializing a variable in caller side as it owns
> > > and aware of initialized value sent.
> > >
> > > Sorry, if I had misunderstood your suggestion.
> >
> > Well, you seem driven too much by smatch.  Just look at your patch
> > again.
> >
> > You're repeating the same initializations and passing to the same
> > function.  And those are the only callers of snd_rme_get_status1().
> > So, instead of initializing in the caller side, initialize the value
> > in snd_rme_get_status1().  Then the whole your changes will be
> > oneliner like below.
> >
> >
> > Takashi
> >
> > --- a/sound/usb/mixer_quirks.c
> > +++ b/sound/usb/mixer_quirks.c
> > @@ -2548,6 +2548,7 @@ static int snd_rme_get_status1(struct snd_kcontrol *kcontrol,
> >  	CLASS(snd_usb_lock, pm)(chip);
> >  	if (pm.err < 0)
> >  		return pm.err;
> > +	*status1 = 0;
> >  	return snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1);
> >  }
> >
> >
> 
> Hi Takashi,
> 
> Yes, tried that before, smatch didn't silence them.

Then it's an obvious failure of smatch.

Or you might set *status1 = 0 at the beginning of
snd_rme_get_status1() although it makes little sense.

> If it is worth having this change though they are not silenced,
> will raise v2 otherwise will drop this patch.

If the smatch still complains, it's not worth.


Takashi

  reply	other threads:[~2025-12-03 11:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-03  8:33 [PATCH] ALSA: usb-audio: Initialize status1 to fix uninitialized symbol errors hariconscious
2025-12-03  8:56 ` Takashi Iwai
2025-12-03 11:01   ` HariKrishna Sagala
2025-12-03 11:09     ` Takashi Iwai
2025-12-03 11:22       ` HariKrishna Sagala
2025-12-03 11:50         ` Takashi Iwai [this message]
2025-12-03 12:01           ` HariKrishna Sagala
2025-12-03 12:54             ` Takashi Iwai
2025-12-03 13:34               ` HariKrishna Sagala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v7inss1z.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=cristian.ciocaltea@collabora.com \
    --cc=cryolitia@uniontech.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=franta-linux@frantovo.cz \
    --cc=hariconscious@gmail.com \
    --cc=khalid@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=shuah@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox