Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: sdw_utils: senary: handle a missing name_prefix
@ 2026-11-10  7:34 Qianghua Wang
  2026-11-10  7:44 ` sashiko-bot
  2026-11-10  8:05 ` [PATCH v2] " Qianghua Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Qianghua Wang @ 2026-11-10  7:34 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-sound, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Cezary Rojewski, Peter Ujfalusi, Bard Liao, Kai Vehmanen,
	Pierre-Louis Bossart, bo liu, Qianghua Wang

asoc_sdw_senary_sdca_jack_rtd_init() passes component->name_prefix to
strstr(). When codec_conf does not apply the prefix, name_prefix is
NULL and card registration oopses.

DAPM widgets then keep the bare names from the codec driver (HP, MIC2,
SPK, DMIC). Keep the existing "sn624x ..." routes when name_prefix is
set, and connect those bare widgets when it is missing. card->components
still reports hs:sn624x-sdca and mic:sn624x-dmic.

Signed-off-by: Qianghua Wang <qianghua.wang@senarytech.com>
---

diff --git a/sound/soc/sdw_utils/soc_sdw_senary_dmic.c b/sound/soc/sdw_utils/soc_sdw_senary_dmic.c
index 748170656..725f4658e 100644
--- a/sound/soc/sdw_utils/soc_sdw_senary_dmic.c
+++ b/sound/soc/sdw_utils/soc_sdw_senary_dmic.c
@@ -15,6 +15,10 @@ static const struct snd_soc_dapm_route senary_dmic_map[] = {
 	{ "sn624x DMIC", NULL, "Dmic" },
 };
 
+static const struct snd_soc_dapm_route senary_dmic_map_bare[] = {
+	{ "DMIC", NULL, "Dmic" },
+};
+
 int asoc_sdw_senary_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
 {
 	struct snd_soc_card *card = rtd->card;
@@ -25,14 +29,21 @@ int asoc_sdw_senary_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_so
 
 	component = dai->component;
 
-	ret = snd_soc_dapm_add_routes(dapm, senary_dmic_map,
-				      ARRAY_SIZE(senary_dmic_map));
+	if (component->name_prefix) {
+		ret = snd_soc_dapm_add_routes(dapm, senary_dmic_map,
+					      ARRAY_SIZE(senary_dmic_map));
+		mic_name = devm_kstrdup(card->dev, component->name_prefix, GFP_KERNEL);
+	} else {
+		dev_warn(card->dev, "sn624x dmic: component %s has no name_prefix\n",
+			 component->name);
+		ret = snd_soc_dapm_add_routes(dapm, senary_dmic_map_bare,
+					      ARRAY_SIZE(senary_dmic_map_bare));
+		mic_name = devm_kstrdup(card->dev, "sn624x", GFP_KERNEL);
+	}
 	if (ret) {
 		dev_err(card->dev, "senary dmic map addition failed: %d\n", ret);
 		return ret;
 	}
-
-	mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s", component->name_prefix);
 	if (!mic_name)
 		return -ENOMEM;
 
diff --git a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
index 5c2cd7530..0adde845a 100644
--- a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
+++ b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
@@ -18,6 +18,10 @@ static const struct snd_soc_dapm_route sn624x_spk_map[] = {
 	{ "Speaker", NULL, "sn624x SPK" },
 };
 
+static const struct snd_soc_dapm_route sn624x_spk_map_bare[] = {
+	{ "Speaker", NULL, "SPK" },
+};
+
 /* Structure to map codec names to respective route arrays and sizes */
 struct codec_route_map {
 	const char *codec_name;
@@ -45,16 +49,30 @@ int asoc_sdw_senary_sdca_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct sn
 	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
 	int ret;
 
-	/* Match by DAI name prefix (e.g. sn624x-sdca-aif2). */
 	const struct codec_route_map *route_map = get_codec_route_map(dai->name);
+	const struct snd_soc_dapm_route *routes;
+	size_t nroutes;
 
 	if (!route_map) {
 		dev_err(rtd->dev, "failed to get codec name and route map\n");
 		return -EINVAL;
 	}
 
-	/* Add routes */
-	ret = snd_soc_dapm_add_routes(dapm, route_map->route_map, route_map->route_size);
+	/*
+	 * No name_prefix means the codec widgets were created as "SPK",
+	 * not "sn624x SPK". DAI name is still sn624x-sdca-aif2.
+	 */
+	if (!dai->component->name_prefix) {
+		dev_warn(rtd->dev, "sn624x spk: component %s has no name_prefix\n",
+			 dai->component->name);
+		routes = sn624x_spk_map_bare;
+		nroutes = ARRAY_SIZE(sn624x_spk_map_bare);
+	} else {
+		routes = route_map->route_map;
+		nroutes = route_map->route_size;
+	}
+
+	ret = snd_soc_dapm_add_routes(dapm, routes, nroutes);
 	if (ret)
 		dev_err(rtd->dev, "failed to add rt sdca spk map: %d\n", ret);
 
diff --git a/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c b/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c
index 1dab6f998..c61c1f160 100644
--- a/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c
+++ b/sound/soc/sdw_utils/soc_sdw_senary_sdca_jack_common.c
@@ -57,6 +57,12 @@ static const struct snd_soc_dapm_route senary_sdca_jack_map[] = {
 	{ "sn624x MIC2", NULL, "Headset Mic" },
 };
 
+/* Widget names stay bare when codec_conf did not apply a name_prefix. */
+static const struct snd_soc_dapm_route senary_sdca_jack_map_bare[] = {
+	{ "Headphone", NULL, "HP" },
+	{ "MIC2", NULL, "Headset Mic" },
+};
+
 static struct snd_soc_jack_pin senary_sdca_jack_pins[] = {
 	{
 		.pin    = "Headphone",
@@ -68,10 +74,6 @@ static struct snd_soc_jack_pin senary_sdca_jack_pins[] = {
 	},
 };
 
-static const char * const need_sdca_suffix[] = {
-	"sn624x"
-};
-
 int asoc_sdw_senary_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
 {
 	struct snd_soc_card *card = rtd->card;
@@ -79,38 +81,41 @@ int asoc_sdw_senary_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd, struct s
 	struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
 	struct snd_soc_component *component;
 	struct snd_soc_jack *jack;
+	const struct snd_soc_dapm_route *routes = senary_sdca_jack_map;
+	const char *prefix;
+	int nroutes = ARRAY_SIZE(senary_sdca_jack_map);
 	int ret;
-	int i;
 
 	component = dai->component;
+	prefix = component->name_prefix;
+	/*
+	 * codec_conf should set name_prefix to "sn624x" before DAPM widgets
+	 * are created. If that match fails, name_prefix is NULL: strstr()
+	 * oopses, and the widgets keep the bare names from the codec driver.
+	 */
+	if (!prefix) {
+		dev_warn(card->dev,
+			 "sn624x jack: component %s has no name_prefix\n",
+			 component->name);
+		prefix = "sn624x";
+		routes = senary_sdca_jack_map_bare;
+		nroutes = ARRAY_SIZE(senary_sdca_jack_map_bare);
+	} else if (!strstr(prefix, "sn624x")) {
+		dev_err(card->dev, "%s is not supported\n", prefix);
+		return -EINVAL;
+	}
+
 	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
-					  "%s hs:%s",
-					  card->components, component->name_prefix);
+					  "%s hs:%s-sdca",
+					  card->components, prefix);
 	if (!card->components)
 		return -ENOMEM;
 
-	for (i = 0; i < ARRAY_SIZE(need_sdca_suffix); i++) {
-		if (!strstr(component->name_prefix, need_sdca_suffix[i]))
-			continue;
-
-		card->components = devm_kasprintf(card->dev, GFP_KERNEL,
-						  "%s-sdca", card->components);
-		if (!card->components)
-			return -ENOMEM;
-
-		ret = snd_soc_dapm_add_routes(dapm, senary_sdca_jack_map,
-					      ARRAY_SIZE(senary_sdca_jack_map));
-		if (ret) {
-			dev_err(card->dev,
-				"senary sdca jack map addition failed: %d\n", ret);
-			return ret;
-		}
-		break;
-	}
-
-	if (i == ARRAY_SIZE(need_sdca_suffix)) {
-		dev_err(card->dev, "%s is not supported\n", component->name_prefix);
-		return -EINVAL;
+	ret = snd_soc_dapm_add_routes(dapm, routes, nroutes);
+	if (ret) {
+		dev_err(card->dev, "senary sdca jack map addition failed: %d\n",
+			ret);
+		return ret;
 	}
 
 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",

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

end of thread, other threads:[~2026-11-11  6:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10  7:34 [PATCH] ASoC: sdw_utils: senary: handle a missing name_prefix Qianghua Wang
2026-11-10  7:44 ` sashiko-bot
2026-11-10  8:05 ` [PATCH v2] " Qianghua Wang
2026-11-10 14:45   ` Liao, Bard
2026-11-11  6:36     ` reply " qianghua.wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox