2022-06-06 04:32:13

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH] 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")
Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/pci/controller/pcie-microchip-host.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/pci/controller/pcie-microchip-host.c b/drivers/pci/controller/pcie-microchip-host.c
index dd5dba419047..7263d175b5ad 100644
--- a/drivers/pci/controller/pcie-microchip-host.c
+++ b/drivers/pci/controller/pcie-microchip-host.c
@@ -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;
}

--
2.25.1


2022-06-08 04:17:00

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH] PCI: microchip: Fix refcount leak in mc_pcie_init_irq_domains

On Sun, Jun 5, 2022 at 12:51 AM Miaoqian Lin <[email protected]> wrote:
>
> 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")
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> drivers/pci/controller/pcie-microchip-host.c | 2 ++
> 1 file changed, 2 insertions(+)

Reviewed-by: Rob Herring <[email protected]>

2022-06-08 20:55:09

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH] PCI: microchip: Fix refcount leak in mc_pcie_init_irq_domains

On Sun, Jun 05, 2022 at 09:51:23AM +0400, Miaoqian Lin wrote:
> 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")
> Signed-off-by: Miaoqian Lin <[email protected]>

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

> ---
> drivers/pci/controller/pcie-microchip-host.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pci/controller/pcie-microchip-host.c b/drivers/pci/controller/pcie-microchip-host.c
> index dd5dba419047..7263d175b5ad 100644
> --- a/drivers/pci/controller/pcie-microchip-host.c
> +++ b/drivers/pci/controller/pcie-microchip-host.c
> @@ -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;
> }
>
> --
> 2.25.1
>