mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
PCI: mediatek: Add missing of_node_put() to fix reference leak
[ Upstream commit 42814c438a ]
The for_each_available_child_of_node helper internally makes use of the
of_get_next_available_child() which performs an of_node_get() on each
iteration when searching for next available child node.
Should an available child node be found, then it would return a device
node pointer with reference count incremented, thus early return from
the middle of the loop requires an explicit of_node_put() to prevent
reference count leak.
To stop the reference leak, explicitly call of_node_put() before
returning after an error occurred.
Link: https://lore.kernel.org/r/20210120184810.3068794-1-kw@linux.com
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
d26949c732
commit
fa6dae9d7f
@@ -1035,14 +1035,14 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
|
|||||||
err = of_pci_get_devfn(child);
|
err = of_pci_get_devfn(child);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(dev, "failed to parse devfn: %d\n", err);
|
dev_err(dev, "failed to parse devfn: %d\n", err);
|
||||||
return err;
|
goto error_put_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
slot = PCI_SLOT(err);
|
slot = PCI_SLOT(err);
|
||||||
|
|
||||||
err = mtk_pcie_parse_port(pcie, child, slot);
|
err = mtk_pcie_parse_port(pcie, child, slot);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
goto error_put_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = mtk_pcie_subsys_powerup(pcie);
|
err = mtk_pcie_subsys_powerup(pcie);
|
||||||
@@ -1058,6 +1058,9 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
|
|||||||
mtk_pcie_subsys_powerdown(pcie);
|
mtk_pcie_subsys_powerdown(pcie);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
error_put_node:
|
||||||
|
of_node_put(child);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mtk_pcie_probe(struct platform_device *pdev)
|
static int mtk_pcie_probe(struct platform_device *pdev)
|
||||||
|
|||||||
Reference in New Issue
Block a user