mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Sherry Sun <sherry.sun@nxp.com>
Cc: Hongxing Zhu <hongxing.zhu@nxp.com>,
	"l.stach@pengutronix.de" <l.stach@pengutronix.de>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"lpieralisi@kernel.org" <lpieralisi@kernel.org>,
	"kwilczynski@kernel.org" <kwilczynski@kernel.org>,
	"mani@kernel.org" <mani@kernel.org>,
	"robh@kernel.org" <robh@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
	"festevam@gmail.com" <festevam@gmail.com>,
	"imx@lists.linux.dev" <imx@lists.linux.dev>,
	"kernel@pengutronix.de" <kernel@pengutronix.de>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V7 02/13] PCI: host-generic: Add common helpers for parsing Root Port properties
Date: Wed, 11 Mar 2026 11:47:32 -0400	[thread overview]
Message-ID: <abGOlFxj0yK53tRO@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <GV2PR04MB121020F9D89A4025C6C59535E9247A@GV2PR04MB12102.eurprd04.prod.outlook.com>

On Wed, Mar 11, 2026 at 10:03:01AM +0000, Sherry Sun wrote:
> > From: Frank Li (AI-BOT) <frank.li@nxp.com>
> >
> > > +int pci_host_common_parse_ports(struct device *dev, struct
> > > +pci_host_bridge *bridge) {
> > > +	int ret = -ENOENT;
> > > +
> > > +	for_each_available_child_of_node_scoped(dev->of_node, of_port) {
> > > +		if (!of_node_is_type(of_port, "pci"))
> > > +			continue;
> > > +		ret = pci_host_common_parse_port(dev, bridge, of_port);
> > > +		if (ret)
> > > +			return ret;
> > > +	}
> > > +
> > > +	return ret;
> > > +}
> >
> > AI: Returning -ENOENT when no ports are found may be unexpected by
> > callers.
> > Consider whether this should return 0 (success, zero ports parsed) or if callers
> > must explicitly handle -ENOENT. Document the semantics clearly.
> >
>
> Returning -ENOENT when no ports are found is intentional and aligns with the
> design requirements for this use case. This pattern is common in the kernel where
> parsing functions return -ENOENT when expected nodes/properties are missing.
>
> 1. -ENOENT semantically means  "the expected entity was not found", which accurately
>     reflects the situation when no Root Port nodes exist in the device tree.
> 2. The callers of this function need to distinguish between:
>    - Success with ports found (return 0)
>    - No ports found in DT (-ENOENT) - this may be a DT configuration issue, for controllers
>      where ports are optional, they can explicitly check for -ENOENT and treat it as non-fatal.
>    - Actual parsing errors (other negative error codes like -ENOMEM, -EPROBE_DEFER)

I think no ports under bridge should treat as 0. otherwise it may broken
other platform, which dt have not added child node yet.

Frank

>
> > > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index
> > > bccc7a4bdd79..9cc3f4ebb370 100644
> > > --- a/drivers/pci/probe.c
> > > +++ b/drivers/pci/probe.c
> > > @@ -647,6 +647,7 @@ static void pci_release_host_bridge_dev(struct
> > > device *dev)
> > >
> > >  	pci_free_resource_list(&bridge->windows);
> > >  	pci_free_resource_list(&bridge->dma_ranges);
> > > +	pci_free_resource_list(&bridge->ports);
> >
> > AI: pci_free_resource_list() expects struct resource_entry nodes. The ports list
> > contains struct pci_host_port nodes. This will corrupt memory or crash. Use
> > list_for_each_entry_safe() with proper cleanup, or define a dedicated
> > pci_free_host_ports() function.
>
> Yes, thanks for catching this, pci_free_resource_list() expects struct resource_entry
> nodes and cannot be used for struct pci_host_port nodes.
> I will add back the cleanup function pci_host_common_delete_ports() in earlier version
> patchset to properly handles the ports list.
>
> Best regards,
> Sherry

  reply	other threads:[~2026-03-11 15:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10  1:54 [PATCH V7 00/13] pci-imx6: Add support for parsing the reset property in new Root Port binding Sherry Sun
2026-03-10  1:54 ` [PATCH V7 01/13] dt-bindings: PCI: fsl,imx6q-pcie: Add reset GPIO in Root Port node Sherry Sun
2026-03-10  1:54 ` [PATCH V7 02/13] PCI: host-generic: Add common helpers for parsing Root Port properties Sherry Sun
2026-03-10 18:28   ` Frank Li
2026-03-11 10:03     ` Sherry Sun
2026-03-11 15:47       ` Frank Li [this message]
2026-03-12  2:04         ` Sherry Sun
2026-03-10  1:54 ` [PATCH V7 03/13] PCI: dwc: Parse Root Port nodes in dw_pcie_host_init() Sherry Sun
2026-03-10  1:54 ` [PATCH V7 04/13] PCI: imx6: Assert PERST# before enabling regulators Sherry Sun
2026-03-10 15:23   ` Frank Li
2026-03-11  7:09     ` Sherry Sun
2026-03-10  1:54 ` [PATCH V7 05/13] PCI: imx6: Add support for parsing the reset property in new Root Port binding Sherry Sun
2026-03-10  1:54 ` [PATCH V7 06/13] arm: dts: imx6qdl: Add Root Port node and PERST property Sherry Sun
2026-03-10  1:54 ` [PATCH V7 07/13] arm: dts: imx6sx: " Sherry Sun
2026-03-10  1:54 ` [PATCH V7 08/13] arm: dts: imx7d: " Sherry Sun
2026-03-10  1:54 ` [PATCH V7 09/13] arm64: dts: imx8mm: " Sherry Sun
2026-03-10  1:54 ` [PATCH V7 10/13] arm64: dts: imx8mp: " Sherry Sun
2026-03-10  1:54 ` [PATCH V7 11/13] arm64: dts: imx8mq: " Sherry Sun
2026-03-10  1:54 ` [PATCH V7 12/13] arm64: dts: imx8dxl/qm/qxp: " Sherry Sun
2026-03-10  1:54 ` [PATCH V7 13/13] arm64: dts: imx95: " Sherry Sun
2026-03-10 19:12 ` [PATCH V7 00/13] pci-imx6: Add support for parsing the reset property in new Root Port binding Bjorn Helgaas
2026-03-11  6:06   ` Sherry Sun

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=abGOlFxj0yK53tRO@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=hongxing.zhu@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sherry.sun@nxp.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

all inboxes | Powered by JetHome®