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:53:16 +0000 (18:53 +0200)
commitc0c2a1ad6825e40fc55e803c8ab9907d0034d766
treec3ebb9ffa4e623ede33caaca9844a8606f8138b3
parent8573fcdff5bfcf622712a0af1954200c242a1d6a
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/host/pci-tegra.c