Re: [PATCH v2 1/3] ASoC: dapm: Fix widget lookup with prefixed names across DAPM contexts

From: Frank Li

Date: Fri Apr 17 2026 - 07:06:03 EST


On Wed, Apr 15, 2026 at 05:19:40PM +0900, Chancel Liu wrote:

subject suggest change to

ASoC: dapm: Use snd_soc_dapm_widget_name_cmp() to fix widget lookup failures

Frank
> Currently dapm_find_widget() manually constructs a prefixed widget name
> based on the provided DAPM context and compares it using strcmp(). This
> happens to work in most cases because callers usually know which DAPM
> context the target widget belongs to and pass in the matching DAPM
> context.
>
> However, this assumption breaks when search_other_contexts is enabled.
> In such cases, callers may intentionally pass a different DAPM context,
> while searching for a widget that actually belongs to another DAPM
> context.
>
> For example, when searching for a "DAC" widget, the widget belongs to
> the codec DAPM and be registered with a codec prefix, while the caller
> passes card->dapm and intends to search across all DAPM contexts. The
> current implementation incorrectly applies the caller card DAPM causing
> the lookup to fail even though the widget exists on the card.
>
> Use snd_soc_dapm_widget_name_cmp() instead, which compares widget names
> using the widget's own DAPM context and prefix. It fixes widget lookup
> failures when searching across different DAPM contexts on the card.
>
> Fixes: ae4fc532244b ("ASoC: dapm: use component prefix when checking widget names")
> Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
> Assisted-by: Cody:Claude-3.5-Sonnet
> ---
> sound/soc/soc-dapm.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index d6192204e613..c5b80d9ed64b 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -2906,20 +2906,9 @@ static struct snd_soc_dapm_widget *dapm_find_widget(
> {
> struct snd_soc_dapm_widget *w;
> struct snd_soc_dapm_widget *fallback = NULL;
> - char prefixed_pin[80];
> - const char *pin_name;
> - const char *prefix = dapm_prefix(dapm);
> -
> - if (prefix) {
> - snprintf(prefixed_pin, sizeof(prefixed_pin), "%s %s",
> - prefix, pin);
> - pin_name = prefixed_pin;
> - } else {
> - pin_name = pin;
> - }
>
> for_each_card_widgets(dapm->card, w) {
> - if (!strcmp(w->name, pin_name)) {
> + if (!snd_soc_dapm_widget_name_cmp(w, pin)) {
> if (w->dapm == dapm)
> return w;
> else
> --
> 2.50.1
>