mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Amadeusz Sławiński" <amade@asmblr.net>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, "Mark Brown" <broonie@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Amadeusz Sławiński" <amade@asmblr.net>
Subject: [PATCH 8/8] ASoC: soc-dapm: Remove widget from cache on removal
Date: Wed, 14 Oct 2026 22:06:08 +0200	[thread overview]
Message-ID: <20261014200608.118770-9-amade@asmblr.net> (raw)
In-Reply-To: <20261014200608.118770-1-amade@asmblr.net>

When a single DAPM widget is removed, it also needs to be removed from
the widget cache to prevent dapm_wcache_lookup() from using a dangling
pointer when checking if a widget is in cache. Since widgets may be
cached across different DAPM contexts on the card (e.g. card routes),
clear any matching cache entries across all DAPM contexts on the card.
Since dapm_free_widgets() calls snd_soc_dapm_free_widget() anyway, it
does not need to clear cache anymore.

Signed-off-by: Amadeusz Sławiński <amade@asmblr.net>
---
 sound/soc/soc-dapm.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 74be5e209493..7455160b11fe 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2869,6 +2869,7 @@ static void dapm_free_path(struct snd_soc_dapm_path *path)
  */
 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
 {
+	struct snd_soc_dapm_context *d;
 	struct snd_soc_dapm_path *p, *next_p;
 	enum snd_soc_dapm_direction dir;
 
@@ -2889,6 +2890,22 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
 
 	dapm_debugfs_free_widget(w);
 
+	if (w->dapm) {
+		if (w->dapm->card) {
+			for_each_card_dapms(w->dapm->card, d) {
+				if (d->wcache_sink == w)
+					d->wcache_sink = NULL;
+				if (d->wcache_source == w)
+					d->wcache_source = NULL;
+			}
+		} else {
+			if (w->dapm->wcache_sink == w)
+				w->dapm->wcache_sink = NULL;
+			if (w->dapm->wcache_source == w)
+				w->dapm->wcache_source = NULL;
+		}
+	}
+
 	kfree(w->kcontrols);
 	kfree_const(w->name);
 	kfree_const(w->sname);
@@ -2906,9 +2923,6 @@ static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
 			continue;
 		snd_soc_dapm_free_widget(w);
 	}
-
-	dapm->wcache_sink	= NULL;
-	dapm->wcache_source	= NULL;
 }
 
 static struct snd_soc_dapm_widget *dapm_find_widget(
-- 
2.56.0


      parent reply	other threads:[~2026-10-14 20:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 20:06 [PATCH 0/8] ASoC: Series of loose fixes Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 1/8] ASoC: soc-link: Correct stream stop operations in snd_soc_link_trigger Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 2/8] ASoC: ops: Fix return value in snd_soc_limit_volume() Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 3/8] ASoC: soc-topology-test: Check return value of kunit_device_register() Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 4/8] ASoC: soc-card-test: " Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 5/8] ASoC: soc-ac97: Fix error handling in snd_soc_new_ac97_component() Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 6/8] ASoC: soc-ac97: Fix debug message Amadeusz Sławiński
2026-10-14 20:06 ` [PATCH 7/8] ASoC: soc-component: Fix return type of snd_soc_pcm_component_pointer() Amadeusz Sławiński
2026-10-14 20:06 ` Amadeusz Sławiński [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014200608.118770-9-amade@asmblr.net \
    --to=amade@asmblr.net \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®