Skip to content

Commit a8de554

Browse files
Ma Kerobherring
authored andcommitted
of: unittest: Fix device reference count leak in of_unittest_pci_node_verify
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: [email protected] Fixes: 26409dd ("of: unittest: Add pci_dt_testdrv pci driver") Signed-off-by: Ma Ke <[email protected]> Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent 4e66293 commit a8de554

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/of/unittest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,6 +4300,7 @@ static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add)
43004300
unittest(!np, "Child device tree node is not removed\n");
43014301
child_dev = device_find_any_child(&pdev->dev);
43024302
unittest(!child_dev, "Child device is not removed\n");
4303+
put_device(child_dev);
43034304
}
43044305

43054306
failed:

0 commit comments

Comments
 (0)