Skip to contentSkip to conversation

greybus: audio: ensure module is set to avoid crash on dev_err message

PATCH In review Colin King 3 participants 4 messages Sep 23, 2016

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 greybus: audio: ensure module is set to avoid crash on dev_err message

From: Colin Ian King <[email protected]>

Currently, if info is null, the dev_err message is dereferencing an uninitialized module pointer. Instead, initialize module before the dev_err call to fix this issue.

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

---
 drivers/staging/greybus/audio_topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/audio_topology.c +3 -3
index 5eef536..c43a959 100644
@@ -171,6 +171,9 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
 	data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
 	info = (struct gb_audio_ctl_elem_info *)data->info;
 
+	module = find_gb_module(gbcodec, kcontrol->id.name);
+	if (!module)
+		return -EINVAL;
 	if (!info) {
 		dev_err(module->dev, "NULL info for %s\n", uinfo->id.name);
 		return -EINVAL;
@@ -192,9 +195,6 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
 		uinfo->value.enumerated.items = max;
 		if (uinfo->value.enumerated.item > max - 1)
 			uinfo->value.enumerated.item = max - 1;
-		module = find_gb_module(gbcodec, kcontrol->id.name);
-		if (!module)
-			return -EINVAL;
 		name = gbaudio_map_controlid(module, data->ctl_id,
 					     uinfo->value.enumerated.item);
 		strlcpy(uinfo->value.enumerated.name, name, NAME_SIZE);
Signature · 1 line
2.9.3
#1 lore raw
Quoted 20 lines · Colin King

From: Colin Ian King <[email protected]>

Currently, if info is null, the dev_err message is dereferencing an uninitialized module pointer. Instead, initialize module before the dev_err call to fix this issue.

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

---
 drivers/staging/greybus/audio_topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/audio_topology.c +0 -0
index 5eef536..c43a959 100644

drivers/staging/greybus/audio_topology.c static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol, · line 176

Quoted 6 lines
drivers/staging/greybus/audio_topology.c +3 -0
@@ -171,6 +171,9 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
 	data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
 	info = (struct gb_audio_ctl_elem_info *)data->info;
 
+	module = find_gb_module(gbcodec, kcontrol->id.name);
+	if (!module)
+		return -EINVAL;

How do you know you can get a module at this point in time, you haven't looked at the type of info to know that?

I agree that there is an issue here, but I don't think this is the correct fix. Vaibhav?

maintainer
#2 lore raw
Quoted 31 lines · Greg Kroah-Hartman
Quoted 20 lines · Colin King

From: Colin Ian King <[email protected]>

Currently, if info is null, the dev_err message is dereferencing an uninitialized module pointer. Instead, initialize module before the dev_err call to fix this issue.

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

---
 drivers/staging/greybus/audio_topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/audio_topology.c +0 -0
index 5eef536..c43a959 100644

drivers/staging/greybus/audio_topology.c static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol, · line 176

Quoted 6 lines
drivers/staging/greybus/audio_topology.c +3 -0
@@ -171,6 +171,9 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
      data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
      info = (struct gb_audio_ctl_elem_info *)data->info;
 
+     module = find_gb_module(gbcodec, kcontrol->id.name);
+     if (!module)
+             return -EINVAL;

How do you know you can get a module at this point in time, you haven't looked at the type of info to know that?

Quoted 2 lines

I agree that there is an issue here, but I don't think this is the correct fix. Vaibhav?

Actually, fetching module is not related to info->type. However it is only required in case of ENUMERATED element_type, thus used in specific case. Also, I think it's better to use codec->dev in the err message and align with other err_msg in this function.

Hi Colin, thanks for sharing this patch. Do you mind updating this patch including my above suggestion? Otherwise, I can share a separate patch.

--
thanks,
vaibhav

Quoted 1 line
#3 lore raw
Quoted 36 lines · Vaibhav Agarwal
Quoted 31 lines · Greg Kroah-Hartman
Quoted 20 lines · Colin King

From: Colin Ian King <[email protected]>

Currently, if info is null, the dev_err message is dereferencing an uninitialized module pointer. Instead, initialize module before the dev_err call to fix this issue.

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

---
 drivers/staging/greybus/audio_topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/audio_topology.c +0 -0
index 5eef536..c43a959 100644

drivers/staging/greybus/audio_topology.c static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol, · line 176

Quoted 6 lines
drivers/staging/greybus/audio_topology.c +3 -0
@@ -171,6 +171,9 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
      data = (struct gbaudio_ctl_pvt *)kcontrol->private_value;
      info = (struct gb_audio_ctl_elem_info *)data->info;
 
+     module = find_gb_module(gbcodec, kcontrol->id.name);
+     if (!module)
+             return -EINVAL;

How do you know you can get a module at this point in time, you haven't looked at the type of info to know that?

Quoted 2 lines

I agree that there is an issue here, but I don't think this is the correct fix. Vaibhav?

Quoted 8 lines

Actually, fetching module is not related to info->type. However it is only required in case of ENUMERATED element_type, thus used in specific case. Also, I think it's better to use codec->dev in the err message and align with other err_msg in this function.

Hi Colin, thanks for sharing this patch. Do you mind updating this patch including my above suggestion? Otherwise, I can share a separate patch.

Vaibhav, I'm currently traveling, so won't be able to check this until next week, so if you would rather send a correct fix sooner rather me re-sending a fix then I'm fine with that.

Thanks, Colin

Quoted 5 lines

--
thanks,
vaibhav

Quoted 1 line