]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
of: unittest: Fix device reference count leak in of_unittest_pci_node_verify
authorMa Ke <make24@iscas.ac.cn>
Tue, 30 Sep 2025 08:16:18 +0000 (16:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 19 Oct 2025 14:37:28 +0000 (16:37 +0200)
commit65074c41d794edd06858fa366e0f6d65ef5f42aa
tree7733586e8e53061a2d3fcc4936f963885a01ead9
parent2cf75878ee59c69c8b3eac96743e85ec67d83ded
of: unittest: Fix device reference count leak in of_unittest_pci_node_verify

commit a8de554774ae48efbe48ace79f8badae2daa2bf1 upstream.

In of_unittest_pci_node_verify(), when the add parameter is false,
device_find_any_child() obtains a reference to a child device. This
function implicitly calls get_device() to increment the device's
reference count before returning the pointer. However, the caller
fails to properly release this reference by calling put_device(),
leading to a device reference count leak. Add put_device() in the else
branch immediately after child_dev is no longer needed.

As the comment of device_find_any_child states: "NOTE: you will need
to drop the reference with put_device() after use".

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 26409dd04589 ("of: unittest: Add pci_dt_testdrv pci driver")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/of/unittest.c