Skip to contentSkip to conversation

ASoC: dapm: Fix empty list check in dapm_new_mux()

PATCH Applied Lars-Peter Clausen 3 participants 5 messages Aug 1, 2013 – Aug 2, 2013

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

PATCH 1/1 ASoC: dapm: Fix empty list check in dapm_new_mux()

list_first_entry() will always return a valid pointer, even if the list is empty. So the check whether path is NULL will always be false. So we end up calling dapm_create_or_share_mixmux_kcontrol() with a path struct that points right in the middle of the widget struct and by trying to modify the path the widgets memory will become corrupted. Fix this by using list_emtpy() to check if the widget doesn't have any paths.

---
This is the real fix for the rt5640 crash.

---
 sound/soc/soc-dapm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
sound/soc/soc-dapm.c +4 -3
index 5f64c16..196cea7 100644
@@ -747,13 +747,14 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
 		return -EINVAL;
 	}
 
-	path = list_first_entry(&w->sources, struct snd_soc_dapm_path,
-				list_sink);
-	if (!path) {
+	if (list_empty(&w->sources)) {
 		dev_err(dapm->dev, "ASoC: mux %s has no paths\n", w->name);
 		return -EINVAL;
 	}
 
+	path = list_first_entry(&w->sources, struct snd_soc_dapm_path,
+				list_sink);
+
 	ret = dapm_create_or_share_mixmux_kcontrol(w, 0, path);
 	if (ret < 0)
 		return ret;
Signature · 1 line
1.8.0
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Lars-Peter Clausen

list_first_entry() will always return a valid pointer, even if the list is empty. So the check whether path is NULL will always be false. So we end up calling dapm_create_or_share_mixmux_kcontrol() with a path struct that points right in the middle of the widget struct and by trying to modify the path the widgets memory will become corrupted. Fix this by using list_emtpy() to check if the widget doesn't have any paths.

---
This is the real fix for the rt5640 crash.

maintainer Applied
#2 lore raw
In reply to Lars-Peter Clausen
Quoted 6 lines · Lars-Peter Clausen

list_first_entry() will always return a valid pointer, even if the list is empty. So the check whether path is NULL will always be false. So we end up calling dapm_create_or_share_mixmux_kcontrol() with a path struct that points right in the middle of the widget struct and by trying to modify the path the widgets memory will become corrupted. Fix this by using list_emtpy() to check if the widget doesn't have any paths.

Applied, thanks - looking at this I'm surprised we've not been running into problems before.

#3 lore raw
Quoted 11 lines · Mark Brown
Quoted 8 lines · Lars-Peter Clausen

list_first_entry() will always return a valid pointer, even if the list is empty. So the check whether path is NULL will always be false. So we end up calling dapm_create_or_share_mixmux_kcontrol() with a path struct that points right in the middle of the widget struct and by trying to modify the path the widgets memory will become corrupted. Fix this by using list_emtpy() to check if the widget doesn't have any paths.

Quoted 2 lines

Applied, thanks - looking at this I'm surprised we've not been running into problems before.

I don't see this in the ASoC git tree, in either for-next, fix/dapm, or topic/dapm.

maintainer
#4 lore raw
Quoted 2 lines · Stephen Warren

I don't see this in the ASoC git tree, in either for-next, fix/dapm, or topic/dapm.

I see it... it missed -next due to being pushed out late.