diff mbox series

[02/11] ASoC: soc-dapm.c: tidyup error handling on snd_soc_dapm_add_route()

Message ID 87zgduowe5.wl-kuninori.morimoto.gx@renesas.com
State Accepted
Commit b913e9f4b313469dac7ae3083356baee3db4454f
Headers show
Series ASoC: soc-dapm.c random cleanups | expand

Commit Message

Kuninori Morimoto Oct. 17, 2022, 11:36 p.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current error handling on snd_soc_dapm_add_route() has some wastes.
It indicates *own* error message *only* for sink or source,
and return error directly at (A). OTOH, it has similar error message at
(B) which indicates *both* sink/source.

And more, (A) is using dev_err(), (B) is using dev_warn().
(B) is caring prefix, but (A) is not.

(X)	int snd_soc_dapm_add_route(...)
	{
		...
		if (wsource == NULL) {
(A)			dev_err(...);
			return -ENODEV;
		}
		if (wsink == NULL) {
(A)			dev_err(...);
			return -ENODEV;
		}

		...

		ret = snd_soc_dapm_add_path(...);
		if (ret)
(B)			goto err;

		return 0;
	err:
(B)		dev_warn(...);
		return ret;
	}

Above snd_soc_dapm_add_route() (= X) is called from
snd_soc_dapm_add_routes() (= Y).
(X) will indicate error message by itself, but (Y) will indicate
own error message at (C). (C) is duplicated.

(Y)	int snd_soc_dapm_add_routes(...)
	{
		...
		for (...) {
(X)			int r = snd_soc_dapm_add_route(...);
			if (r < 0) {
(C)				dev_err(...);
				ret = r;
			}
			...
		}
		...
	}

This patch (1) merges these error message (= A,B) into one,
(2) use dev_err(), (3) remove duplicate error message (= C) from
snd_soc_dapm_add_routes().

By this patch, it will indicate error message like this.

	- error message with prefix
	- not found widget will have "(*)" mark
	- it indicates [control] if exists.

ex)
[if no sink with control]

	ASoC: Failed to add route SOURCE -> [CTRL] -> SINK(*)

[if no source without control]

	ASoC: Failed to add route SOURCE(*) -> SINK

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-dapm.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 1796863bff1b..b4f876dff994 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2994,16 +2994,11 @@  static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
 	if (!wsource)
 		wsource = wtsource;
 
-	if (wsource == NULL) {
-		dev_err(dapm->dev, "ASoC: no source widget found for %s\n",
-			route->source);
-		return -ENODEV;
-	}
-	if (wsink == NULL) {
-		dev_err(dapm->dev, "ASoC: no sink widget found for %s\n",
-			route->sink);
-		return -ENODEV;
-	}
+	ret = -ENODEV;
+	if (!wsource)
+		goto err;
+	if (!wsink)
+		goto err;
 
 skip_search:
 	/* update cache */
@@ -3012,13 +3007,14 @@  static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
 
 	ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control,
 		route->connected);
-	if (ret)
-		goto err;
-
-	return 0;
 err:
-	dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n",
-		 source, route->control, sink);
+	if (ret)
+		dev_err(dapm->dev, "ASoC: Failed to add route %s%s -%s%s%s> %s%s\n",
+			source, !wsource ? "(*)" : "",
+			!route->control ? "" : "> [",
+			!route->control ? "" : route->control,
+			!route->control ? "" : "] -",
+			sink,  !wsink ? "(*)" : "");
 	return ret;
 }
 
@@ -3104,13 +3100,8 @@  int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
 	mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
 	for (i = 0; i < num; i++) {
 		int r = snd_soc_dapm_add_route(dapm, route);
-		if (r < 0) {
-			dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n",
-				route->source,
-				route->control ? route->control : "direct",
-				route->sink);
+		if (r < 0)
 			ret = r;
-		}
 		route++;
 	}
 	mutex_unlock(&dapm->card->dapm_mutex);