Skip to content

Commit 8cdabfd

Browse files
paliLorenzo Pieralisi
authored andcommitted
PCI: mvebu: Check for valid ports
Some mvebu ports do not have to be initialized. So skip these uninitialized mvebu ports in every port iteration function to prevent access to unmapped memory or dereferencing NULL pointers. Uninitialized mvebu port has base address set to NULL. Link: https://lore.kernel.org/r/20211125124605.25915-2-pali@kernel.org Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1 parent 600b790 commit 8cdabfd

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/pci/controller/pci-mvebu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie,
606606
for (i = 0; i < pcie->nports; i++) {
607607
struct mvebu_pcie_port *port = &pcie->ports[i];
608608

609+
if (!port->base)
610+
continue;
611+
609612
if (bus->number == 0 && port->devfn == devfn)
610613
return port;
611614
if (bus->number != 0 &&
@@ -781,6 +784,8 @@ static int mvebu_pcie_suspend(struct device *dev)
781784
pcie = dev_get_drvdata(dev);
782785
for (i = 0; i < pcie->nports; i++) {
783786
struct mvebu_pcie_port *port = pcie->ports + i;
787+
if (!port->base)
788+
continue;
784789
port->saved_pcie_stat = mvebu_readl(port, PCIE_STAT_OFF);
785790
}
786791

@@ -795,6 +800,8 @@ static int mvebu_pcie_resume(struct device *dev)
795800
pcie = dev_get_drvdata(dev);
796801
for (i = 0; i < pcie->nports; i++) {
797802
struct mvebu_pcie_port *port = pcie->ports + i;
803+
if (!port->base)
804+
continue;
798805
mvebu_writel(port, port->saved_pcie_stat, PCIE_STAT_OFF);
799806
mvebu_pcie_setup_hw(port);
800807
}

0 commit comments

Comments
 (0)