Skip to content

Commit fa6dae9

Browse files
kwilczynskigregkh
authored andcommitted
PCI: mediatek: Add missing of_node_put() to fix reference leak
[ Upstream commit 42814c4 ] 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>
1 parent d26949c commit fa6dae9

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎drivers/pci/controller/pcie-mediatek.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,14 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
10351035
err = of_pci_get_devfn(child);
10361036
if (err < 0) {
10371037
dev_err(dev, "failed to parse devfn: %d\n", err);
1038-
return err;
1038+
goto error_put_node;
10391039
}
10401040

10411041
slot = PCI_SLOT(err);
10421042

10431043
err = mtk_pcie_parse_port(pcie, child, slot);
10441044
if (err)
1045-
return err;
1045+
goto error_put_node;
10461046
}
10471047

10481048
err = mtk_pcie_subsys_powerup(pcie);
@@ -1058,6 +1058,9 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
10581058
mtk_pcie_subsys_powerdown(pcie);
10591059

10601060
return 0;
1061+
error_put_node:
1062+
of_node_put(child);
1063+
return err;
10611064
}
10621065

10631066
static int mtk_pcie_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)