MLK-18559 PCI: imx: fix crash when request reserved region
authorRichard Zhu <hongxing.zhu@nxp.com>
Mon, 14 Jan 2019 12:24:37 +0000 (17:54 +0530)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Fix the crash when pcie request the reserved memory region
after the -EPROBE_DEFER in the probe.
The pointer of the resource parameter would be invalided
in the second probe. Use one structure varible to replace
it.
Put node after done with it, after call of_parse_phandle.

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
rebase on v4.19
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
drivers/pci/controller/dwc/pci-imx6.c

index 6465c8c..ba212a5 100644 (file)
@@ -2159,7 +2159,7 @@ static int __init imx_pcie_probe(struct platform_device *pdev)
        struct device *dev = &pdev->dev;
        struct dw_pcie *pci;
        struct imx_pcie *imx_pcie;
-       struct resource *res;
+       struct resource *res, reserved_res;
        struct device_node *reserved_node, *node = dev->of_node;
        int ret;
        u16 val;
@@ -2215,11 +2215,13 @@ static int __init imx_pcie_probe(struct platform_device *pdev)
        if (!reserved_node) {
                dev_info(dev, "no reserved region node.\n");
        } else {
-               if (of_address_to_resource(reserved_node, 0, res)) {
+               if (of_address_to_resource(reserved_node, 0, &reserved_res)) {
                        dev_err(dev, "failed to get reserved region address\n");
+                       of_node_put(reserved_node);
                        return -EINVAL;
                }
-               ddr_test_region = res->start + SZ_2M;
+               ddr_test_region = reserved_res.start + SZ_2M;
+               of_node_put(reserved_node);
        }
 
        /* Fetch GPIOs */