interconnect: qcom: Fix icc_onecell_data allocation
authorLeonard Crestez <leonard.crestez@nxp.com>
Tue, 24 Sep 2019 18:01:15 +0000 (21:01 +0300)
committerGeorgi Djakov <georgi.djakov@linaro.org>
Sun, 20 Oct 2019 09:09:31 +0000 (12:09 +0300)
This is a struct with a trailing zero-length array of icc_node pointers
but it's allocated as if it were a single array of icc_nodes instead.

This allocates too much memory at probe time but shouldn't have any
noticeable effect. Both sdm845 and qcs404 are affected.

Fix by replacing kcalloc with kzalloc and using the "struct_size" macro.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Fixes: 5e4e6c4d3ae0 ("interconnect: qcom: Add QCS404 interconnect provider driver")
Link: https://lore.kernel.org/linux-pm/a7360abb6561917e30bbfaa6084578449152bf1d.1569348056.git.leonard.crestez@nxp.com/
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
drivers/interconnect/qcom/qcs404.c
drivers/interconnect/qcom/sdm845.c

index 910081d6ddc00e59a9c8bd4c4e180cdba9d791d0..b4966d8f3348d269e90f2c69f69d167ba613f905 100644 (file)
@@ -433,7 +433,8 @@ static int qnoc_probe(struct platform_device *pdev)
        if (!qp)
                return -ENOMEM;
 
-       data = devm_kcalloc(dev, num_nodes, sizeof(*node), GFP_KERNEL);
+       data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes),
+                           GFP_KERNEL);
        if (!data)
                return -ENOMEM;
 
index 57955596bb5967ec8a7477cd38caa0b4d744acba..502a6c22b41eea9ded02b65a51b68aa028a78ca6 100644 (file)
@@ -790,7 +790,8 @@ static int qnoc_probe(struct platform_device *pdev)
        if (!qp)
                return -ENOMEM;
 
-       data = devm_kcalloc(&pdev->dev, num_nodes, sizeof(*node), GFP_KERNEL);
+       data = devm_kzalloc(&pdev->dev, struct_size(data, nodes, num_nodes),
+                           GFP_KERNEL);
        if (!data)
                return -ENOMEM;