All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux()
@ 2013-08-01 16:30 Lars-Peter Clausen
  2013-08-01 17:20 ` Stephen Warren
  2013-08-01 18:44 ` Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2013-08-01 16:30 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Olof Johansson, Bard Liao, alsa-devel, Lars-Peter Clausen,
	Stephen Warren

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.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

---
This is the real fix for the rt5640 crash.
---
 sound/soc/soc-dapm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 5f64c16..196cea7 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -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;
-- 
1.8.0

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

* Re: [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux()
  2013-08-01 16:30 [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux() Lars-Peter Clausen
@ 2013-08-01 17:20 ` Stephen Warren
  2013-08-01 18:44 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Warren @ 2013-08-01 17:20 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Olof Johansson, Bard Liao, alsa-devel, Mark Brown, Liam Girdwood

On 08/01/2013 10:30 AM, Lars-Peter Clausen wrote:
> 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.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> 
> ---
> This is the real fix for the rt5640 crash.

Tested-by: Stephen Warren <swarren@nvidia.com>

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

* Re: [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux()
  2013-08-01 16:30 [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux() Lars-Peter Clausen
  2013-08-01 17:20 ` Stephen Warren
@ 2013-08-01 18:44 ` Mark Brown
  2013-08-02 15:43   ` Stephen Warren
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Brown @ 2013-08-01 18:44 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Olof Johansson, Bard Liao, alsa-devel, Liam Girdwood,
	Stephen Warren


[-- Attachment #1.1: Type: text/plain, Size: 597 bytes --]

On Thu, Aug 01, 2013 at 06:30:38PM +0200, Lars-Peter Clausen wrote:
> 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.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

* Re: [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux()
  2013-08-01 18:44 ` Mark Brown
@ 2013-08-02 15:43   ` Stephen Warren
  2013-08-02 16:11     ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2013-08-02 15:43 UTC (permalink / raw)
  To: Mark Brown
  Cc: Olof Johansson, Bard Liao, alsa-devel, Lars-Peter Clausen,
	Liam Girdwood

On 08/01/2013 12:44 PM, Mark Brown wrote:
> On Thu, Aug 01, 2013 at 06:30:38PM +0200, Lars-Peter Clausen
> wrote:
>> 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.

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

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

* Re: [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux()
  2013-08-02 15:43   ` Stephen Warren
@ 2013-08-02 16:11     ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2013-08-02 16:11 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Olof Johansson, Bard Liao, alsa-devel, Lars-Peter Clausen,
	Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 213 bytes --]

On Fri, Aug 02, 2013 at 09:43:50AM -0600, Stephen Warren wrote:

> 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.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

end of thread, other threads:[~2013-08-02 16:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-01 16:30 [PATCH] ASoC: dapm: Fix empty list check in dapm_new_mux() Lars-Peter Clausen
2013-08-01 17:20 ` Stephen Warren
2013-08-01 18:44 ` Mark Brown
2013-08-02 15:43   ` Stephen Warren
2013-08-02 16:11     ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.