ASoC: soc-dapm.c: tidyup error handling on snd_soc_dapm_add_route()

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>
Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Link: https://lore.kernel.org/r/878rlctzt5.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2022-10-19 00:36:06 +00:00 committed by Mark Brown
parent 86b94c396b
commit f19a2ec7a3
No known key found for this signature in database
GPG key ID: 24D68B725D5487D0

View 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 @@ 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);