Commit f228a5b1 authored by Jaska Uimonen's avatar Jaska Uimonen Committed by Mark Brown

ASoC: SOF: topology: stop parsing when all tokens have been found

Optimize the parsing so that it will stop after all required tokens
have been found as there is no reason to continue after that.
Signed-off-by: default avatarJaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Reviewed-by: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20200415202816.934-24-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 18aaab64
......@@ -769,13 +769,14 @@ static const struct sof_topology_token led_tokens[] = {
get_token_u32, offsetof(struct snd_sof_led_control, direction), 0},
};
static void sof_parse_uuid_tokens(struct snd_soc_component *scomp,
static int sof_parse_uuid_tokens(struct snd_soc_component *scomp,
void *object,
const struct sof_topology_token *tokens,
int count,
struct snd_soc_tplg_vendor_array *array)
{
struct snd_soc_tplg_vendor_uuid_elem *elem;
int found = 0;
int i, j;
/* parse element by element */
......@@ -795,17 +796,22 @@ static void sof_parse_uuid_tokens(struct snd_soc_component *scomp,
/* matched - now load token */
tokens[j].get_token(elem, object, tokens[j].offset,
tokens[j].size);
found++;
}
}
return found;
}
static void sof_parse_string_tokens(struct snd_soc_component *scomp,
static int sof_parse_string_tokens(struct snd_soc_component *scomp,
void *object,
const struct sof_topology_token *tokens,
int count,
struct snd_soc_tplg_vendor_array *array)
{
struct snd_soc_tplg_vendor_string_elem *elem;
int found = 0;
int i, j;
/* parse element by element */
......@@ -825,11 +831,15 @@ static void sof_parse_string_tokens(struct snd_soc_component *scomp,
/* matched - now load token */
tokens[j].get_token(elem, object, tokens[j].offset,
tokens[j].size);
found++;
}
}
return found;
}
static void sof_parse_word_tokens(struct snd_soc_component *scomp,
static int sof_parse_word_tokens(struct snd_soc_component *scomp,
void *object,
const struct sof_topology_token *tokens,
int count,
......@@ -838,6 +848,7 @@ static void sof_parse_word_tokens(struct snd_soc_component *scomp,
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
struct snd_soc_tplg_vendor_value_elem *elem;
size_t size = sizeof(struct sof_ipc_dai_dmic_pdm_ctrl);
int found = 0;
int i, j;
u32 offset;
u32 *index = NULL;
......@@ -897,8 +908,12 @@ static void sof_parse_word_tokens(struct snd_soc_component *scomp,
tokens[j].get_token(elem, object,
offset + tokens[j].offset,
tokens[j].size);
found++;
}
}
return found;
}
static int sof_parse_tokens(struct snd_soc_component *scomp,
......@@ -908,9 +923,10 @@ static int sof_parse_tokens(struct snd_soc_component *scomp,
struct snd_soc_tplg_vendor_array *array,
int priv_size)
{
int found = 0;
int asize;
while (priv_size > 0) {
while (priv_size > 0 && found < count) {
asize = le32_to_cpu(array->size);
/* validate asize */
......@@ -931,19 +947,19 @@ static int sof_parse_tokens(struct snd_soc_component *scomp,
/* call correct parser depending on type */
switch (le32_to_cpu(array->type)) {
case SND_SOC_TPLG_TUPLE_TYPE_UUID:
sof_parse_uuid_tokens(scomp, object, tokens, count,
array);
found += sof_parse_uuid_tokens(scomp, object, tokens,
count, array);
break;
case SND_SOC_TPLG_TUPLE_TYPE_STRING:
sof_parse_string_tokens(scomp, object, tokens, count,
array);
found += sof_parse_string_tokens(scomp, object, tokens,
count, array);
break;
case SND_SOC_TPLG_TUPLE_TYPE_BOOL:
case SND_SOC_TPLG_TUPLE_TYPE_BYTE:
case SND_SOC_TPLG_TUPLE_TYPE_WORD:
case SND_SOC_TPLG_TUPLE_TYPE_SHORT:
sof_parse_word_tokens(scomp, object, tokens, count,
array);
found += sof_parse_word_tokens(scomp, object, tokens,
count, array);
break;
default:
dev_err(scomp->dev, "error: unknown token type %d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment