All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ASoC: damp: Reset dapm wcache after freeing damp widgets
@ 2015-11-10 16:12 Jyri Sarha
  2015-11-10 18:53 ` Mark Brown
  2015-11-10 18:53 ` Applied "ASoC: dapm: Reset dapm wcache after freeing damp widgets" to the asoc tree Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Jyri Sarha @ 2015-11-10 16:12 UTC (permalink / raw)
  To: alsa-devel
  Cc: peter.ujfalusi, lars, Jyri Sarha, liam.r.girdwood, broonie, balbi

If there is anything in damp->path_source_cache or
damp->path_sink_cache, it can not be valid after the widgets have been
freed. Without this patch a repeated remove and load of a machine
driver may cause NULL pointer reference in dapm_wcache_lookup() when a
freed widget, not belonging to any list, is haunting in the wcache.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
Reported-by: Felipe Balbi <balbi@ti.com>
---
The patch fixes the problem reported here:
http://mailman.alsa-project.org/pipermail/alsa-devel/2015-October/099431.html

For v2, followed Lars-Peter's suggestion here:
http://mailman.alsa-project.org/pipermail/alsa-devel/2015-November/100335.html

 include/sound/soc-dapm.h | 1 +
 sound/soc/soc-dapm.c     | 7 +++++++
 sound/soc/soc-topology.c | 1 +
 3 files changed, 9 insertions(+)

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 5abba03..ddcbe33 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -398,6 +398,7 @@ int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
 			     const struct snd_soc_dapm_route *route, int num);
 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
+void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm);
 
 /* dapm events */
 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index ff8bda4..945a792 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2276,6 +2276,12 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
 	kfree(w);
 }
 
+void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm)
+{
+	dapm->path_sink_cache.widget = NULL;
+	dapm->path_source_cache.widget = NULL;
+}
+
 /* free all dapm widgets and resources */
 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
 {
@@ -2286,6 +2292,7 @@ static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
 			continue;
 		snd_soc_dapm_free_widget(w);
 	}
+	snd_soc_dapm_reset_cache(dapm);
 }
 
 static struct snd_soc_dapm_widget *dapm_find_widget(
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index 69d01cd..c6ee033 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -1805,6 +1805,7 @@ void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
 		snd_soc_tplg_widget_remove(w);
 		snd_soc_dapm_free_widget(w);
 	}
+	snd_soc_dapm_reset_cache(dapm);
 }
 EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove_all);
 
-- 
1.9.1

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

* Re: [PATCH v2] ASoC: damp: Reset dapm wcache after freeing damp widgets
  2015-11-10 16:12 [PATCH v2] ASoC: damp: Reset dapm wcache after freeing damp widgets Jyri Sarha
@ 2015-11-10 18:53 ` Mark Brown
  2015-11-11 13:00   ` Jyri Sarha
  2015-11-10 18:53 ` Applied "ASoC: dapm: Reset dapm wcache after freeing damp widgets" to the asoc tree Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Mark Brown @ 2015-11-10 18:53 UTC (permalink / raw)
  To: Jyri Sarha; +Cc: liam.r.girdwood, peter.ujfalusi, alsa-devel, lars, balbi


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

On Tue, Nov 10, 2015 at 06:12:42PM +0200, Jyri Sarha wrote:
> If there is anything in damp->path_source_cache or
> damp->path_sink_cache, it can not be valid after the widgets have been
> freed. Without this patch a repeated remove and load of a machine
> driver may cause NULL pointer reference in dapm_wcache_lookup() when a
> freed widget, not belonging to any list, is haunting in the wcache.

Please try to check the spelling in your subject lines!

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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



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

* Applied "ASoC: dapm: Reset dapm wcache after freeing damp widgets" to the asoc tree
  2015-11-10 16:12 [PATCH v2] ASoC: damp: Reset dapm wcache after freeing damp widgets Jyri Sarha
  2015-11-10 18:53 ` Mark Brown
@ 2015-11-10 18:53 ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2015-11-10 18:53 UTC (permalink / raw)
  To: Jyri Sarha, Felipe Balbi, Mark Brown; +Cc: alsa-devel

The patch

   ASoC: dapm: Reset dapm wcache after freeing damp widgets

has been applied to the asoc tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From fd589a1be20fdd76ef97700dd0185e7a060546dc Mon Sep 17 00:00:00 2001
From: Jyri Sarha <jsarha@ti.com>
Date: Tue, 10 Nov 2015 18:12:42 +0200
Subject: [PATCH] ASoC: dapm: Reset dapm wcache after freeing damp widgets

If there is anything in damp->path_source_cache or
damp->path_sink_cache, it can not be valid after the widgets have been
freed. Without this patch a repeated remove and load of a machine
driver may cause NULL pointer reference in dapm_wcache_lookup() when a
freed widget, not belonging to any list, is haunting in the wcache.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
Reported-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 include/sound/soc-dapm.h | 1 +
 sound/soc/soc-dapm.c     | 7 +++++++
 sound/soc/soc-topology.c | 1 +
 3 files changed, 9 insertions(+)

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 7855cfe46b69..95a937eafb79 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -398,6 +398,7 @@ int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
 			     const struct snd_soc_dapm_route *route, int num);
 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
+void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm);
 
 /* dapm events */
 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 016eba10b1ec..7d009428934a 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2293,6 +2293,12 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
 	kfree(w);
 }
 
+void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm)
+{
+	dapm->path_sink_cache.widget = NULL;
+	dapm->path_source_cache.widget = NULL;
+}
+
 /* free all dapm widgets and resources */
 static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
 {
@@ -2303,6 +2309,7 @@ static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
 			continue;
 		snd_soc_dapm_free_widget(w);
 	}
+	snd_soc_dapm_reset_cache(dapm);
 }
 
 static struct snd_soc_dapm_widget *dapm_find_widget(
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index 8d7ec80af51b..cce63fe65dd9 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -1805,6 +1805,7 @@ void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
 		snd_soc_tplg_widget_remove(w);
 		snd_soc_dapm_free_widget(w);
 	}
+	snd_soc_dapm_reset_cache(dapm);
 }
 EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove_all);
 
-- 
2.6.2

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

* Re: [PATCH v2] ASoC: damp: Reset dapm wcache after freeing damp widgets
  2015-11-10 18:53 ` Mark Brown
@ 2015-11-11 13:00   ` Jyri Sarha
  0 siblings, 0 replies; 4+ messages in thread
From: Jyri Sarha @ 2015-11-11 13:00 UTC (permalink / raw)
  To: Mark Brown; +Cc: liam.r.girdwood, peter.ujfalusi, alsa-devel, lars, balbi

On 11/10/15 20:53, Mark Brown wrote:
> On Tue, Nov 10, 2015 at 06:12:42PM +0200, Jyri Sarha wrote:
>> If there is anything in damp->path_source_cache or
>> damp->path_sink_cache, it can not be valid after the widgets have been
>> freed. Without this patch a repeated remove and load of a machine
>> driver may cause NULL pointer reference in dapm_wcache_lookup() when a
>> freed widget, not belonging to any list, is haunting in the wcache.
>
> Please try to check the spelling in your subject lines!
>


Argh, these acronyms wont get corrected by blind spell checker run. I 
need to be more careful in the future, at least for the subject.

Sorry,
Jyri

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

end of thread, other threads:[~2015-11-11 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-10 16:12 [PATCH v2] ASoC: damp: Reset dapm wcache after freeing damp widgets Jyri Sarha
2015-11-10 18:53 ` Mark Brown
2015-11-11 13:00   ` Jyri Sarha
2015-11-10 18:53 ` Applied "ASoC: dapm: Reset dapm wcache after freeing damp widgets" to the asoc tree 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.