OSDN Git Service

ASoC: soc-dapm.c: tidyup error handling on snd_soc_dapm_add_route()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Mon, 17 Oct 2022 23:36:35 +0000 (23:36 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 18 Oct 2022 18:16:36 +0000 (19:16 +0100)
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>
Link: https://lore.kernel.org/r/87zgduowe5.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-dapm.c

index 1796863..b4f876d 100644 (file)
@@ -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 @@ skip_search:
 
        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);