Skip to contentSkip to conversation

PCI: of_property: Omit 'bus-range' property if no secondary bus

PATCH In review Bo Sun 2 participants 2 messages Feb 24 – Apr 29

Subsystems (2)
lore
Share & tools
lore

Bo Sun

author
#0 lore raw

PATCH 1/1 PCI: of_property: Omit 'bus-range' property if no secondary bus

The previous implementation of of_pci_add_properties() and of_pci_prop_bus_range() assumed that a valid secondary bus is always present, which can be problematic in cases where no bus numbers are assigned for a secondary bus. This patch introduces a check for a valid secondary bus and omits the 'bus-range' property if it is not available, preventing dereferencing the NULL pointer.

Fixes 407d1a51921e ("PCI: Create device tree node for bridge")
---
 drivers/pci/of_property.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/of_property.c +3 -0
index 75a358f73e69..cade01ea6e68 100644
@@ -95,6 +95,9 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
 				 struct of_changeset *ocs,
 				 struct device_node *np)
 {
+	if (!pdev->subordinate)
+		return -EINVAL;
+
 	u32 bus_range[] = { pdev->subordinate->busn_res.start,
 			    pdev->subordinate->busn_res.end };
 
#1 lore raw
Quoted 4 lines · Bo Sun

The previous implementation of of_pci_add_properties() and of_pci_prop_bus_range() assumed that a valid secondary bus is always present, which can be problematic in cases where no bus numbers are assigned for a secondary bus. This patch introduces a check for a valid

Imperative tone, please.

Quoted 16 lines

secondary bus and omits the 'bus-range' property if it is not available, preventing dereferencing the NULL pointer.

Fixes 407d1a51921e ("PCI: Create device tree node for bridge")
---
 drivers/pci/of_property.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/of_property.c +0 -0
index 75a358f73e69..cade01ea6e68 100644

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 99

Quoted 5 lines
drivers/pci/of_property.c +2 -0
@@ -95,6 +95,9 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
 				 struct of_changeset *ocs,
 				 struct device_node *np)
 {
+	if (!pdev->subordinate)
+		return -EINVAL;

Returning errno is not 'omitting'. This will result in a failure of of_pci_add_properties(). I hope that's not what you wanted.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்