Skip to contentSkip to conversation

PCI: Check parent for NULL in of_pci_bus_release_domain_nr()

PATCH Applied Sergey Shtylyov 2 participants 3 messages Jan 27 – Jan 29 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Check parent for NULL in of_pci_bus_release_domain_nr()

of_pci_bus_find_domain_nr() allows its parent parameter to be NULL but of_pci_bus_release_domain_nr() (that undoes its effect) doesn't -- that means it's going to blow up while calling of_get_pci_domain_nr() if the parent parameter indeed happens to be NULL. Add the missing NULL check.

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes c14f7ccc9f5d ("PCI: Assign PCI domain IDs by ida_alloc()")
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
index 13dbb405dc31..9fc4c2226b03 100644
@@ -6591,7 +6591,7 @@ static void of_pci_bus_release_domain_nr(struct device *parent, int domain_nr)
 		return;
 
 	/* Release domain from IDA where it was allocated. */
-	if (of_get_pci_domain_nr(parent->of_node) == domain_nr)
+	if (parent && of_get_pci_domain_nr(parent->of_node) == domain_nr)
 		ida_free(&pci_domain_nr_static_ida, domain_nr);
 	else
 		ida_free(&pci_domain_nr_dynamic_ida, domain_nr);
Signature · 1 line
2.52.0
#1 lore raw
Quoted 11 lines · Sergey Shtylyov

of_pci_bus_find_domain_nr() allows its parent parameter to be NULL but of_pci_bus_release_domain_nr() (that undoes its effect) doesn't -- that means it's going to blow up while calling of_get_pci_domain_nr() if the parent parameter indeed happens to be NULL. Add the missing NULL check.

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes c14f7ccc9f5d ("PCI: Assign PCI domain IDs by ida_alloc()")

---

Forgot to add that this patch was done against the for-linus branch of
the pci.git repo...

[...]

MBR, Sergey

#2 lore raw
In reply to Sergey Shtylyov
Quoted 10 lines · Sergey Shtylyov

of_pci_bus_find_domain_nr() allows its parent parameter to be NULL but of_pci_bus_release_domain_nr() (that undoes its effect) doesn't -- that means it's going to blow up while calling of_get_pci_domain_nr() if the parent parameter indeed happens to be NULL. Add the missing NULL check.

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes c14f7ccc9f5d ("PCI: Assign PCI domain IDs by ida_alloc()")

Applied to pci/enumeration for v6.20, thanks!

Quoted 20 lines
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
index 13dbb405dc31..9fc4c2226b03 100644
@@ -6591,7 +6591,7 @@ static void of_pci_bus_release_domain_nr(struct device *parent, int domain_nr)
 		return;
 
 	/* Release domain from IDA where it was allocated. */
-	if (of_get_pci_domain_nr(parent->of_node) == domain_nr)
+	if (parent && of_get_pci_domain_nr(parent->of_node) == domain_nr)
 		ida_free(&pci_domain_nr_static_ida, domain_nr);
 	else
 		ida_free(&pci_domain_nr_dynamic_ida, domain_nr);
Signature · 1 line
2.52.0