summaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-topology.c
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2021-01-21 19:13:27 +0100
committerMark Brown <broonie@kernel.org>2021-01-21 19:13:27 +0100
commitc7a83edf9d0869011c66befe83ec8f27689d0336 (patch)
treeb895c6e41cb2d5a80080b2a0cef6d48bb6245295 /sound/soc/soc-topology.c
parentMerge series "ASoC: sync parameter naming : rate / sample_bits" from Kuninori... (diff)
parentASoC: topology: Check if ops is set before dereference (diff)
downloadlinux-c7a83edf9d0869011c66befe83ec8f27689d0336.tar.xz
linux-c7a83edf9d0869011c66befe83ec8f27689d0336.zip
Merge series "Add sanity checks for topology API calls" from Amadeusz Sławiński<amadeuszx.slawinski@linux.intel.com>:
Topology API exposes just 2 function calls, to load and unload topology. This adds sanity checks to make sure that it behaves well when some of parameters are set incoorectly or not needed. This makes developer live easier by failing early instead of proceeding on and then failing in unexpected ways. As loading and unloading topology usually happens one the overhead of additional checks should be negligible. Amadeusz Sławiński (2): ASoC: topology: Ensure that needed parameters are set ASoC: topology: Check if ops is set before dereference sound/soc/soc-topology.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) -- 2.25.1
Diffstat (limited to 'sound/soc/soc-topology.c')
-rw-r--r--sound/soc/soc-topology.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index 27f7dd8fb7f6..7a75ca77d3e7 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -2659,8 +2659,14 @@ int snd_soc_tplg_component_load(struct snd_soc_component *comp,
struct soc_tplg tplg;
int ret;
- /* component needs to exist to keep and reference data while parsing */
- if (!comp)
+ /*
+ * check if we have sane parameters:
+ * comp - needs to exist to keep and reference data while parsing
+ * comp->dev - used for resource management and prints
+ * comp->card - used for setting card related parameters
+ * fw - we need it, as it is the very thing we parse
+ */
+ if (!comp || !comp->dev || !comp->card || !fw)
return -EINVAL;
/* setup parsing context */
@@ -2668,11 +2674,13 @@ int snd_soc_tplg_component_load(struct snd_soc_component *comp,
tplg.fw = fw;
tplg.dev = comp->dev;
tplg.comp = comp;
- tplg.ops = ops;
- tplg.io_ops = ops->io_ops;
- tplg.io_ops_count = ops->io_ops_count;
- tplg.bytes_ext_ops = ops->bytes_ext_ops;
- tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count;
+ if (ops) {
+ tplg.ops = ops;
+ tplg.io_ops = ops->io_ops;
+ tplg.io_ops_count = ops->io_ops_count;
+ tplg.bytes_ext_ops = ops->bytes_ext_ops;
+ tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count;
+ }
ret = soc_tplg_load(&tplg);
/* free the created components if fail to load topology */