PCI: tegra: Fix OF node reference leak
authorNishka Dasgupta <nishkadg.linux@gmail.com>
Wed, 24 Jul 2019 08:24:12 +0000 (13:54 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 7 Oct 2019 16:57:09 +0000 (18:57 +0200)
commit3b7fbbddeb7a1d7f01026586077faa850d099b78
treefc8327a1bf8310903a884a446b6f355914ad464b
parentc74a801ded7d785bb71c91fb28efbd703ef30c42
PCI: tegra: Fix OF node reference leak

[ Upstream commit 9e38e690ace3e7a22a81fc02652fc101efb340cf ]

Each iteration of for_each_child_of_node() executes of_node_put() on the
previous node, but in some return paths in the middle of the loop
of_node_put() is missing thus causing a reference leak.

Hence stash these mid-loop return values in a variable 'err' and add a
new label err_node_put which executes of_node_put() on the previous node
and returns 'err' on failure.

Change mid-loop return statements to point to jump to this label to
fix the reference leak.

Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
[lorenzo.pieralisi@arm.com: rewrote commit log]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pci/controller/pci-tegra.c