Skip to contentSkip to conversation

PCI: iproc: Fix NULL pointer dereference for BCMA

PATCH Superseded Ray Jui 2 participants 3 messages Jan 9, 2018 – Jan 11, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ray Jui

author
#0 lore raw

PATCH 1/1 PCI: iproc: Fix NULL pointer dereference for BCMA

With the inbound DMA mapping supported added, the iProc PCIe driver parses DT property "dma-ranges" through call to "of_pci_dma_range_parser_init". In the case of BCMA, this results in a NULL pointer deference due to a missing of_node.

Fix this by adding a guard in pcie-iproc-platform.c to only enable the inbound DMA mapping logic when DT property "dma-ranges" is present

Fixes dd9d4e7498de3 ("PCI: iproc: Add inbound DMA mapping support")
Cc <[email protected]> # 4.10+
---
 drivers/pci/host/pcie-iproc-platform.c | 3 +++
 drivers/pci/host/pcie-iproc.c          | 8 +++++---
 drivers/pci/host/pcie-iproc.h          | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)
drivers/pci/host/pcie-iproc-platform.c +3 -0
index a5073a9..235c545 100644
@@ -92,6 +92,9 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 		pcie->need_ob_cfg = true;
 	}
 
+	if (of_property_read_bool(np, "dma-ranges"))
+		pcie->need_ib_cfg = true;
+
 	/* PHY use is optional */
 	pcie->phy = devm_phy_get(dev, "pcie-phy");
 	if (IS_ERR(pcie->phy)) {
drivers/pci/host/pcie-iproc.c +5 -3
index 935909b..7583606 100644
@@ -1378,9 +1378,11 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 		}
 	}
 
-	ret = iproc_pcie_map_dma_ranges(pcie);
-	if (ret && ret != -ENOENT)
-		goto err_power_off_phy;
+	if (pcie->need_ib_cfg) {
+		ret = iproc_pcie_map_dma_ranges(pcie);
+		if (ret && ret != -ENOENT)
+			goto err_power_off_phy;
+	}
 
 #ifdef CONFIG_ARM
 	pcie->sysdata.private_data = pcie;
drivers/pci/host/pcie-iproc.h +2 -0
index a6b55ce..4ac6282 100644
@@ -74,6 +74,7 @@ struct iproc_msi;
  * @ob: outbound mapping related parameters
  * @ob_map: outbound mapping related parameters specific to the controller
  *
+ * @need_ib_cfg: indicates SW needs to configure the inbound mapping window
  * @ib: inbound mapping related parameters
  * @ib_map: outbound mapping region related parameters
  *
@@ -101,6 +102,7 @@ struct iproc_pcie {
 	struct iproc_pcie_ob ob;
 	const struct iproc_pcie_ob_map *ob_map;
 
+	bool need_ib_cfg;
 	struct iproc_pcie_ib ib;
 	const struct iproc_pcie_ib_map *ib_map;
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 9 lines · Ray Jui

With the inbound DMA mapping supported added, the iProc PCIe driver parses DT property "dma-ranges" through call to "of_pci_dma_range_parser_init". In the case of BCMA, this results in a NULL pointer deference due to a missing of_node.

Fix this by adding a guard in pcie-iproc-platform.c to only enable the inbound DMA mapping logic when DT property "dma-ranges" is present

Fixes dd9d4e7498de3 ("PCI: iproc: Add inbound DMA mapping support")

s/fixes/Fixes

Quoted 15 lines
---
 drivers/pci/host/pcie-iproc-platform.c | 3 +++
 drivers/pci/host/pcie-iproc.c          | 8 +++++---
 drivers/pci/host/pcie-iproc.h          | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)
drivers/pci/host/pcie-iproc-platform.c +0 -0
index a5073a9..235c545 100644

drivers/pci/host/pcie-iproc-platform.c static int iproc_pcie_pltfm_probe(struct platform_device *pdev) · line 96

Quoted 5 lines
drivers/pci/host/pcie-iproc-platform.c +2 -0
@@ -92,6 +92,9 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 		pcie->need_ob_cfg = true;
 	}
 
+	if (of_property_read_bool(np, "dma-ranges"))
+		pcie->need_ib_cfg = true;

Nit:

	pci->need_ib_cfg = of_property_read_bool(np, "dma-ranges"));

will do. Add a comment to it to explain why it is needed.

Please update the patch, send a v2 and I will merge it.

Thanks,
Lorenzo

Quoted 46 lines
drivers/pci/host/pcie-iproc-platform.c +1 -0
+
 	/* PHY use is optional */
 	pcie->phy = devm_phy_get(dev, "pcie-phy");
 	if (IS_ERR(pcie->phy)) {
drivers/pci/host/pcie-iproc.c +5 -3
index 935909b..7583606 100644
@@ -1378,9 +1378,11 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 		}
 	}
 
-	ret = iproc_pcie_map_dma_ranges(pcie);
-	if (ret && ret != -ENOENT)
-		goto err_power_off_phy;
+	if (pcie->need_ib_cfg) {
+		ret = iproc_pcie_map_dma_ranges(pcie);
+		if (ret && ret != -ENOENT)
+			goto err_power_off_phy;
+	}
 
 #ifdef CONFIG_ARM
 	pcie->sysdata.private_data = pcie;
drivers/pci/host/pcie-iproc.h +2 -0
index a6b55ce..4ac6282 100644
@@ -74,6 +74,7 @@ struct iproc_msi;
  * @ob: outbound mapping related parameters
  * @ob_map: outbound mapping related parameters specific to the controller
  *
+ * @need_ib_cfg: indicates SW needs to configure the inbound mapping window
  * @ib: inbound mapping related parameters
  * @ib_map: outbound mapping region related parameters
  *
@@ -101,6 +102,7 @@ struct iproc_pcie {
 	struct iproc_pcie_ob ob;
 	const struct iproc_pcie_ob_map *ob_map;
 
+	bool need_ib_cfg;
 	struct iproc_pcie_ib ib;
 	const struct iproc_pcie_ib_map *ib_map;
 
Signature · 1 line
2.1.4
author
#2 lore raw

Hi Lorenzo,

Quoted 6 lines · Lorenzo Pieralisi
Quoted 5 lines · Ray Jui

With the inbound DMA mapping supported added, the iProc PCIe driver parses DT property "dma-ranges" through call to "of_pci_dma_range_parser_init". In the case of BCMA, this results in a NULL pointer deference due to a missing of_node.

Quoted 6 lines
Quoted 4 lines

Fix this by adding a guard in pcie-iproc-platform.c to only enable the inbound DMA mapping logic when DT property "dma-ranges" is present

Fixes dd9d4e7498de3 ("PCI: iproc: Add inbound DMA mapping support")

s/fixes/Fixes >

Will fix.

Quoted 18 lines
Quoted 18 lines
---
  drivers/pci/host/pcie-iproc-platform.c | 3 +++
  drivers/pci/host/pcie-iproc.c          | 8 +++++---
  drivers/pci/host/pcie-iproc.h          | 2 ++
  3 files changed, 10 insertions(+), 3 deletions(-)
drivers/pci/host/pcie-iproc-platform.c +0 -0
index a5073a9..235c545 100644
@@ -92,6 +92,9 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
  		pcie->need_ob_cfg = true;
  	}
 
Quoted 7 lines

drivers/pci/host/pcie-iproc-platform.c static int iproc_pcie_pltfm_probe(struct platform_device *pdev) · line 96

Quoted 2 lines
drivers/pci/host/pcie-iproc-platform.c +2 -0
+	if (of_property_read_bool(np, "dma-ranges"))
+		pcie->need_ib_cfg = true;

Nit:

	pci->need_ib_cfg = of_property_read_bool(np, "dma-ranges"));

will do. Add a comment to it to explain why it is needed.

Will fix.

Quoted 2 lines

Please update the patch, send a v2 and I will merge it.

Okay will send out v2 with comments from you addressed. Thanks!

Quoted 4 lines

Thanks,
Lorenzo