Skip to contentSkip to conversation

PCI: microchip: Fix refcount leak in mc_pcie_init_irq_domains

PATCH In review Miaoqian Lin 3 participants 3 messages Jun 5, 2022 – Jun 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: microchip: Fix refcount leak in mc_pcie_init_irq_domains

of_get_next_child() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only call of_node_put() in normal path, missing it in some error paths.
Add missing of_node_put() to avoid refcount leak.

Fixes 6f15a9c9f941 ("PCI: microchip: Add Microchip PolarFire PCIe controller driver")
---
 drivers/pci/controller/pcie-microchip-host.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/pcie-microchip-host.c +2 -0
index dd5dba419047..7263d175b5ad 100644
@@ -904,6 +904,7 @@ static int mc_pcie_init_irq_domains(struct mc_pcie *port)
 						   &event_domain_ops, port);
 	if (!port->event_domain) {
 		dev_err(dev, "failed to get event domain\n");
+		of_node_put(pcie_intc_node);
 		return -ENOMEM;
 	}
 
@@ -913,6 +914,7 @@ static int mc_pcie_init_irq_domains(struct mc_pcie *port)
 						  &intx_domain_ops, port);
 	if (!port->intx_domain) {
 		dev_err(dev, "failed to get an INTx IRQ domain\n");
+		of_node_put(pcie_intc_node);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Miaoqian Lin

of_get_next_child() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only call of_node_put() in normal path, missing it in some error paths.
Add missing of_node_put() to avoid refcount leak.

Quoted 5 lines
Fixes 6f15a9c9f941 ("PCI: microchip: Add Microchip PolarFire PCIe controller driver")
---
 drivers/pci/controller/pcie-microchip-host.c | 2 ++
 1 file changed, 2 insertions(+)
#2 lore raw
In reply to Miaoqian Lin
Quoted 8 lines · Miaoqian Lin

of_get_next_child() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function only call of_node_put() in normal path, missing it in some error paths.
Add missing of_node_put() to avoid refcount leak.

Fixes 6f15a9c9f941 ("PCI: microchip: Add Microchip PolarFire PCIe controller driver")

Applied with Rob's reviewed-by to pci/ctrl/microchip for v5.20, thanks!

Quoted 27 lines
---
 drivers/pci/controller/pcie-microchip-host.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/controller/pcie-microchip-host.c +2 -0
index dd5dba419047..7263d175b5ad 100644
@@ -904,6 +904,7 @@ static int mc_pcie_init_irq_domains(struct mc_pcie *port)
 						   &event_domain_ops, port);
 	if (!port->event_domain) {
 		dev_err(dev, "failed to get event domain\n");
+		of_node_put(pcie_intc_node);
 		return -ENOMEM;
 	}
 
@@ -913,6 +914,7 @@ static int mc_pcie_init_irq_domains(struct mc_pcie *port)
 						  &intx_domain_ops, port);
 	if (!port->intx_domain) {
 		dev_err(dev, "failed to get an INTx IRQ domain\n");
+		of_node_put(pcie_intc_node);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.25.1