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[] = { ...@@ -769,13 +769,14 @@ static const struct sof_topology_token led_tokens[] = {
get_token_u32, offsetof(struct snd_sof_led_control, direction), 0}, 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, void *object,
const struct sof_topology_token *tokens, const struct sof_topology_token *tokens,
int count, int count,
struct snd_soc_tplg_vendor_array *array) struct snd_soc_tplg_vendor_array *array)
{ {
struct snd_soc_tplg_vendor_uuid_elem *elem; struct snd_soc_tplg_vendor_uuid_elem *elem;
int found = 0;
int i, j; int i, j;
/* parse element by element */ /* parse element by element */
...@@ -795,17 +796,22 @@ static void sof_parse_uuid_tokens(struct snd_soc_component *scomp, ...@@ -795,17 +796,22 @@ static void sof_parse_uuid_tokens(struct snd_soc_component *scomp,
/* matched - now load token */ /* matched - now load token */
tokens[j].get_token(elem, object, tokens[j].offset, tokens[j].get_token(elem, object, tokens[j].offset,
tokens[j].size); 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, void *object,
const struct sof_topology_token *tokens, const struct sof_topology_token *tokens,
int count, int count,
struct snd_soc_tplg_vendor_array *array) struct snd_soc_tplg_vendor_array *array)
{ {
struct snd_soc_tplg_vendor_string_elem *elem; struct snd_soc_tplg_vendor_string_elem *elem;
int found = 0;
int i, j; int i, j;
/* parse element by element */ /* parse element by element */
...@@ -825,19 +831,24 @@ static void sof_parse_string_tokens(struct snd_soc_component *scomp, ...@@ -825,19 +831,24 @@ static void sof_parse_string_tokens(struct snd_soc_component *scomp,
/* matched - now load token */ /* matched - now load token */
tokens[j].get_token(elem, object, tokens[j].offset, tokens[j].get_token(elem, object, tokens[j].offset,
tokens[j].size); 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, void *object,
const struct sof_topology_token *tokens, const struct sof_topology_token *tokens,
int count, int count,
struct snd_soc_tplg_vendor_array *array) struct snd_soc_tplg_vendor_array *array)
{ {
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
struct snd_soc_tplg_vendor_value_elem *elem; struct snd_soc_tplg_vendor_value_elem *elem;
size_t size = sizeof(struct sof_ipc_dai_dmic_pdm_ctrl); size_t size = sizeof(struct sof_ipc_dai_dmic_pdm_ctrl);
int found = 0;
int i, j; int i, j;
u32 offset; u32 offset;
u32 *index = NULL; u32 *index = NULL;
...@@ -897,8 +908,12 @@ static void sof_parse_word_tokens(struct snd_soc_component *scomp, ...@@ -897,8 +908,12 @@ static void sof_parse_word_tokens(struct snd_soc_component *scomp,
tokens[j].get_token(elem, object, tokens[j].get_token(elem, object,
offset + tokens[j].offset, offset + tokens[j].offset,
tokens[j].size); tokens[j].size);
found++;
} }
} }
return found;
} }
static int sof_parse_tokens(struct snd_soc_component *scomp, static int sof_parse_tokens(struct snd_soc_component *scomp,
...@@ -908,9 +923,10 @@ 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, struct snd_soc_tplg_vendor_array *array,
int priv_size) int priv_size)
{ {
int found = 0;
int asize; int asize;
while (priv_size > 0) { while (priv_size > 0 && found < count) {
asize = le32_to_cpu(array->size); asize = le32_to_cpu(array->size);
/* validate asize */ /* validate asize */
...@@ -931,19 +947,19 @@ static int sof_parse_tokens(struct snd_soc_component *scomp, ...@@ -931,19 +947,19 @@ static int sof_parse_tokens(struct snd_soc_component *scomp,
/* call correct parser depending on type */ /* call correct parser depending on type */
switch (le32_to_cpu(array->type)) { switch (le32_to_cpu(array->type)) {
case SND_SOC_TPLG_TUPLE_TYPE_UUID: case SND_SOC_TPLG_TUPLE_TYPE_UUID:
sof_parse_uuid_tokens(scomp, object, tokens, count, found += sof_parse_uuid_tokens(scomp, object, tokens,
array); count, array);
break; break;
case SND_SOC_TPLG_TUPLE_TYPE_STRING: case SND_SOC_TPLG_TUPLE_TYPE_STRING:
sof_parse_string_tokens(scomp, object, tokens, count, found += sof_parse_string_tokens(scomp, object, tokens,
array); count, array);
break; break;
case SND_SOC_TPLG_TUPLE_TYPE_BOOL: case SND_SOC_TPLG_TUPLE_TYPE_BOOL:
case SND_SOC_TPLG_TUPLE_TYPE_BYTE: case SND_SOC_TPLG_TUPLE_TYPE_BYTE:
case SND_SOC_TPLG_TUPLE_TYPE_WORD: case SND_SOC_TPLG_TUPLE_TYPE_WORD:
case SND_SOC_TPLG_TUPLE_TYPE_SHORT: case SND_SOC_TPLG_TUPLE_TYPE_SHORT:
sof_parse_word_tokens(scomp, object, tokens, count, found += sof_parse_word_tokens(scomp, object, tokens,
array); count, array);
break; break;
default: default:
dev_err(scomp->dev, "error: unknown token type %d\n", 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