linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: rockchip: Fix bus checks in rockchip_pcie_valid_device()
@ 2020-09-04 14:09 Lorenzo Pieralisi
  2020-09-04 18:54 ` Rob Herring
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Lorenzo Pieralisi @ 2020-09-04 14:09 UTC (permalink / raw)
  To: linux-pci
  Cc: Lorenzo Pieralisi, Samuel Dionne-Riel, Bjorn Helgaas,
	Rob Herring, Shawn Lin, linux-arm-kernel

The root bus checks rework in:

commit d84c572de1a3 ("PCI: rockchip: Use pci_is_root_bus() to check if bus is root bus")

caused a regression whereby in rockchip_pcie_valid_device() if
the bus parameter is the root bus and the dev value == 0 the
function should return 1 (ie true) without checking if the
bus->parent pointer is a root bus because that triggers a NULL
pointer dereference.

Fix this by streamlining the root bus detection.

Fixes: d84c572de1a3 ("PCI: rockchip: Use pci_is_root_bus() to check if bus is root bus")
Reported-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Shawn Lin <shawn.lin@rock-chips.com>
---
 drivers/pci/controller/pcie-rockchip-host.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 0bb2fb3e8a0b..9705059523a6 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -71,16 +71,13 @@ static void rockchip_pcie_update_txcredit_mui(struct rockchip_pcie *rockchip)
 static int rockchip_pcie_valid_device(struct rockchip_pcie *rockchip,
 				      struct pci_bus *bus, int dev)
 {
-	/* access only one slot on each root port */
-	if (pci_is_root_bus(bus) && dev > 0)
-		return 0;
-
 	/*
-	 * do not read more than one device on the bus directly attached
+	 * Access only one slot on each root port.
+	 * Do not read more than one device on the bus directly attached
 	 * to RC's downstream side.
 	 */
-	if (pci_is_root_bus(bus->parent) && dev > 0)
-		return 0;
+	if (pci_is_root_bus(bus) || pci_is_root_bus(bus->parent))
+		return dev == 0;
 
 	return 1;
 }
-- 
2.26.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-09 19:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04 14:09 [PATCH] PCI: rockchip: Fix bus checks in rockchip_pcie_valid_device() Lorenzo Pieralisi
2020-09-04 18:54 ` Rob Herring
2020-09-07 10:20 ` Lorenzo Pieralisi
2020-09-07 17:29   ` Samuel Dionne-Riel
2020-09-08 10:02 ` Lorenzo Pieralisi
2020-09-08 22:08   ` Bjorn Helgaas
2020-09-09 19:14     ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).