Skip to content

Commit 6e347b5

Browse files
committed
PCI: iproc: Save host bridge window resource in struct iproc_pcie
The host bridge memory window resource is inserted into the iomem_resource tree and cannot be deallocated until the host bridge itself is removed. Previously, the window was on the stack, which meant the iomem_resource entry pointed into the stack and was corrupted as soon as the probe function returned, which caused memory corruption and errors like this: pcie_iproc_bcma bcma0:8: resource collision: [mem 0x40000000-0x47ffffff] conflicts with PCIe MEM space [mem 0x40000000-0x47ffffff] Move the memory window resource from the stack into struct iproc_pcie so its lifetime matches that of the host bridge. Fixes: c3245a5 ("PCI: iproc: Request host bridge window resources") Reported-and-tested-by: Rafał Miłecki <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> CC: [email protected] # v4.8+
1 parent 3bd7db6 commit 6e347b5

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

drivers/pci/host/pcie-iproc-bcma.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
4444
{
4545
struct device *dev = &bdev->dev;
4646
struct iproc_pcie *pcie;
47-
LIST_HEAD(res);
48-
struct resource res_mem;
47+
LIST_HEAD(resources);
4948
int ret;
5049

5150
pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
@@ -63,22 +62,23 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
6362

6463
pcie->base_addr = bdev->addr;
6564

66-
res_mem.start = bdev->addr_s[0];
67-
res_mem.end = bdev->addr_s[0] + SZ_128M - 1;
68-
res_mem.name = "PCIe MEM space";
69-
res_mem.flags = IORESOURCE_MEM;
70-
pci_add_resource(&res, &res_mem);
65+
pcie->mem.start = bdev->addr_s[0];
66+
pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1;
67+
pcie->mem.name = "PCIe MEM space";
68+
pcie->mem.flags = IORESOURCE_MEM;
69+
pci_add_resource(&resources, &pcie->mem);
7170

7271
pcie->map_irq = iproc_pcie_bcma_map_irq;
7372

74-
ret = iproc_pcie_setup(pcie, &res);
75-
if (ret)
73+
ret = iproc_pcie_setup(pcie, &resources);
74+
if (ret) {
7675
dev_err(dev, "PCIe controller setup failed\n");
77-
78-
pci_free_resource_list(&res);
76+
pci_free_resource_list(&resources);
77+
return ret;
78+
}
7979

8080
bcma_set_drvdata(bdev, pcie);
81-
return ret;
81+
return 0;
8282
}
8383

8484
static void iproc_pcie_bcma_remove(struct bcma_device *bdev)

drivers/pci/host/pcie-iproc-platform.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
5151
struct device_node *np = dev->of_node;
5252
struct resource reg;
5353
resource_size_t iobase = 0;
54-
LIST_HEAD(res);
54+
LIST_HEAD(resources);
5555
int ret;
5656

5757
pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
@@ -96,10 +96,10 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
9696
pcie->phy = NULL;
9797
}
9898

99-
ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase);
99+
ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &resources,
100+
&iobase);
100101
if (ret) {
101-
dev_err(dev,
102-
"unable to get PCI host bridge resources\n");
102+
dev_err(dev, "unable to get PCI host bridge resources\n");
103103
return ret;
104104
}
105105

@@ -112,14 +112,15 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
112112
pcie->map_irq = of_irq_parse_and_map_pci;
113113
}
114114

115-
ret = iproc_pcie_setup(pcie, &res);
116-
if (ret)
115+
ret = iproc_pcie_setup(pcie, &resources);
116+
if (ret) {
117117
dev_err(dev, "PCIe controller setup failed\n");
118-
119-
pci_free_resource_list(&res);
118+
pci_free_resource_list(&resources);
119+
return ret;
120+
}
120121

121122
platform_set_drvdata(pdev, pcie);
122-
return ret;
123+
return 0;
123124
}
124125

125126
static int iproc_pcie_pltfm_remove(struct platform_device *pdev)

drivers/pci/host/pcie-iproc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct iproc_pcie {
9090
#ifdef CONFIG_ARM
9191
struct pci_sys_data sysdata;
9292
#endif
93+
struct resource mem;
9394
struct pci_bus *root_bus;
9495
struct phy *phy;
9596
int (*map_irq)(const struct pci_dev *, u8, u8);

0 commit comments

Comments
 (0)