From d9712ef6711fbe2930c46ea36f0987bc2d292833 Mon Sep 17 00:00:00 2001 From: Mohana Datta Yelugoti Date: Fri, 14 Aug 2020 16:24:03 +0000 Subject: [PATCH] testbench: topology:check array size mismatch in filewrite component This patch uses the functionality added by the c9e090ccf37 commit to check for array size mismatch in components. Since, the components are in places other than tplg_parser, the function which checks for the mismatch has been made an external function from a static one. The function declaration has been added to the tplg_parser header files, so that the function can be used by any code which needs array size checks in components. Signed-off-by: Mohana Datta Yelugoti --- tools/testbench/topology.c | 6 ++++++ tools/tplg_parser/include/tplg_parser/topology.h | 2 ++ tools/tplg_parser/tplg_parser.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/testbench/topology.c b/tools/testbench/topology.c index c176c1dad..576cc2f02 100644 --- a/tools/testbench/topology.c +++ b/tools/testbench/topology.c @@ -240,6 +240,12 @@ static int tplg_load_filewrite(int comp_id, int pipeline_id, int size, return -EINVAL; } + if (!is_valid_priv_size(total_array_size, size, array)) { + fprintf(stderr, "error: filewrite array size mismatch\n"); + free(array); + return -EINVAL; + } + tplg_read_array(array, file); ret = sof_parse_tokens(&filewrite->config, comp_tokens, diff --git a/tools/tplg_parser/include/tplg_parser/topology.h b/tools/tplg_parser/include/tplg_parser/topology.h index 64fac8c7d..14abcd4ff 100644 --- a/tools/tplg_parser/include/tplg_parser/topology.h +++ b/tools/tplg_parser/include/tplg_parser/topology.h @@ -269,5 +269,7 @@ int load_widget(void *dev, int dev_type, struct comp_info *temp_comp_list, void register_comp(int comp_type); int find_widget(struct comp_info *temp_comp_list, int count, char *name); +bool is_valid_priv_size(size_t size_read, size_t priv_size, + struct snd_soc_tplg_vendor_array *array); #endif diff --git a/tools/tplg_parser/tplg_parser.c b/tools/tplg_parser/tplg_parser.c index f1cb0e8cc..c6279fe3b 100644 --- a/tools/tplg_parser/tplg_parser.c +++ b/tools/tplg_parser/tplg_parser.c @@ -61,7 +61,7 @@ static enum sof_comp_type find_process_comp_type(enum sof_ipc_process_type type) return SOF_COMP_NONE; } -static bool is_valid_priv_size(size_t size_read, size_t priv_size, +bool is_valid_priv_size(size_t size_read, size_t priv_size, struct snd_soc_tplg_vendor_array *array) { size_t arr_size, elem_size, arr_elems_size;