summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorMa Ke <make24@iscas.ac.cn>2025-09-30 16:16:18 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-10-19 16:30:50 +0200
commitff770d10cfeb16aac9592b4f8c036095ef05b590 (patch)
tree71028be5e92f9f8941b0612dfea387a6f2fb0330 /drivers/of
parentbabe2b53fa7db66533767cd0b242b52094716d2a (diff)
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>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/unittest.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 5bfec440b4fd..aae4e8ef9e36 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -3957,6 +3957,7 @@ static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add)
unittest(!np, "Child device tree node is not removed\n");
child_dev = device_find_any_child(&pdev->dev);
unittest(!child_dev, "Child device is not removed\n");
+ put_device(child_dev);
}
failed: