PCI: mediatek: Add missing of_node_put() to fix reference leak
authorKrzysztof Wilczyński <kw@linux.com>
Wed, 20 Jan 2021 18:48:10 +0000 (18:48 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Mar 2021 16:06:24 +0000 (17:06 +0100)
commitfa6dae9d7ffd3baf9610fd3ae3cfe7b68d446786
treec47a2168ca38ba1abe32381e613ec1e683d0aa2b
parentd26949c732e47f6821b694e259f43e19bf266e0e
PCI: mediatek: Add missing of_node_put() to fix reference leak

[ Upstream commit 42814c438aac79746d310f413a27d5b0b959c5de ]

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>
drivers/pci/controller/pcie-mediatek.c