Skip to content

Commit

Permalink
PCI: rockchip: Fix bus checks in rockchip_pcie_valid_device()
Browse files Browse the repository at this point in the history
The root bus checks rework in d84c572 ("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: d84c572 ("PCI: rockchip: Use pci_is_root_bus() to check if bus is root bus")
Link: https://lore.kernel.org/r/20200904140904.944-1-lorenzo.pieralisi@arm.com
Reported-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
Tested-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Cc: Shawn Lin <shawn.lin@rock-chips.com>
  • Loading branch information
Lorenzo Pieralisi authored and Bjorn Helgaas committed Sep 8, 2020
1 parent 7c2308f commit e338eec
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions drivers/pci/controller/pcie-rockchip-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e338eec

Please sign in to comment.