diff mbox series

[v2] ASoC: soc-core: add snd_soc_dapm_add_routes_with_card()

Message ID 87ldvmknrz.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New
Headers show
Series [v2] ASoC: soc-core: add snd_soc_dapm_add_routes_with_card() | expand

Commit Message

Kuninori Morimoto Jan. 8, 2025, 3:06 a.m. UTC
Some device want to ignore snd_soc_dapm_add_routes() error, thus
card->disable_route_checks flags had been added for such purpose. Because
of this, ASoC has duplicate code for it. Let's adds new
snd_soc_dapm_add_routes_with_card(), and share the error message handling.

We don't need to indicate error message on this function, because it will
be indicated from snd_soc_dapm_add_route().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v1 -> v2
	- rebase to latest asoc/for-6.14

 include/sound/soc-dapm.h |  3 +++
 sound/soc/soc-core.c     | 33 ++++++---------------------------
 sound/soc/soc-dapm.c     | 15 +++++++++++++++
 sound/soc/soc-topology.c | 14 +++-----------
 4 files changed, 27 insertions(+), 38 deletions(-)

Comments

Amadeusz Sławiński Jan. 8, 2025, 8:44 a.m. UTC | #1
On 1/8/2025 4:06 AM, Kuninori Morimoto wrote:
> Some device want to ignore snd_soc_dapm_add_routes() error, thus
> card->disable_route_checks flags had been added for such purpose. Because
> of this, ASoC has duplicate code for it. Let's adds new
> snd_soc_dapm_add_routes_with_card(), and share the error message handling.
> 
> We don't need to indicate error message on this function, because it will
> be indicated from snd_soc_dapm_add_route().
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---

card->disable_route_checks is a leftover from skylake driver which had 
partial routes in some topologies, as skylake driver was removed, 
perhaps we can remove the field altogether?

Quick grep shows that there is only one board left which sets it:
sound/soc/intel/boards/skl_hda_dsp_generic.c: 
card->disable_route_checks = true;
and it only does it after checking that parent driver isn't SOF, and as 
skylake driver was removed it is dead code (it was shared between SOF 
and skylake drivers).

As such I would recommend removing whole thing altogether ;)
Kuninori Morimoto Jan. 8, 2025, 11:38 p.m. UTC | #2
Hi Amadeusz

> > Some device want to ignore snd_soc_dapm_add_routes() error, thus
> > card->disable_route_checks flags had been added for such purpose. Because
> > of this, ASoC has duplicate code for it. Let's adds new
> > snd_soc_dapm_add_routes_with_card(), and share the error message handling.
> > 
> > We don't need to indicate error message on this function, because it will
> > be indicated from snd_soc_dapm_add_route().
> > 
> > Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > ---
> 
> card->disable_route_checks is a leftover from skylake driver which had 
> partial routes in some topologies, as skylake driver was removed, 
> perhaps we can remove the field altogether?
> 
> Quick grep shows that there is only one board left which sets it:
> sound/soc/intel/boards/skl_hda_dsp_generic.c: 
> card->disable_route_checks = true;
> and it only does it after checking that parent driver isn't SOF, and as 
> skylake driver was removed it is dead code (it was shared between SOF 
> and skylake drivers).
> 
> As such I would recommend removing whole thing altogether ;)

Nice to know.
OK, let's remove it and clean code.

Thank you for your help !!

Best regards
---
Kuninori Morimoto
diff mbox series

Patch

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 12cd7b5a2202e..16f4a536cdf52 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -478,6 +478,9 @@  void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm,
 		       struct snd_soc_card *card, struct snd_soc_component *component);
 int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
 			    const struct snd_soc_dapm_route *route, int num);
+int snd_soc_dapm_add_routes_with_card(struct snd_soc_card *card,
+				      struct snd_soc_dapm_context *dapm,
+				      const struct snd_soc_dapm_route *routes, int num);
 int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
 			    const struct snd_soc_dapm_route *route, int num);
 int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 710c278e4f36b..01ce1c9366223 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1641,22 +1641,11 @@  static int soc_probe_component(struct snd_soc_card *card,
 	if (ret < 0)
 		goto err_probe;
 
-	ret = snd_soc_dapm_add_routes(dapm,
+	ret = snd_soc_dapm_add_routes_with_card(card, dapm,
 				      component->driver->dapm_routes,
 				      component->driver->num_dapm_routes);
-	if (ret < 0) {
-		if (card->disable_route_checks) {
-			ret = 0;
-			dev_info(card->dev,
-				 "%s: disable_route_checks set, ignoring errors on add_routes\n",
-				 __func__);
-		} else {
-			dev_err(card->dev,
-				"%s: snd_soc_dapm_add_routes failed: %d\n",
-				__func__, ret);
-			goto err_probe;
-		}
-	}
+	if (ret < 0)
+		goto err_probe;
 
 	/* see for_each_card_components */
 	list_add(&component->card_list, &card->component_dev_list);
@@ -2233,20 +2222,10 @@  static int snd_soc_bind_card(struct snd_soc_card *card)
 	if (ret < 0)
 		goto probe_end;
 
-	ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
+	ret = snd_soc_dapm_add_routes_with_card(card, &card->dapm, card->dapm_routes,
 				      card->num_dapm_routes);
-	if (ret < 0) {
-		if (card->disable_route_checks) {
-			dev_info(card->dev,
-				 "%s: disable_route_checks set, ignoring errors on add_routes\n",
-				 __func__);
-		} else {
-			dev_err(card->dev,
-				 "%s: snd_soc_dapm_add_routes failed: %d\n",
-				 __func__, ret);
-			goto probe_end;
-		}
-	}
+	if (ret < 0)
+		goto probe_end;
 
 	ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
 				      card->num_of_dapm_routes);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 99521c784a9b1..ea0c74f0df102 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3189,6 +3189,21 @@  int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
 
+int snd_soc_dapm_add_routes_with_card(struct snd_soc_card *card,
+				      struct snd_soc_dapm_context *dapm,
+				      const struct snd_soc_dapm_route *routes, int num)
+{
+	int ret = snd_soc_dapm_add_routes(dapm, routes, num);
+
+	if (ret < 0 && card->disable_route_checks) {
+		dev_info(card->dev, "disable_route_checks set, ignoring errors on add_routes\n");
+		ret = 0;
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes_with_card);
+
 /**
  * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
  * @dapm: DAPM context
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index ae2d6802cce05..37e7e1147c241 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -1100,17 +1100,9 @@  static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
 			break;
 		}
 
-		ret = snd_soc_dapm_add_routes(dapm, route, 1);
-		if (ret) {
-			if (dapm->card->disable_route_checks) {
-				ret = 0;
-				dev_info(tplg->dev,
-					 "ASoC: disable_route_checks set, ignoring dapm_add_routes errors\n");
-			} else {
-				dev_err(tplg->dev, "ASoC: dapm_add_routes failed: %d\n", ret);
-				break;
-			}
-		}
+		ret = snd_soc_dapm_add_routes_with_card(dapm->card, dapm, route, 1);
+		if (ret)
+			break;
 	}
 
 	return ret;