Skip to content

Commit e0e7bc2

Browse files
Amadeusz Sławińskibroonie
authored andcommitted
ASoC: topology: Clean up route loading
Instead of using very long macro name, assign it to shorter variable and use it instead. While doing that, we can reduce multiple if checks using this define to one. Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com> Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com> Link: https://lore.kernel.org/r/20240603102818.36165-5-amadeuszx.slawinski@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent daf0b99 commit e0e7bc2

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

sound/soc/soc-topology.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
10211021
struct snd_soc_tplg_hdr *hdr)
10221022
{
10231023
struct snd_soc_dapm_context *dapm = &tplg->comp->dapm;
1024+
const size_t maxlen = SNDRV_CTL_ELEM_ID_NAME_MAXLEN;
10241025
struct snd_soc_tplg_dapm_graph_elem *elem;
10251026
struct snd_soc_dapm_route *route;
10261027
int count, i;
@@ -1044,38 +1045,27 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
10441045
tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem);
10451046

10461047
/* validate routes */
1047-
if (strnlen(elem->source, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1048-
SNDRV_CTL_ELEM_ID_NAME_MAXLEN) {
1049-
ret = -EINVAL;
1050-
break;
1051-
}
1052-
if (strnlen(elem->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1053-
SNDRV_CTL_ELEM_ID_NAME_MAXLEN) {
1054-
ret = -EINVAL;
1055-
break;
1056-
}
1057-
if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1058-
SNDRV_CTL_ELEM_ID_NAME_MAXLEN) {
1048+
if ((strnlen(elem->source, maxlen) == maxlen) ||
1049+
(strnlen(elem->sink, maxlen) == maxlen) ||
1050+
(strnlen(elem->control, maxlen) == maxlen)) {
10591051
ret = -EINVAL;
10601052
break;
10611053
}
10621054

10631055
route->source = devm_kmemdup(tplg->dev, elem->source,
1064-
min(strlen(elem->source),
1065-
SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
1056+
min(strlen(elem->source), maxlen),
10661057
GFP_KERNEL);
10671058
route->sink = devm_kmemdup(tplg->dev, elem->sink,
1068-
min(strlen(elem->sink), SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
1059+
min(strlen(elem->sink), maxlen),
10691060
GFP_KERNEL);
10701061
if (!route->source || !route->sink) {
10711062
ret = -ENOMEM;
10721063
break;
10731064
}
10741065

1075-
if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) != 0) {
1066+
if (strnlen(elem->control, maxlen) != 0) {
10761067
route->control = devm_kmemdup(tplg->dev, elem->control,
1077-
min(strlen(elem->control),
1078-
SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
1068+
min(strlen(elem->control), maxlen),
10791069
GFP_KERNEL);
10801070
if (!route->control) {
10811071
ret = -ENOMEM;

0 commit comments

Comments
 (0)