Re: [PATCH] PCI/AER: Fix device reference leak in aer_inject()

From: Aadityarangan Shridhar Iyengar

Date: Wed Mar 18 2026 - 06:36:50 EST


On Mon, Mar 17, 2026 at 09:17:00PM +0000, Bjorn Helgaas wrote:
> From AI
> (https://sashiko.dev/#/patchset/20260317172732.58053-1-adiyenga%40cisco.com):
>
> Is this description accurate? Looking at pcie_port_find_device(), it
> uses device_for_each_child() with the find_service_iter() callback.
> Unlike device_find_child(), neither of these functions calls
> get_device() on the matched child device to increment its reference
> count.

You're right, the description is inaccurate. I confused
device_for_each_child() with device_find_child(). The latter explicitly
calls get_device() on the matched child and documents that the caller
must call put_device(), but device_for_each_child() does not — the
iterator ref is dropped by klist_iter_exit() and no caller-owned
reference is returned.

Adding put_device() here would underflow the refcount, which is worse
than the original code.

Please drop this patch. Sorry for the noise.

Aditya