Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Felix Gu <ustc.gu@gmail.com>
Cc: Bartosz Golaszewski <brgl@kernel.org>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>,
	Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
	Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI/pwrctrl: Fix device node leak in pci_pwrctrl_is_required()
Date: Tue, 24 Mar 2026 10:49:04 -0500	[thread overview]
Message-ID: <20260324154904.GA1129159@bhelgaas> (raw)
In-Reply-To: <CAN4SLj2PRsaZnO_WptYQaQH4-DajrVd9L_=KXwTuOZj0kyLrOw@mail.gmail.com>

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@kernel.org> 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@gmail.com>
> >
> > 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))


      reply	other threads:[~2026-03-24 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 11:05 [PATCH] PCI/pwrctrl: Fix device node leak in pci_pwrctrl_is_required() Felix Gu
2026-03-23 12:07 ` Manivannan Sadhasivam
2026-03-23 13:00 ` Bartosz Golaszewski
2026-03-23 20:57 ` Bjorn Helgaas
2026-03-24 10:05   ` Felix Gu
2026-03-24 15:49     ` Bjorn Helgaas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260324154904.GA1129159@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=bhelgaas@google.com \
    --cc=brgl@kernel.org \
    --cc=krishna.chundru@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=manivannan.sadhasivam@oss.qualcomm.com \
    --cc=ustc.gu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox