ASoC: qcom: common: Fix NULL pointer in of parser
authorBjorn Andersson <bjorn.andersson@linaro.org>
Tue, 18 Jun 2019 05:28:13 +0000 (22:28 -0700)
committerMark Brown <broonie@kernel.org>
Wed, 19 Jun 2019 11:04:24 +0000 (12:04 +0100)
A snd_soc_dai_link_component is allocated and associated with the first
link, so when the code tries to assign the of_node of the second link's
"cpu" member it dereferences a NULL pointer.

Fix this by moving the allocation and assignement of
snd_soc_dai_link_components into the loop, giving us one pair per link.

Fixes: 1e36ea360ab9 ("ASoC: qcom: common: use modern dai_link style")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/common.c

index c7a878507220b36e7753cb5223cfc9e08f0787fc..97488b5cc5157a5ba9a1c3f3fcf77803e9b9f5b0 100644 (file)
@@ -42,17 +42,17 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
        card->num_links = num_links;
        link = card->dai_link;
 
-       dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
-       if (!dlc)
-               return -ENOMEM;
+       for_each_child_of_node(dev->of_node, np) {
+               dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
+               if (!dlc)
+                       return -ENOMEM;
 
-       link->cpus      = &dlc[0];
-       link->platforms = &dlc[1];
+               link->cpus      = &dlc[0];
+               link->platforms = &dlc[1];
 
-       link->num_cpus          = 1;
-       link->num_platforms     = 1;
+               link->num_cpus          = 1;
+               link->num_platforms     = 1;
 
-       for_each_child_of_node(dev->of_node, np) {
                cpu = of_get_child_by_name(np, "cpu");
                platform = of_get_child_by_name(np, "platform");
                codec = of_get_child_by_name(np, "codec");