Skip to contentSkip to conversation

ALSA: mixart: don't print an unintialized variable on error

PATCH Applied Dan Carpenter 3 participants 4 messages Jul 13, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: mixart: don't print an unintialized variable on error

My static checker complains that "resp" could be unitialized on error when we print its value.

sound/pci/mixart/mixart_mixer.c +1 -1
index 58fd79eb..51e5349 100644
@@ -965,7 +965,7 @@ static int mixart_update_monitoring(struct snd_mixart* chip, int channel)
 	int err;
 	struct mixart_msg request;
 	struct mixart_set_out_audio_level audio_level;
-	u32 resp;
+	u32 resp = 0;
 
 	if(chip->pipe_out_ana.status = PIPE_UNDEFINED)
 		return -EINVAL; /* no pipe defined */
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines · Dan Carpenter

My static checker complains that "resp" could be unitialized on error when we print its value.

sound/pci/mixart/mixart_mixer.c +0 -0
index 58fd79eb..51e5349 100644

sound/pci/mixart/mixart_mixer.c static int mixart_update_monitoring(struct snd_mixart* chip, int channel) · line 971

Quoted 8 lines
sound/pci/mixart/mixart_mixer.c +1 -1
@@ -965,7 +965,7 @@ static int mixart_update_monitoring(struct snd_mixart* chip, int channel)
  	int err;
  	struct mixart_msg request;
  	struct mixart_set_out_audio_level audio_level;
-	u32 resp;
+	u32 resp = 0;
 
  	if(chip->pipe_out_ana.status == PIPE_UNDEFINED)
  		return -EINVAL; /* no pipe defined */

The 'resp' variable is firstly given to snd_mixart_send_msg().

static int mixart_update_monitoring(struct snd_mixart* chip,
int channel)

{
    ...
    err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp);
    if((err<0) || resp) {
        dev_dbg(chip->card->dev,
                "error MSG_CONNECTOR_SET_OUT_AUDIO_LEVEL card(%d) 
resp(%x)\n",
                chip->chip_idx, resp);
        return -EINVAL;
    }
    return 0;
}

When the function, snd_mixart_send_msg(), assigns nothing to the variable in error cases, dev_dbg() prints uninitialized value.

Regards

Takashi Sakamoto

#2 lore raw
Quoted 41 lines · Takashi Sakamoto

Hi,

Quoted 19 lines · Dan Carpenter

My static checker complains that "resp" could be unitialized on error when we print its value.

sound/pci/mixart/mixart_mixer.c +1 -1
index 58fd79eb..51e5349 100644
@@ -965,7 +965,7 @@ static int mixart_update_monitoring(struct
 snd_mixart* chip, int channel)
      int err;
      struct mixart_msg request;
      struct mixart_set_out_audio_level audio_level;
-    u32 resp;
+    u32 resp = 0;
 
      if(chip->pipe_out_ana.status == PIPE_UNDEFINED)
Quoted 1 line

return -EINVAL; /* no pipe defined */

The 'resp' variable is firstly given to snd_mixart_send_msg().

static int mixart_update_monitoring(struct snd_mixart* chip,
int channel)

{
    ...
    err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp);
    if((err<0) || resp) {
        dev_dbg(chip->card->dev,
                "error MSG_CONNECTOR_SET_OUT_AUDIO_LEVEL card(%d)
resp(%x)\n",
                chip->chip_idx, resp);
        return -EINVAL;
    }
    return 0;
}
Quoted 2 lines

When the function, snd_mixart_send_msg(), assigns nothing to the variable in error cases, dev_dbg() prints uninitialized value.

Hm. I realized that this interpretation is not enough. When value of the error is not negative, snd_mixart_send_msg() can assign something to the resp variable, then dev_dbg() is called. In short, when the function is successful, there's a case that the message is processed. This is a bit strange...

I think a condition statement for the resp variable is needless here, as long as the variable is initialized ahead...

Quoted 1 line

Anyway, it's better to initialize it.

Regards

Takashi Sakamoto

Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

My static checker complains that "resp" could be unitialized on error when we print its value.

Applied, thanks.

Takashi

Quoted 15 lines
sound/pci/mixart/mixart_mixer.c +1 -1
index 58fd79eb..51e5349 100644
@@ -965,7 +965,7 @@ static int mixart_update_monitoring(struct snd_mixart* chip, int channel)
 	int err;
 	struct mixart_msg request;
 	struct mixart_set_out_audio_level audio_level;
-	u32 resp;
+	u32 resp = 0;
 
 	if(chip->pipe_out_ana.status == PIPE_UNDEFINED)
 		return -EINVAL; /* no pipe defined */