Re: [PATCH] PCI/pwrctrl: Fix device node leak in pci_pwrctrl_is_required()

From: Bjorn Helgaas

Date: Tue Mar 24 2026 - 12:00:54 EST


On Tue, Mar 24, 2026 at 06:05:18PM +0800, Felix Gu wrote:
> On Tue, Mar 24, 2026 at 4:57 AM Bjorn Helgaas <helgaas@xxxxxxxxxx> wrote:
> >
> > On Mon, Mar 23, 2026 at 07:05:22PM +0800, Felix Gu wrote:
> > > The for_each_endpoint_of_node() macro requires calling of_node_put() on
> > > the endpoint node when breaking out of the loop early.
> > >
> > > Add of_node_put(endpoint) before the early return to properly release
> > > the reference.
> > >
> > > Fixes: cf3287fb2c1f ("PCI/pwrctrl: Ensure that remote endpoint node parent has supply requirement")
> > > Signed-off-by: Felix Gu <ustc.gu@xxxxxxxxx>
> >
> > cf3287fb2c1f appeared in v7.0-rc5, so I put this on pci/for-linus for
> > v7.0, thanks!
> >
> > Would you also take a look at pwrseq_pcie_m2_match()? It can
> > similarly return early from a for_each_endpoint_of_node() loop, so I'm
> > concerned it may have a similar issue.
>
> pwrseq_pcie_m2_match should be fine, endpoint is marked as
> __free(device_node), it will be called of_node_put() automatically
> when returning early.

Thanks, Felix, I indeed missed the __free() on the declaration.

For anyone else following along (and me the next time I trip over
this, since the connection from __free() to of_node_put() is somewhat
obscure), here's the connection:

pwrseq_pcie_m2_match(...)
{
struct device_node *endpoint __free(device_node) = NULL;
for_each_endpoint_of_node(ctx->of_node, endpoint) {
if (...)
return PWRSEQ_MATCH_OK;
}
}

$ git grep "DEFINE_FREE(device_node"
include/linux/of.h:DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))