Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: soc-dapm: Add helper for comparing widget name

Some drivers use one event callback for multiple widgets but still need
to perform a bit different actions based on actual widget. This is done
by comparing widget name, however drivers tend to miss possible name
prefix. Add a helper to solve common mistakes.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20231003155710.821315-2-krzysztof.kozlowski@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
76aca10c 1426b9ba

+14
+1
include/sound/soc-dapm.h
··· 469 469 470 470 int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream, 471 471 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai); 472 + int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s); 472 473 473 474 /* dapm path setup */ 474 475 int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
+1
sound/soc/soc-component.c
··· 242 242 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; 243 243 struct snd_kcontrol *kctl; 244 244 245 + /* When updating, change also snd_soc_dapm_widget_name_cmp() */ 245 246 if (component->name_prefix) 246 247 snprintf(name, ARRAY_SIZE(name), "%s %s", component->name_prefix, ctl); 247 248 else
+12
sound/soc/soc-dapm.c
··· 2728 2728 } 2729 2729 EXPORT_SYMBOL_GPL(snd_soc_dapm_update_dai); 2730 2730 2731 + int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s) 2732 + { 2733 + struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); 2734 + const char *wname = widget->name; 2735 + 2736 + if (component->name_prefix) 2737 + wname += strlen(component->name_prefix) + 1; /* plus space */ 2738 + 2739 + return strcmp(wname, s); 2740 + } 2741 + EXPORT_SYMBOL_GPL(snd_soc_dapm_widget_name_cmp); 2742 + 2731 2743 /* 2732 2744 * dapm_update_widget_flags() - Re-compute widget sink and source flags 2733 2745 * @w: The widget for which to update the flags