Skip to contentSkip to conversation

ASoC: bug fix patches

PATCH Superseded Kuninori Morimoto 2 participants 9 messages Feb 26, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kuninori Morimoto

author maintainer
#0 lore raw

cover ASoC: bug fix patches

Hi Takashi, Mark

These fixes the issues.

asoc/for-6.15 branch includes my patch (419d1918105e) which uses __free(), but because of it, it has of_node_put() count underrun issue. [1/3] will solve it.

alsa/for-next branch includes patch (0ecd24a6d8b2) which uses procfs, but we might get "already registered" error.
[3/3] will solve it.

[2/3] is cleanup utils code which is based on [1/3]

Kuninori Morimoto (3):
ASoC: simple-card-utils: Don't use __free(device_node) at graph_util_parse_dai()
ASoC: simple-card-utils: fixup dlc->xxx handling for error case
ASoC: hdmi-codec: use DAI ID and Name for ELD entry

 sound/soc/codecs/hdmi-codec.c         | 22 +++++++++++++++++++---
 sound/soc/generic/simple-card-utils.c | 22 +++++++++++++++-------
 2 files changed, 34 insertions(+), 10 deletions(-)
Signature · 11 lines
2.43.0





Thank you for your help !!

Best regards
---
Kuninori Morimoto
author maintainer
#1 lore raw

PATCH 1/3 ASoC: simple-card-utils: Don't use __free(device_node) at graph_util_parse_dai()

commit 419d1918105e ("ASoC: simple-card-utils: use __free(device_node) for device node") uses __free(device_node) for dlc->of_node, but we need to keep it while driver is in use.

Don't use __free(device_node) in graph_util_parse_dai().

Fixes 419d1918105e ("ASoC: simple-card-utils: use __free(device_node) for device node")
---
 sound/soc/generic/simple-card-utils.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
sound/soc/generic/simple-card-utils.c +5 -2
index 51e0e434514d..79fdd57a470c 100644
@@ -1102,6 +1102,7 @@ static int graph_get_dai_id(struct device_node *ep)
 int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
 			 struct snd_soc_dai_link_component *dlc, int *is_single_link)
 {
+	struct device_node *node;
 	struct device *dev = simple_priv_to_dev(priv);
 	struct of_phandle_args args = {};
 	struct snd_soc_dai *dai;
@@ -1110,7 +1111,7 @@ int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
 	if (!ep)
 		return 0;
 
-	struct device_node *node __free(device_node) = of_graph_get_port_parent(ep);
+	node = of_graph_get_port_parent(ep);
 
 	/*
 	 * Try to find from DAI node
@@ -1153,8 +1154,10 @@ int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
 	 *    if he unbinded CPU or Codec.
 	 */
 	ret = snd_soc_get_dlc(&args, dlc);
-	if (ret < 0)
+	if (ret < 0) {
+		of_node_put(node);
 		goto end;
+	}
 
 parse_dai_end:
 	if (is_single_link)
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/3 ASoC: simple-card-utils: fixup dlc->xxx handling for error case

In reply to Kuninori Morimoto

Current graph_util_parse_dai() has 2 issue for dlc->xxx handling.

1) dlc->xxx might be filled if snd_soc_get_dai_via_args() (A) works. In such case it will fill dlc->xxx first (B), and detect error after that (C). We need to fill dlc->xxx in success case only.

(A)	dai = snd_soc_get_dai_via_args(&args);
	if (dai) {
		ret = -ENOMEM;

^ dlc->of_node = ...
(B) dlc->dai_name = ...
v dlc->dai_args = ...
(C) if (!dlc->dai_args)

			goto end;
		...
	}

2) graph_util_parse_dai() itself has 2 patterns (X)(Y) to fill dlc->xxx. Both case, we need to call of_node_put(node) in error case, but we are calling it only in (Y) case.

	int graph_util_parse_dai(...)
	{
		...
		dai = snd_soc_get_dai_via_args(&args);
		if (dai) {
			...
 ^			dlc->of_node  = ...
(X)			dlc->dai_name = ...
 v			dlc->dai_args = ...
			...
		}
		...
(Y)		ret = snd_soc_get_dlc(&args, dlc);
		if (ret < 0) {
			of_node_put(node);
			...
		}
		...
	}

This patch fixup both case. Make it easy to understand, update lavel "end" to "err", too.

---
 sound/soc/generic/simple-card-utils.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
sound/soc/generic/simple-card-utils.c +14 -9
index 79fdd57a470c..692bafca55af 100644
@@ -1119,12 +1119,16 @@ int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
 	args.np = ep;
 	dai = snd_soc_get_dai_via_args(&args);
 	if (dai) {
+		const char *dai_name = snd_soc_dai_name_get(dai);
+		const struct of_phandle_args *dai_args = snd_soc_copy_dai_args(dev, &args);
+
 		ret = -ENOMEM;
+		if (!dai_args)
+			goto err;
+
 		dlc->of_node  = node;
-		dlc->dai_name = snd_soc_dai_name_get(dai);
-		dlc->dai_args = snd_soc_copy_dai_args(dev, &args);
-		if (!dlc->dai_args)
-			goto end;
+		dlc->dai_name = dai_name;
+		dlc->dai_args = dai_args;
 
 		goto parse_dai_end;
 	}
@@ -1154,16 +1158,17 @@ int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
 	 *    if he unbinded CPU or Codec.
 	 */
 	ret = snd_soc_get_dlc(&args, dlc);
-	if (ret < 0) {
-		of_node_put(node);
-		goto end;
-	}
+	if (ret < 0)
+		goto err;
 
 parse_dai_end:
 	if (is_single_link)
 		*is_single_link = of_graph_get_endpoint_count(node) == 1;
 	ret = 0;
-end:
+err:
+	if (ret < 0)
+		of_node_put(node);
+
 	return simple_ret(priv, ret);
 }
 EXPORT_SYMBOL_GPL(graph_util_parse_dai);
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/3 ASoC: hdmi-codec: use DAI ID and Name for ELD entry

In reply to Kuninori Morimoto

commit 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs") adds "eld#%d" entry for sound proc. It is using DAI ID. But it is possible to have duplicate DAI ID on same Sound Card. In such case, we will get below error. To avoid duplicate entry name, use RTD ID instead of DAI ID.

	proc_dir_entry 'card0/eld#0' already registered
	WARNING: CPU: 3 PID: 74 at fs/proc/generic.c:377 proc_register+0x11c/0x1a4
	Modules linked in:
	CPU: 3 UID: 0 PID: 74 Comm: kworker/u33:5 Not tainted 6.14.0-rc1-next-20250206-arm64-renesas #174
	Hardware name: Renesas Salvator-X 2nd version board based on r8a77951 (DT)
	Workqueue: events_unbound deferred_probe_work_func
	pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
	pc : proc_register+0x11c/0x1a4
	ata1: SATA link down (SStatus 0 SControl 300)
	lr : proc_register+0x11c/0x1a4
	sp : ffff8000847db880
	x29: ffff8000847db880 x28: 0000000000000000 x27: ffff0004c3403c98
	x26: 0000000000000005 x25: ffff0004c14b03e4 x24: 0000000000000005
	x23: ffff0004c361adb8 x22: ffff800082f24860 x21: ffff0004c361ad00
	x20: ffff0004c14b0300 x19: ffff0004c14b02c0 x18: 00000000ffffffff
	x17: 0000000000000000 x16: 00400034b5503510 x15: ffff8001047db447
	x14: 0000000000000000 x13: 6465726574736967 x12: ffff800082e66d30
	x11: 000000000000028e x10: ffff800082e66d30 x9 : 00000000ffffefff
	x8 : ffff800082ebed30 x7 : 0000000000017fe8 x6 : 0000000000000000
	x5 : 80000000fffff000 x4 : 0000000000000000 x3 : 0000000000000000
	x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0004c15b3600
	Call trace:
	 proc_register+0x11c/0x1a4 (P)
	 proc_create_data+0x3c/0x60
	 snd_info_register+0xd0/0x130
	 snd_info_register+0x30/0x130
	 snd_info_card_register+0x1c/0xbc
	 snd_card_register+0x194/0x1ec
	 snd_soc_bind_card+0x7f8/0xad0
	 snd_soc_register_card+0xe8/0xfc
	 devm_snd_soc_register_card+0x48/0x98
	 audio_graph_parse_of+0x1c4/0x1f8
	 graph_probe+0x6c/0x80
	...
---
 sound/soc/codecs/hdmi-codec.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
sound/soc/codecs/hdmi-codec.c +19 -3
index 17019b1d680b..bc01ff65bd6f 100644
@@ -842,12 +842,28 @@ static void print_eld_info(struct snd_info_entry *entry,
 static int hdmi_dai_proc_new(struct hdmi_codec_priv *hcp,
 			     struct snd_soc_dai *dai)
 {
+	struct snd_soc_component *component = dai->component;
+	struct snd_soc_card *card = component->card;
+	struct snd_soc_dai *d;
+	struct snd_soc_pcm_runtime *rtd;
 	struct snd_info_entry *entry;
 	char name[32];
-	int err;
+	int err, i, id = 0;
 
-	snprintf(name, sizeof(name), "eld#%d", dai->id);
-	err = snd_card_proc_new(dai->component->card->snd_card, name, &entry);
+	/*
+	 * To avoid duplicate proc entry, find its rtd and use rtd->id
+	 * instead of dai->id
+	 */
+	for_each_card_rtds(card, rtd) {
+		for_each_rtd_dais(rtd, i, d)
+			if (d == dai) {
+				id = rtd->id;
+				goto found;
+			}
+	}
+found:
+	snprintf(name, sizeof(name), "eld#%d", id);
+	err = snd_card_proc_new(card->snd_card, name, &entry);
 	if (err < 0)
 		return err;
 
Signature · 1 line
2.43.0
maintainer Acked-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] ASoC: hdmi-codec: use DAI ID and Name for ELD entry

Quoted 4 lines · Kuninori Morimoto

commit 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs") adds "eld#%d" entry for sound proc. It is using DAI ID. But it is possible to have duplicate DAI ID on same Sound Card. In such case, we will get below error. To avoid duplicate entry name, use RTD ID instead of DAI ID.

Given that this doesn't depend on the first two patches it'd probably have been better sent separately, especially since it needs to get merged via a separate tree.

author maintainer
#5 lore raw

Re: [PATCH 3/3] ASoC: hdmi-codec: use DAI ID and Name for ELD entry

Hi Mark, Takashi

Quoted 10 lines
Quoted 4 lines

commit 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs") adds "eld#%d" entry for sound proc. It is using DAI ID. But it is possible to have duplicate DAI ID on same Sound Card. In such case, we will get below error. To avoid duplicate entry name, use RTD ID instead of DAI ID.

Given that this doesn't depend on the first two patches it'd probably have been better sent separately, especially since it needs to get merged via a separate tree.

OK, thanks. Will do

# I noticed that the Subject was not matched, and the patch is missing # Fixes tag. I will post it as v2 patch, soon

Thank you for your help !!

Best regards
---
Kuninori Morimoto

author maintainer
#6 lore raw

Re: [PATCH 3/3] ASoC: hdmi-codec: use DAI ID and Name for ELD entry

Hi Takashi

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

commit 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs") adds "eld#%d" entry for sound proc. It is using DAI ID. But it is possible to have duplicate DAI ID on same Sound Card. In such case, we will get below error. To avoid duplicate entry name, use RTD ID instead of DAI ID.

Quoted 8 lines
Quoted 3 lines

Given that this doesn't depend on the first two patches it'd probably have been better sent separately, especially since it needs to get merged via a separate tree.

OK, thanks. Will do

# I noticed that the Subject was not matched, and the patch is missing # Fixes tag. I will post it as v2 patch, soon

This patch has "ASoC: " on Subject, but commit 0ecd24a6d8b2 exists only on your tree, not on Mark tree. Will post v2

Thank you for your help !!

Best regards
---
Kuninori Morimoto

maintainer
#7 lore raw
In reply to Kuninori Morimoto
Quoted 3 lines · Kuninori Morimoto

asoc/for-6.15 branch includes my patch (419d1918105e) which uses __free(), but because of it, it has of_node_put() count underrun issue. [1/3] will solve it.

That's actually in Linus' tree isn't it?

author maintainer
#8 lore raw

Hi Mark

Quoted 5 lines
Quoted 3 lines

asoc/for-6.15 branch includes my patch (419d1918105e) which uses __free(), but because of it, it has of_node_put() count underrun issue. [1/3] will solve it.

That's actually in Linus' tree isn't it?

Oops, yes, indeed.

[1/3] is needed to linus/master
[2/3] is just cleaup, can be asoc/for-6.15 ?

I will repost [1/3][2/3] as v2

Thank you for your help !!

Best regards
---
Kuninori Morimoto