bcm53xx: use upstream fix for PCI iproc driver regression
[openwrt/staging/mkresin.git] / target / linux / bcm53xx / patches-4.14 / 089-PCI-iproc-Fix-NULL-pointer-dereference-for-BCMA.patch
1 From 3b65ca50d24ce33cb92d88840e289135c92b40ed Mon Sep 17 00:00:00 2001
2 From: Ray Jui <ray.jui@broadcom.com>
3 Date: Thu, 11 Jan 2018 12:36:16 -0800
4 Subject: [PATCH] PCI: iproc: Fix NULL pointer dereference for BCMA
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 With the inbound DMA mapping supported added, the iProc PCIe driver
10 parses DT property "dma-ranges" through call to
11 "of_pci_dma_range_parser_init()". In the case of BCMA, this results in a
12 NULL pointer deference due to a missing of_node.
13
14 Fix this by adding a guard in pcie-iproc-platform.c to only enable the
15 inbound DMA mapping logic when DT property "dma-ranges" is present.
16
17 Fixes: dd9d4e7498de3 ("PCI: iproc: Add inbound DMA mapping support")
18 Reported-by: Rafał Miłecki <rafal@milecki.pl>
19 Signed-off-by: Ray Jui <ray.jui@broadcom.com>
20 [lorenzo.pieralisi@arm.com: updated commit log]
21 Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
22 Tested-by: Rafał Miłecki <rafal@milecki.pl>
23 cc: <stable@vger.kernel.org> # 4.10+
24 ---
25 drivers/pci/host/pcie-iproc-platform.c | 7 +++++++
26 drivers/pci/host/pcie-iproc.c | 8 +++++---
27 drivers/pci/host/pcie-iproc.h | 2 ++
28 3 files changed, 14 insertions(+), 3 deletions(-)
29
30 --- a/drivers/pci/host/pcie-iproc-platform.c
31 +++ b/drivers/pci/host/pcie-iproc-platform.c
32 @@ -92,6 +92,13 @@ static int iproc_pcie_pltfm_probe(struct
33 pcie->need_ob_cfg = true;
34 }
35
36 + /*
37 + * DT nodes are not used by all platforms that use the iProc PCIe
38 + * core driver. For platforms that require explict inbound mapping
39 + * configuration, "dma-ranges" would have been present in DT
40 + */
41 + pcie->need_ib_cfg = of_property_read_bool(np, "dma-ranges");
42 +
43 /* PHY use is optional */
44 pcie->phy = devm_phy_get(dev, "pcie-phy");
45 if (IS_ERR(pcie->phy)) {
46 --- a/drivers/pci/host/pcie-iproc.c
47 +++ b/drivers/pci/host/pcie-iproc.c
48 @@ -1396,9 +1396,11 @@ int iproc_pcie_setup(struct iproc_pcie *
49 }
50 }
51
52 - ret = iproc_pcie_map_dma_ranges(pcie);
53 - if (ret && ret != -ENOENT)
54 - goto err_power_off_phy;
55 + if (pcie->need_ib_cfg) {
56 + ret = iproc_pcie_map_dma_ranges(pcie);
57 + if (ret && ret != -ENOENT)
58 + goto err_power_off_phy;
59 + }
60
61 #ifdef CONFIG_ARM
62 pcie->sysdata.private_data = pcie;
63 --- a/drivers/pci/host/pcie-iproc.h
64 +++ b/drivers/pci/host/pcie-iproc.h
65 @@ -74,6 +74,7 @@ struct iproc_msi;
66 * @ob: outbound mapping related parameters
67 * @ob_map: outbound mapping related parameters specific to the controller
68 *
69 + * @need_ib_cfg: indicates SW needs to configure the inbound mapping window
70 * @ib: inbound mapping related parameters
71 * @ib_map: outbound mapping region related parameters
72 *
73 @@ -101,6 +102,7 @@ struct iproc_pcie {
74 struct iproc_pcie_ob ob;
75 const struct iproc_pcie_ob_map *ob_map;
76
77 + bool need_ib_cfg;
78 struct iproc_pcie_ib ib;
79 const struct iproc_pcie_ib_map *ib_map;
80