[{"id":3674190,"web_url":"http://patchwork.ozlabs.org/comment/3674190/","msgid":"<lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>","list_archive_url":null,"date":"2026-04-07T13:27:03","subject":"Re: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","submitter":{"id":78905,"url":"http://patchwork.ozlabs.org/api/people/78905/","name":"Manivannan Sadhasivam","email":"mani@kernel.org"},"content":"On Tue, Apr 07, 2026 at 06:41:44PM +0800, Sherry Sun wrote:\n> Introduce generic helper functions to parse Root Port device tree nodes\n> and extract common properties like reset GPIOs. This allows multiple\n> PCI host controller drivers to share the same parsing logic.\n> \n> Define struct pci_host_port to hold common Root Port properties\n> (currently only reset GPIO descriptor) and add\n> pci_host_common_parse_ports() to parse Root Port nodes from device tree.\n> \n> Also add the 'ports' list to struct pci_host_bridge for better maintain\n> parsed Root Port information.\n> \n> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>\n> ---\n>  drivers/pci/controller/pci-host-common.c | 77 ++++++++++++++++++++++++\n>  drivers/pci/controller/pci-host-common.h | 16 +++++\n>  drivers/pci/probe.c                      |  1 +\n>  include/linux/pci.h                      |  1 +\n>  4 files changed, 95 insertions(+)\n> \n> diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c\n> index d6258c1cffe5..0fb6991dde7b 100644\n> --- a/drivers/pci/controller/pci-host-common.c\n> +++ b/drivers/pci/controller/pci-host-common.c\n> @@ -9,6 +9,7 @@\n>  \n>  #include <linux/kernel.h>\n>  #include <linux/module.h>\n> +#include <linux/gpio/consumer.h>\n>  #include <linux/of.h>\n>  #include <linux/of_address.h>\n>  #include <linux/of_pci.h>\n> @@ -17,6 +18,82 @@\n>  \n>  #include \"pci-host-common.h\"\n>  \n> +/**\n> + * pci_host_common_delete_ports - Cleanup function for port list\n> + * @data: Pointer to the port list head\n> + */\n> +void pci_host_common_delete_ports(void *data)\n> +{\n> +\tstruct list_head *ports = data;\n> +\tstruct pci_host_port *port, *tmp;\n> +\n> +\tlist_for_each_entry_safe(port, tmp, ports, list)\n> +\t\tlist_del(&port->list);\n> +}\n> +EXPORT_SYMBOL_GPL(pci_host_common_delete_ports);\n> +\n> +/**\n> + * pci_host_common_parse_port - Parse a single Root Port node\n> + * @dev: Device pointer\n> + * @bridge: PCI host bridge\n> + * @node: Device tree node of the Root Port\n> + *\n> + * Returns: 0 on success, negative error code on failure\n> + */\n> +static int pci_host_common_parse_port(struct device *dev,\n> +\t\t\t\t      struct pci_host_bridge *bridge,\n> +\t\t\t\t      struct device_node *node)\n> +{\n> +\tstruct pci_host_port *port;\n> +\tstruct gpio_desc *reset;\n> +\n> +\treset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> +\t\t\t\t      \"reset\", GPIOD_ASIS, \"PERST#\");\n\nSorry, I missed this earlier.\n\nSince PERST# is optional, you cannot reliably detect whether the Root Port\nbinding intentionally skipped the PERST# GPIO or legacy binding is used, just by\nchecking for PERST# in Root Port node.\n\nSo this helper should do 3 things:\n\n1. If PERST# is found in Root Port node, use it.\n2. If not, check the RC node and if present, return -ENOENT to fallback to the\nlegacy binding.\n3. If not found in both nodes, assume that the PERST# is not present in the\ndesign, and proceed with parsing Root Port binding further.\n\nBut there is one more important limitation here. Right now, this API only\nhandles PERST#. But if another vendor tries to use it and if they need other\nproperties such as PHY, clocks etc... those resources should be fetched\noptionally only by this helper. But if the controller has a hard dependency on\nthose resources, the driver will fail to operate.\n\nI don't think we can fix this limitation though and those platforms should\nensure that the resource dependency is correctly modeled in DT binding and the\nDTS is validated properly. It'd be good to mention this in the kernel doc of\nthis API.\n\n> +\tif (IS_ERR(reset))\n> +\t\treturn PTR_ERR(reset);\n> +\n> +\tport = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> +\tif (!port)\n> +\t\treturn -ENOMEM;\n> +\n> +\tport->reset = reset;\n> +\tINIT_LIST_HEAD(&port->list);\n> +\tlist_add_tail(&port->list, &bridge->ports);\n> +\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * pci_host_common_parse_ports - Parse Root Port nodes from device tree\n> + * @dev: Device pointer\n> + * @bridge: PCI host bridge\n> + *\n> + * This function iterates through child nodes of the host bridge and parses\n> + * Root Port properties (currently only reset GPIO).\n> + *\n> + * Returns: 0 on success, -ENOENT if no ports found, other negative error codes\n> + * on failure\n> + */\n> +int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *bridge)\n> +{\n> +\tint ret = -ENOENT;\n> +\n> +\tfor_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> +\t\tif (!of_node_is_type(of_port, \"pci\"))\n> +\t\t\tcontinue;\n> +\t\tret = pci_host_common_parse_port(dev, bridge, of_port);\n> +\t\tif (ret)\n> +\t\t\treturn ret;\n\nAs Sashiko flagged, you need to make sure that devm_add_action_or_reset() is\nadded even during the error path:\nhttps://sashiko.dev/#/patchset/20260407104154.2842132-1-sherry.sun%40nxp.com?part=2\n\n- Mani\n\n> +\t}\n> +\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\treturn devm_add_action_or_reset(dev, pci_host_common_delete_ports,\n> +\t\t\t\t\t&bridge->ports);\n> +}\n> +EXPORT_SYMBOL_GPL(pci_host_common_parse_ports);\n> +\n>  static void gen_pci_unmap_cfg(void *ptr)\n>  {\n>  \tpci_ecam_free((struct pci_config_window *)ptr);\n> diff --git a/drivers/pci/controller/pci-host-common.h b/drivers/pci/controller/pci-host-common.h\n> index b5075d4bd7eb..37714bedb625 100644\n> --- a/drivers/pci/controller/pci-host-common.h\n> +++ b/drivers/pci/controller/pci-host-common.h\n> @@ -12,6 +12,22 @@\n>  \n>  struct pci_ecam_ops;\n>  \n> +/**\n> + * struct pci_host_port - Generic Root Port properties\n> + * @list: List node for linking multiple ports\n> + * @reset: GPIO descriptor for PERST# signal\n> + *\n> + * This structure contains common properties that can be parsed from\n> + * Root Port device tree nodes.\n> + */\n> +struct pci_host_port {\n> +\tstruct list_head\tlist;\n> +\tstruct gpio_desc\t*reset;\n> +};\n> +\n> +void pci_host_common_delete_ports(void *data);\n> +int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *bridge);\n> +\n>  int pci_host_common_probe(struct platform_device *pdev);\n>  int pci_host_common_init(struct platform_device *pdev,\n>  \t\t\t struct pci_host_bridge *bridge,\n> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c\n> index eaa4a3d662e8..629ae08b7d35 100644\n> --- a/drivers/pci/probe.c\n> +++ b/drivers/pci/probe.c\n> @@ -677,6 +677,7 @@ static void pci_init_host_bridge(struct pci_host_bridge *bridge)\n>  {\n>  \tINIT_LIST_HEAD(&bridge->windows);\n>  \tINIT_LIST_HEAD(&bridge->dma_ranges);\n> +\tINIT_LIST_HEAD(&bridge->ports);\n>  \n>  \t/*\n>  \t * We assume we can manage these PCIe features.  Some systems may\n> diff --git a/include/linux/pci.h b/include/linux/pci.h\n> index 8f63de38f2d2..a73ea81ce88f 100644\n> --- a/include/linux/pci.h\n> +++ b/include/linux/pci.h\n> @@ -636,6 +636,7 @@ struct pci_host_bridge {\n>  \tint\t\tdomain_nr;\n>  \tstruct list_head windows;\t/* resource_entry */\n>  \tstruct list_head dma_ranges;\t/* dma ranges resource list */\n> +\tstruct list_head ports;\t\t/* Root Port list (pci_host_port) */\n>  #ifdef CONFIG_PCI_IDE\n>  \tu16 nr_ide_streams; /* Max streams possibly active in @ide_stream_ida */\n>  \tstruct ida ide_stream_ida;\n> -- \n> 2.37.1\n>","headers":{"Return-Path":"\n <linux-pci+bounces-52072-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=Ch1UitFu;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-52072-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"Ch1UitFu\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fqnHd70mQz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 07 Apr 2026 23:34:53 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 9424A3088910\n\tfor <incoming@patchwork.ozlabs.org>; Tue,  7 Apr 2026 13:27:15 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id E5FB53B774A;\n\tTue,  7 Apr 2026 13:27:13 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id C2C362F60CC;\n\tTue,  7 Apr 2026 13:27:13 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id B371EC19424;\n\tTue,  7 Apr 2026 13:27:07 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775568433; cv=none;\n b=n64wZke4PM3kvBMvqyF+xQtwx6NFlQWP+YjL4pxFKPC5ikD575b74qzHCUx7xHInmlzVTYdcN10fQEKFjHPg4HYqSBVTVq6LYlApaouW84IjI4v2h1ApKwbbydLGPvv93hkUEJ1zTeuSAZc5juhgIHW4J9KKyJKTkzR5KccYhe8=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775568433; c=relaxed/simple;\n\tbh=NbvYPznNh5YF7BLCPc0vkkphiqZCgi6sGlSzqTEKe4c=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=ByqzeXlOShuDm3SAt23FO807xZtYjoWXqA8C0sk72W+GXs8qf8l/QDi6D51xKnM37BIhcJyLMMa8Pl+QOrDK/AnkeJjbCjgCvyfsjJ8WxUrl3vSMwOUeRXuJhzhDENeGD/vIIpTalyGXhyPmDC7uFFx6ovbXlLgD0MRKOrcjnvg=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=Ch1UitFu; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775568433;\n\tbh=NbvYPznNh5YF7BLCPc0vkkphiqZCgi6sGlSzqTEKe4c=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Ch1UitFu4B4nmanDqFPopy62LPM5Pa7VCdL0eyDdf5CyqE/KW9DvFpWntJtqIdMcK\n\t VA3pt1Hd+/ORLe3VqOo52fYtUYdhO1OVGn1d2rDmvdHLnbOMZEZLoTzlJlNfcMA2+A\n\t tiGCzXFaXeMOJY+JiFf+cZLBxShZEPA1GrmBdxOMqI5hfOmchhwxzsUOf87hgWZlo6\n\t 3fsXhARMFVOONtS+hz54n1CFbZC9OD4BjLwcE2QdqxSPbSACZrZoI/LNaMMWmgd6RK\n\t CQADol0qm36nT5JbY4vzh9DTz7tR5XNvqaUG5glthTYqXI7YyJAxHmuTCt826rbtYR\n\t v9jLAXWxsKnsg==","Date":"Tue, 7 Apr 2026 18:57:03 +0530","From":"Manivannan Sadhasivam <mani@kernel.org>","To":"Sherry Sun <sherry.sun@nxp.com>","Cc":"robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,\n\tFrank.Li@nxp.com, s.hauer@pengutronix.de, kernel@pengutronix.de,\n\tfestevam@gmail.com, lpieralisi@kernel.org, kwilczynski@kernel.org,\n\tbhelgaas@google.com, hongxing.zhu@nxp.com, l.stach@pengutronix.de,\n\timx@lists.linux.dev, linux-pci@vger.kernel.org,\n linux-arm-kernel@lists.infradead.org,\n\tdevicetree@vger.kernel.org, linux-kernel@vger.kernel.org","Subject":"Re: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Message-ID":"<lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>","References":"<20260407104154.2842132-1-sherry.sun@nxp.com>\n <20260407104154.2842132-3-sherry.sun@nxp.com>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260407104154.2842132-3-sherry.sun@nxp.com>"}},{"id":3674576,"web_url":"http://patchwork.ozlabs.org/comment/3674576/","msgid":"<VI0PR04MB12114A60C4A7E43ED62A32B04925BA@VI0PR04MB12114.eurprd04.prod.outlook.com>","list_archive_url":null,"date":"2026-04-08T06:34:02","subject":"RE: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","submitter":{"id":77063,"url":"http://patchwork.ozlabs.org/api/people/77063/","name":"Sherry Sun","email":"sherry.sun@nxp.com"},"content":"> On Tue, Apr 07, 2026 at 06:41:44PM +0800, Sherry Sun wrote:\n> > Introduce generic helper functions to parse Root Port device tree\n> > nodes and extract common properties like reset GPIOs. This allows\n> > multiple PCI host controller drivers to share the same parsing logic.\n> >\n> > Define struct pci_host_port to hold common Root Port properties\n> > (currently only reset GPIO descriptor) and add\n> > pci_host_common_parse_ports() to parse Root Port nodes from device\n> tree.\n> >\n> > Also add the 'ports' list to struct pci_host_bridge for better\n> > maintain parsed Root Port information.\n> >\n> > Signed-off-by: Sherry Sun <sherry.sun@nxp.com>\n> > ---\n> >  drivers/pci/controller/pci-host-common.c | 77\n> > ++++++++++++++++++++++++  drivers/pci/controller/pci-host-common.h |\n> 16 +++++\n> >  drivers/pci/probe.c                      |  1 +\n> >  include/linux/pci.h                      |  1 +\n> >  4 files changed, 95 insertions(+)\n> >\n> > diff --git a/drivers/pci/controller/pci-host-common.c\n> > b/drivers/pci/controller/pci-host-common.c\n> > index d6258c1cffe5..0fb6991dde7b 100644\n> > --- a/drivers/pci/controller/pci-host-common.c\n> > +++ b/drivers/pci/controller/pci-host-common.c\n> > @@ -9,6 +9,7 @@\n> >\n> >  #include <linux/kernel.h>\n> >  #include <linux/module.h>\n> > +#include <linux/gpio/consumer.h>\n> >  #include <linux/of.h>\n> >  #include <linux/of_address.h>\n> >  #include <linux/of_pci.h>\n> > @@ -17,6 +18,82 @@\n> >\n> >  #include \"pci-host-common.h\"\n> >\n> > +/**\n> > + * pci_host_common_delete_ports - Cleanup function for port list\n> > + * @data: Pointer to the port list head  */ void\n> > +pci_host_common_delete_ports(void *data) {\n> > +\tstruct list_head *ports = data;\n> > +\tstruct pci_host_port *port, *tmp;\n> > +\n> > +\tlist_for_each_entry_safe(port, tmp, ports, list)\n> > +\t\tlist_del(&port->list);\n> > +}\n> > +EXPORT_SYMBOL_GPL(pci_host_common_delete_ports);\n> > +\n> > +/**\n> > + * pci_host_common_parse_port - Parse a single Root Port node\n> > + * @dev: Device pointer\n> > + * @bridge: PCI host bridge\n> > + * @node: Device tree node of the Root Port\n> > + *\n> > + * Returns: 0 on success, negative error code on failure  */ static\n> > +int pci_host_common_parse_port(struct device *dev,\n> > +\t\t\t\t      struct pci_host_bridge *bridge,\n> > +\t\t\t\t      struct device_node *node)\n> > +{\n> > +\tstruct pci_host_port *port;\n> > +\tstruct gpio_desc *reset;\n> > +\n> > +\treset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> > +\t\t\t\t      \"reset\", GPIOD_ASIS, \"PERST#\");\n> \n> Sorry, I missed this earlier.\n> \n> Since PERST# is optional, you cannot reliably detect whether the Root Port\n> binding intentionally skipped the PERST# GPIO or legacy binding is used, just\n> by checking for PERST# in Root Port node.\n> \n> So this helper should do 3 things:\n> \n> 1. If PERST# is found in Root Port node, use it.\n> 2. If not, check the RC node and if present, return -ENOENT to fallback to the\n> legacy binding.\n> 3. If not found in both nodes, assume that the PERST# is not present in the\n> design, and proceed with parsing Root Port binding further.\n\nHi Mani, understand, does the following code looks ok for above three cases?\n\n    /* Check if PERST# is present in Root Port node */\n    reset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n                      \"reset\", GPIOD_ASIS, \"PERST#\");\n    if (IS_ERR(reset)) {\n        /* If error is not -ENOENT, it's a real error */\n        if (PTR_ERR(reset) != -ENOENT)\n            return PTR_ERR(reset);\n\n        /* PERST# not found in Root Port node, check RC node */\n        rc_has_reset = of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n                   of_property_read_bool(dev->of_node, \"reset-gpio\");\n        if (rc_has_reset)\n            return -ENOENT;\n\n        /* No PERST# in either node, assume not present in design */\n        reset = NULL;\n    }\n\n    port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n    if (!port)\n        return -ENOMEM;\n...\n\n> \n> But there is one more important limitation here. Right now, this API only\n> handles PERST#. But if another vendor tries to use it and if they need other\n> properties such as PHY, clocks etc... those resources should be fetched\n> optionally only by this helper. But if the controller has a hard dependency on\n> those resources, the driver will fail to operate.\n> \n> I don't think we can fix this limitation though and those platforms should\n> ensure that the resource dependency is correctly modeled in DT binding and\n> the DTS is validated properly. It'd be good to mention this in the kernel doc of\n> this API.\n\nOk, I will add a NOTE for this in this API description.\n\n> \n> > +\tif (IS_ERR(reset))\n> > +\t\treturn PTR_ERR(reset);\n> > +\n> > +\tport = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> > +\tif (!port)\n> > +\t\treturn -ENOMEM;\n> > +\n> > +\tport->reset = reset;\n> > +\tINIT_LIST_HEAD(&port->list);\n> > +\tlist_add_tail(&port->list, &bridge->ports);\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> > +/**\n> > + * pci_host_common_parse_ports - Parse Root Port nodes from device\n> > +tree\n> > + * @dev: Device pointer\n> > + * @bridge: PCI host bridge\n> > + *\n> > + * This function iterates through child nodes of the host bridge and\n> > +parses\n> > + * Root Port properties (currently only reset GPIO).\n> > + *\n> > + * Returns: 0 on success, -ENOENT if no ports found, other negative\n> > +error codes\n> > + * on failure\n> > + */\n> > +int pci_host_common_parse_ports(struct device *dev, struct\n> > +pci_host_bridge *bridge) {\n> > +\tint ret = -ENOENT;\n> > +\n> > +\tfor_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> > +\t\tif (!of_node_is_type(of_port, \"pci\"))\n> > +\t\t\tcontinue;\n> > +\t\tret = pci_host_common_parse_port(dev, bridge, of_port);\n> > +\t\tif (ret)\n> > +\t\t\treturn ret;\n> \n> As Sashiko flagged, you need to make sure that devm_add_action_or_reset()\n> is added even during the error path:\n\nYes, it needs to be fixed. We can handle it with the following two methods, I am not sure which method is better or more preferable?\n\n#1: register cleanup action after first successful port parse and use cleanup_registered flag to avoid duplicate register.\n    int ret = -ENOENT;    \n    bool cleanup_registered = false;\n\n    for_each_available_child_of_node_scoped(dev->of_node, of_port) {\n        if (!of_node_is_type(of_port, \"pci\"))\n            continue;\n        ret = pci_host_common_parse_port(dev, bridge, of_port);\n        if (ret)\n            return ret;\n\n        /* Register cleanup action after first successful port parse */\n        if (!cleanup_registered) {\n            ret = devm_add_action_or_reset(dev,\n                               pci_host_common_delete_ports,\n                               &bridge->ports);\n            if (ret)\n                return ret;\n            cleanup_registered = true;\n        }\n    }\n\n#2: call devm_add_action to register cleanup action before the loop begins.\n\tret = devm_add_action(dev, pci_host_common_delete_ports,\n\t\t\t      &bridge->ports);\n\tif (ret)\n\t\treturn ret;\n\n\tret = -ENOENT;\n\tfor_each_available_child_of_node_scoped(dev->of_node, of_port) {\n\t\tif (!of_node_is_type(of_port, \"pci\"))\n\t\t\tcontinue;\n\t\tret = pci_host_common_parse_port(dev, bridge, of_port);\n\t\tif (ret)\n\t\t\treturn ret;\n\t}\n\nBest Regards\nSherry\n\n> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsashiko\n> .dev%2F%23%2Fpatchset%2F20260407104154.2842132-1-\n> sherry.sun%2540nxp.com%3Fpart%3D2&data=05%7C02%7Csherry.sun%40nx\n> p.com%7Ca19d6997cb63454afd7808de94a961fe%7C686ea1d3bc2b4c6fa92cd\n> 99c5c301635%7C0%7C0%7C639111652420710900%7CUnknown%7CTWFpbG\n> Zsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiI\n> sIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=P4Vz%2B7kH\n> i07bzBnR1w4smYzRWDKPbzQsEcJXqEGyzP4%3D&reserved=0\n> \n> - Mani\n> \n> > +\t}\n> > +\n> > +\tif (ret)\n> > +\t\treturn ret;\n> > +\n> > +\treturn devm_add_action_or_reset(dev,\n> pci_host_common_delete_ports,\n> > +\t\t\t\t\t&bridge->ports);\n> > +}\n> > +EXPORT_SYMBOL_GPL(pci_host_common_parse_ports);\n> > +\n> >  static void gen_pci_unmap_cfg(void *ptr)  {\n> >  \tpci_ecam_free((struct pci_config_window *)ptr); diff --git\n> > a/drivers/pci/controller/pci-host-common.h\n> > b/drivers/pci/controller/pci-host-common.h\n> > index b5075d4bd7eb..37714bedb625 100644\n> > --- a/drivers/pci/controller/pci-host-common.h\n> > +++ b/drivers/pci/controller/pci-host-common.h\n> > @@ -12,6 +12,22 @@\n> >\n> >  struct pci_ecam_ops;\n> >\n> > +/**\n> > + * struct pci_host_port - Generic Root Port properties\n> > + * @list: List node for linking multiple ports\n> > + * @reset: GPIO descriptor for PERST# signal\n> > + *\n> > + * This structure contains common properties that can be parsed from\n> > + * Root Port device tree nodes.\n> > + */\n> > +struct pci_host_port {\n> > +\tstruct list_head\tlist;\n> > +\tstruct gpio_desc\t*reset;\n> > +};\n> > +\n> > +void pci_host_common_delete_ports(void *data); int\n> > +pci_host_common_parse_ports(struct device *dev, struct\n> > +pci_host_bridge *bridge);\n> > +\n> >  int pci_host_common_probe(struct platform_device *pdev);  int\n> > pci_host_common_init(struct platform_device *pdev,\n> >  \t\t\t struct pci_host_bridge *bridge,\n> > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index\n> > eaa4a3d662e8..629ae08b7d35 100644\n> > --- a/drivers/pci/probe.c\n> > +++ b/drivers/pci/probe.c\n> > @@ -677,6 +677,7 @@ static void pci_init_host_bridge(struct\n> > pci_host_bridge *bridge)  {\n> >  \tINIT_LIST_HEAD(&bridge->windows);\n> >  \tINIT_LIST_HEAD(&bridge->dma_ranges);\n> > +\tINIT_LIST_HEAD(&bridge->ports);\n> >\n> >  \t/*\n> >  \t * We assume we can manage these PCIe features.  Some systems\n> may\n> > diff --git a/include/linux/pci.h b/include/linux/pci.h index\n> > 8f63de38f2d2..a73ea81ce88f 100644\n> > --- a/include/linux/pci.h\n> > +++ b/include/linux/pci.h\n> > @@ -636,6 +636,7 @@ struct pci_host_bridge {\n> >  \tint\t\tdomain_nr;\n> >  \tstruct list_head windows;\t/* resource_entry */\n> >  \tstruct list_head dma_ranges;\t/* dma ranges resource list */\n> > +\tstruct list_head ports;\t\t/* Root Port list (pci_host_port) */\n> >  #ifdef CONFIG_PCI_IDE\n> >  \tu16 nr_ide_streams; /* Max streams possibly active in\n> @ide_stream_ida */\n> >  \tstruct ida ide_stream_ida;\n> > --\n> > 2.37.1\n> >\n> \n> --\n> மணிவண்ணன் சதாசிவம்","headers":{"Return-Path":"\n <linux-pci+bounces-52121-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256\n header.s=selector1 header.b=B5VeWScg;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52121-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com\n header.b=\"B5VeWScg\"","smtp.subspace.kernel.org;\n arc=fail smtp.client-ip=52.101.83.36","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=nxp.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=nxp.com","dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=nxp.com;"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frCy00Lprz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 08 Apr 2026 16:36:07 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 9F101301D06C\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  8 Apr 2026 06:34:09 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id ED85E35BDDB;\n\tWed,  8 Apr 2026 06:34:08 +0000 (UTC)","from GVXPR05CU001.outbound.protection.outlook.com\n (mail-swedencentralazon11013036.outbound.protection.outlook.com\n [52.101.83.36])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id B3DA9355F39;\n\tWed,  8 Apr 2026 06:34:05 +0000 (UTC)","from VI0PR04MB12114.eurprd04.prod.outlook.com\n (2603:10a6:800:315::13) by AM9PR04MB8635.eurprd04.prod.outlook.com\n (2603:10a6:20b:43e::19) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.18; Wed, 8 Apr\n 2026 06:34:02 +0000","from VI0PR04MB12114.eurprd04.prod.outlook.com\n ([fe80::feda:fd0e:147f:f994]) by VI0PR04MB12114.eurprd04.prod.outlook.com\n ([fe80::feda:fd0e:147f:f994%6]) with mapi id 15.20.9769.018; Wed, 8 Apr 2026\n 06:34:02 +0000"],"ARC-Seal":["i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775630048; cv=fail;\n b=aCNTZZ+XU6Fb10JetgfBfybXX8VlRdv2/ZbFDQyhK+AOOlr/uLTLEzRZc04qqz0WPXauVm8nFI938kpojIGh+4n6/cINcPFNpxPWtLyDYRhlJyqXKYsnb9L2EgrIB4zQ1OuXyePyB/sLSVc4iMuW6R7zWvdyrTqYTg9fmQT2mCk=","i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;\n b=afwRbqQ3L503KRWCHBmwzHhAWhsb0yOVac+fRISkLCKgRawXxZgJXqFmyeumrCWTFGHvTADI7SlQJU9qntEDfbh1Zf1QmjP8vv+LXLTYyn7B42quwfPwLPmfozLkCJ+89sy7gQEGtt9KcdNb3gGK17E2kl/QOXa3weudpWIxhEYFuiW3icEKgMlyyFmuVpzTxBqcq/3txRY6V+BwA+qF7hgeyXf0LFNSm5DvEO58BqAE5Ag6E1LgVgu+xToEAVmUbrmNS0AmipzU3tcUY43EkmSHp8WPOX8CGJqR2kHwFFItGvYxnExsJlI3+PYFVDUvSyt83Lr+9fBljEbQXXUxdg=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775630048; c=relaxed/simple;\n\tbh=+GTMvgHgu9D/Ho+j6a22xTePPq1I5jp22hbCK4Hq0bc=;\n\th=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To:\n\t Content-Type:MIME-Version;\n b=hD/WXjihnFY3Sw6iPvrnfat6P2yzIkHRq7tk1cClhwHGSvt1sLaiB0+J6RXtvffkwSqTyLfX3/YkPlReh5Tgzz1RpSWMPBTnMo8j/SObERPiiOrtnSQPVSvHFqRINrBw1rdL5bjPW+1Dh8RoMGtez5pmRkxNJVZmxgDRAlDCc7c=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector10001;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;\n bh=+GTMvgHgu9D/Ho+j6a22xTePPq1I5jp22hbCK4Hq0bc=;\n b=lYHZ5TUCn5j0okOD2x8bbqUgGfv2l+r7ocGxOSaQXz/Z/HypdUGtkSRNfwxjnjb+8IhFHyBvLoEsL9ZwOSVzfTifEdv2JOVlZulBPaDoN93wrmslHnLki/1Px+gGSBetFCLIFTjzNHdo2oszSi1iLhH5ngb2S9VJj8Ak/n3QL+GSdqs4A7iYGweHV/wHXYowUV5H3XHhngWHMr7czrcF2lZXyDZJQOo5MHLXxLbY6r3OKxtDqXugpSQvmfLFz0frs2UvdSZbTnYvtYDuyHArTcBoRBYrP8SZiwXIyz2NBUT7Hj0ZpYZszpqSMO6JV8wwsDl34R1zPNgPiJwNP7RrLg=="],"ARC-Authentication-Results":["i=2; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=nxp.com;\n spf=pass smtp.mailfrom=nxp.com;\n dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com\n header.b=B5VeWScg; arc=fail smtp.client-ip=52.101.83.36","i=1; mx.microsoft.com 1; spf=pass\n smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass\n header.d=nxp.com; arc=none"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=+GTMvgHgu9D/Ho+j6a22xTePPq1I5jp22hbCK4Hq0bc=;\n b=B5VeWScgSis0tfZuczyADWvMHSx3ETNzISnBldSqhPAaRQMfuo9mQqGESNg5Sr0tpAhnx5EJc2HcrhjkT+LxgidFe54aKzhYjJNdmtpmJkUeJvn8dHda2wJS4WE+g+bQ+TtoJ/EliDOIiqVbJ62fIThVrakxthi6aVTdz3O+/E5xkZS9qmU0s8ZqGCuNJYbB0BxJduQhOs+obAtRegCGGW2tx2+pXms/4wlhnBvS3pPGusPHBVo6ZPwuxknbzZZpBWwQHI+MvMl/lC97hBU+aU06ju3YKFl3BnXdb8jqOIIKDmXbjDN/GGfG0sq9x/xMfhC4ENjVNO4w29S57LCyEA==","From":"Sherry Sun <sherry.sun@nxp.com>","To":"Manivannan Sadhasivam <mani@kernel.org>","CC":"\"robh@kernel.org\" <robh@kernel.org>, \"krzk+dt@kernel.org\"\n\t<krzk+dt@kernel.org>, \"conor+dt@kernel.org\" <conor+dt@kernel.org>, Frank Li\n\t<frank.li@nxp.com>, \"s.hauer@pengutronix.de\" <s.hauer@pengutronix.de>,\n\t\"kernel@pengutronix.de\" <kernel@pengutronix.de>, \"festevam@gmail.com\"\n\t<festevam@gmail.com>, \"lpieralisi@kernel.org\" <lpieralisi@kernel.org>,\n\t\"kwilczynski@kernel.org\" <kwilczynski@kernel.org>, \"bhelgaas@google.com\"\n\t<bhelgaas@google.com>, Hongxing Zhu <hongxing.zhu@nxp.com>,\n\t\"l.stach@pengutronix.de\" <l.stach@pengutronix.de>, \"imx@lists.linux.dev\"\n\t<imx@lists.linux.dev>, \"linux-pci@vger.kernel.org\"\n\t<linux-pci@vger.kernel.org>, \"linux-arm-kernel@lists.infradead.org\"\n\t<linux-arm-kernel@lists.infradead.org>, \"devicetree@vger.kernel.org\"\n\t<devicetree@vger.kernel.org>, \"linux-kernel@vger.kernel.org\"\n\t<linux-kernel@vger.kernel.org>","Subject":"RE: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Thread-Topic":"[PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Thread-Index":"AQHcxnsnHAAJHNaLCkmHx9RiuF3pD7XTl3qAgAEbHYA=","Date":"Wed, 8 Apr 2026 06:34:02 +0000","Message-ID":"\n <VI0PR04MB12114A60C4A7E43ED62A32B04925BA@VI0PR04MB12114.eurprd04.prod.outlook.com>","References":"<20260407104154.2842132-1-sherry.sun@nxp.com>\n <20260407104154.2842132-3-sherry.sun@nxp.com>\n <lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>","In-Reply-To":"<lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>","Accept-Language":"zh-CN, en-US","Content-Language":"en-US","X-MS-Has-Attach":"","X-MS-TNEF-Correlator":"","authentication-results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256\n header.s=selector1 header.b=B5VeWScg;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52121-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com\n header.b=\"B5VeWScg\"","smtp.subspace.kernel.org;\n arc=fail smtp.client-ip=52.101.83.36","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=nxp.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=nxp.com","dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=nxp.com;"],"x-ms-publictraffictype":"Email","x-ms-traffictypediagnostic":"VI0PR04MB12114:EE_|AM9PR04MB8635:EE_","x-ms-office365-filtering-correlation-id":"c4e12835-52d9-45e2-8362-08de9538d2d0","x-ms-exchange-senderadcheck":"1","x-ms-exchange-antispam-relay":"0","x-microsoft-antispam":"\n BCL:0;ARA:13230040|19092799006|7416014|376014|1800799024|366016|38070700021|22082099003|56012099003|18002099003;","x-microsoft-antispam-message-info":"\n 2aY+WADvOxWg2ZMJnUDZ6oQ6hASI0XdIgvY+r5kihLF/GIihwfAr+goSm7fP1KnzY6OyHiQnW4QdRdkTiPw0CricKVKfDILBqSVSm0md5+aWgKNRMWje5s3F1R3bd0b8r7QN6VVjPIHmFcRCKu+0iDd8yj5Es6N/fAghj/WDvcYhWUkBiI8Z+hyLM3NjrcbhHL2wJeVCuwUMC3gwX+ujxYdfnea9pkRRSGFmEfSsjj4kZz+g7e9sVNmXrPm3hRR66qLh+/bw9RIS/qYuWXXw/pfgVHy1rf7qrrM/YITvp2FXj4h79P4SlxVF54FLAnb/OHX+bcjTGA5f/dsQ6vDayzGyEjCL4am18eV51bsLQXr8uY2aK9k8M/A4+sN4PernuIy13zCLCuUBvqlc/lTWfBM4LK7zGHSqwwGiE22Qmp/adx8sQWLG+8tIOgluze+cYBX8vtnPPrSD1P5FcIAy0wKNDB2QhddkVz701n4hL3NvM+5x3LaAtXItovVjT3CmtPXTYBkJZMtkAqCBYvSIBAwwuTGzRV6rrtI7isFKMBl1rFhEZt2NlfnMncswqYif/Kbtr3npT9lJQzRmOfaiAleJSDGtsbsZ9Bop+ed4T/tYM4JKBg8NmVNmkWtti+mlxSjFAMDBk6DTnKC9gJFGxKJnUGpB9P4pQkzI45HYP24iha0riAMhRCIFfrStdDq5MZu5AnprdA62wV7QtXGLxbMR83zcuHcx81F8K5OHYv2g8Ab8qNm5ZXD5vFIzlPVq0mIvegQgsImqJjK2g2FvZCzr6lbxvafppW11UtbVVJE=","x-forefront-antispam-report":"\n CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI0PR04MB12114.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(19092799006)(7416014)(376014)(1800799024)(366016)(38070700021)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101;","x-ms-exchange-antispam-messagedata-chunkcount":"1","x-ms-exchange-antispam-messagedata-0":"=?utf-8?q?hm6re04VRdNPZiczDy/cTVFlc/Mc?=\n\t=?utf-8?q?4kBOuORmb0aqolwFtKqMyOyER5QmctPjQ5DETMjOOB21vBLKEvmPQEpCmU8eGT2Ce?=\n\t=?utf-8?q?3rX0Kv5nSGbHEOFHcI7uSOShRC8aVduFgo0hrvB+xMFrvOGRcHYp2A2q/6zphJdtj?=\n\t=?utf-8?q?CdHyqXri4FrTXnYBT2RgIb/Rd5mW+2hmdPSOKtWGuCl3BosurgaHbvRcmryKLxFnW?=\n\t=?utf-8?q?HVdUFfIbmv7p4bQdgVdc8KBm05Jf1MjfalVT7N4iGk0TN1QMdyo3zsU7mcWacFlvf?=\n\t=?utf-8?q?27iq2xKjPr4WsRhk6oqiiLaL0XJubc8XKGsU4KpKDmu1mDh2Yx8xa1EJtbEhUij90?=\n\t=?utf-8?q?0G+cFGFYfeqorRUu3wPzA/ti4VNrCdlt9wkgxYbdcSYcbBv882dQ/jFfg+Sb5PKtm?=\n\t=?utf-8?q?S5f+A4fVSo1y/0DTc9HA4cJ5pTHb+4jvFalhv5EF9WhiNExwACjrsBHr9hTl/WQC3?=\n\t=?utf-8?q?PnU8SPUdb7fFjMsLgf7f2Tx17ZcaSaEoki7uYE5kpj8KBs78M7rDQg5Eawr3AiryE?=\n\t=?utf-8?q?edDA8mM6mj/HqQhjfIweqsrP4dekB9PPR6flp/cpAP6YMnvSjdcFR9bJo/gz40PcM?=\n\t=?utf-8?q?pAMkNNauRaGh4/uIzM/w+VpsUQHxJq+1t3kVXyztaqILrQ4ZeiiWBX5UIh7eFpEhB?=\n\t=?utf-8?q?ZtswPGXkFoJ2mzKgHAqvtMtu9cBhrY9FX3VXncjwpWzXQzUWlBKi9fvPHAXsxBvxK?=\n\t=?utf-8?q?67cg+FY7wUJbIx9/GwAvvrhzwDbsIKcUVytriOGeDsbttJYDCIY979ibzStgaWr1s?=\n\t=?utf-8?q?A7fqqKrx+pu+kMxZO5/CxXYFko5pLXQ9wy8meQemhYGIPYdPeYRj8Q9PXDT9NYzv8?=\n\t=?utf-8?q?6Y7CCq/vRE2qZi8H+fsWa7MRGrQpCtbDoCFyNTMlGvMta19woq1nyzFyg6bqbNIW3?=\n\t=?utf-8?q?zSbU23SKxUt1eD7Xozs5MqFB10EgJo9ddxfHYQuEiEvALdKc6is8NBeP5IYgnUQRq?=\n\t=?utf-8?q?Pgnie7EE/lX5QomI9sgn4tuTPD466OU4EkYcn2/YaGiTVYobwpAAmMdaMINu2o8oW?=\n\t=?utf-8?q?d0J3ext0BkZJ+PcPGS4qbqlseGobmudjm63+Isa5swDfRAJj4n/q2ftGhtRw9T2DJ?=\n\t=?utf-8?q?0GDISovlZpCbaflI/PT47m6UYOBWwoyqndYTjCyT1842bIZvG80odAjPDphGDLdlc?=\n\t=?utf-8?q?fAbELt5xQv5nTpaAbms5NRhmaWpP2jiNK/oNB2ZupNPORb32R0aZrkN1QN25S1erc?=\n\t=?utf-8?q?Af2BDA1F+ZyumENmYq5Q7ja9SEQmxdttaQJCYdOhpLxfEFpOAAdwCnHbOOky9nSID?=\n\t=?utf-8?q?Re/Vgd5QkXkmFvOHSx6pTeQ3Oh3sjhFBaQkjOMas5E4CTLVd4moOTNJFb9eJ+ouks?=\n\t=?utf-8?q?Gh4EvN8kC+C6iNnIYYbT18yzta7RttFVj+2EBsxnnYPnDvIy9gBKdCg5z2eAhMTNy?=\n\t=?utf-8?q?1P4WAmsrTDJju8fni/9HhzIShGfuJIQUI5QuAh6/FrngH/lB2AWxRu+KmkIi8USBB?=\n\t=?utf-8?q?IKCaReMh4VWy3puho+gepPY8bhjNVJxr0saXDNMiP0qqIpYcD047KGN0K4bG8vL1a?=\n\t=?utf-8?q?A4uS/QAJImco24pJ5wZuqzqOgruVlhgKkr3/4EYfq3tvOxYJY8Eg4vAq94nrqNoSF?=\n\t=?utf-8?q?SbL1CnLHyk7nfIJ8BqvrLWCCN2wUHPBQj4QeiE1Fyr9DFpLWR4LoxjfLjzop1KQmf?=\n\t=?utf-8?q?AHCLltvUGV?=","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","X-OriginatorOrg":"nxp.com","X-MS-Exchange-CrossTenant-AuthAs":"Internal","X-MS-Exchange-CrossTenant-AuthSource":"VI0PR04MB12114.eurprd04.prod.outlook.com","X-MS-Exchange-CrossTenant-Network-Message-Id":"\n c4e12835-52d9-45e2-8362-08de9538d2d0","X-MS-Exchange-CrossTenant-originalarrivaltime":"08 Apr 2026 06:34:02.0470\n (UTC)","X-MS-Exchange-CrossTenant-fromentityheader":"Hosted","X-MS-Exchange-CrossTenant-id":"686ea1d3-bc2b-4c6f-a92c-d99c5c301635","X-MS-Exchange-CrossTenant-mailboxtype":"HOSTED","X-MS-Exchange-CrossTenant-userprincipalname":"\n ioBp0M4KMQ0GbtdbybuD92X+cdCmTnyUx7HynFVeI6PFjbPVaXCYB/Tayg3Qao9rtI2e3lO92iwSS57rEsL2uQ==","X-MS-Exchange-Transport-CrossTenantHeadersStamped":"AM9PR04MB8635"}},{"id":3674793,"web_url":"http://patchwork.ozlabs.org/comment/3674793/","msgid":"<yijf6mwclpx6n7giucgykxvrm73baicy2urhzns34sxgloli3z@ygose2qrgvuz>","list_archive_url":null,"date":"2026-04-08T14:10:19","subject":"Re: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","submitter":{"id":78905,"url":"http://patchwork.ozlabs.org/api/people/78905/","name":"Manivannan Sadhasivam","email":"mani@kernel.org"},"content":"On Wed, Apr 08, 2026 at 06:34:02AM +0000, Sherry Sun wrote:\n\n[...]\n\n> > > +/**\n> > > + * pci_host_common_parse_port - Parse a single Root Port node\n> > > + * @dev: Device pointer\n> > > + * @bridge: PCI host bridge\n> > > + * @node: Device tree node of the Root Port\n> > > + *\n> > > + * Returns: 0 on success, negative error code on failure  */ static\n> > > +int pci_host_common_parse_port(struct device *dev,\n> > > +\t\t\t\t      struct pci_host_bridge *bridge,\n> > > +\t\t\t\t      struct device_node *node)\n> > > +{\n> > > +\tstruct pci_host_port *port;\n> > > +\tstruct gpio_desc *reset;\n> > > +\n> > > +\treset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> > > +\t\t\t\t      \"reset\", GPIOD_ASIS, \"PERST#\");\n> > \n> > Sorry, I missed this earlier.\n> > \n> > Since PERST# is optional, you cannot reliably detect whether the Root Port\n> > binding intentionally skipped the PERST# GPIO or legacy binding is used, just\n> > by checking for PERST# in Root Port node.\n> > \n> > So this helper should do 3 things:\n> > \n> > 1. If PERST# is found in Root Port node, use it.\n> > 2. If not, check the RC node and if present, return -ENOENT to fallback to the\n> > legacy binding.\n> > 3. If not found in both nodes, assume that the PERST# is not present in the\n> > design, and proceed with parsing Root Port binding further.\n> \n> Hi Mani, understand, does the following code looks ok for above three cases?\n> \n>     /* Check if PERST# is present in Root Port node */\n>     reset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n>                       \"reset\", GPIOD_ASIS, \"PERST#\");\n>     if (IS_ERR(reset)) {\n>         /* If error is not -ENOENT, it's a real error */\n>         if (PTR_ERR(reset) != -ENOENT)\n>             return PTR_ERR(reset);\n> \n>         /* PERST# not found in Root Port node, check RC node */\n>         rc_has_reset = of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n>                    of_property_read_bool(dev->of_node, \"reset-gpio\");\n\nJust:\n\t\tif (of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n\t\t    of_property_read_bool(dev->of_node, \"reset-gpio\")) {\n\t\t\treturn -ENOENT;\n\t\t} \n\n>         if (rc_has_reset)\n>             return -ENOENT;\n> \n>         /* No PERST# in either node, assume not present in design */\n>         reset = NULL;\n>     }\n> \n>     port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n>     if (!port)\n>         return -ENOMEM;\n> ...\n> \n> > \n> > But there is one more important limitation here. Right now, this API only\n> > handles PERST#. But if another vendor tries to use it and if they need other\n> > properties such as PHY, clocks etc... those resources should be fetched\n> > optionally only by this helper. But if the controller has a hard dependency on\n> > those resources, the driver will fail to operate.\n> > \n> > I don't think we can fix this limitation though and those platforms should\n> > ensure that the resource dependency is correctly modeled in DT binding and\n> > the DTS is validated properly. It'd be good to mention this in the kernel doc of\n> > this API.\n> \n> Ok, I will add a NOTE for this in this API description.\n> \n> > \n> > > +\tif (IS_ERR(reset))\n> > > +\t\treturn PTR_ERR(reset);\n> > > +\n> > > +\tport = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> > > +\tif (!port)\n> > > +\t\treturn -ENOMEM;\n> > > +\n> > > +\tport->reset = reset;\n> > > +\tINIT_LIST_HEAD(&port->list);\n> > > +\tlist_add_tail(&port->list, &bridge->ports);\n> > > +\n> > > +\treturn 0;\n> > > +}\n> > > +\n> > > +/**\n> > > + * pci_host_common_parse_ports - Parse Root Port nodes from device\n> > > +tree\n> > > + * @dev: Device pointer\n> > > + * @bridge: PCI host bridge\n> > > + *\n> > > + * This function iterates through child nodes of the host bridge and\n> > > +parses\n> > > + * Root Port properties (currently only reset GPIO).\n> > > + *\n> > > + * Returns: 0 on success, -ENOENT if no ports found, other negative\n> > > +error codes\n> > > + * on failure\n> > > + */\n> > > +int pci_host_common_parse_ports(struct device *dev, struct\n> > > +pci_host_bridge *bridge) {\n> > > +\tint ret = -ENOENT;\n> > > +\n> > > +\tfor_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> > > +\t\tif (!of_node_is_type(of_port, \"pci\"))\n> > > +\t\t\tcontinue;\n> > > +\t\tret = pci_host_common_parse_port(dev, bridge, of_port);\n> > > +\t\tif (ret)\n> > > +\t\t\treturn ret;\n> > \n> > As Sashiko flagged, you need to make sure that devm_add_action_or_reset()\n> > is added even during the error path:\n> \n> Yes, it needs to be fixed. We can handle it with the following two methods, I am not sure which method is better or more preferable?\n> \n> #1: register cleanup action after first successful port parse and use cleanup_registered flag to avoid duplicate register.\n>     int ret = -ENOENT;    \n>     bool cleanup_registered = false;\n> \n>     for_each_available_child_of_node_scoped(dev->of_node, of_port) {\n>         if (!of_node_is_type(of_port, \"pci\"))\n>             continue;\n>         ret = pci_host_common_parse_port(dev, bridge, of_port);\n>         if (ret)\n>             return ret;\n> \n>         /* Register cleanup action after first successful port parse */\n>         if (!cleanup_registered) {\n>             ret = devm_add_action_or_reset(dev,\n>                                pci_host_common_delete_ports,\n>                                &bridge->ports);\n\nEven if you register devm_add_action_or_reset(), it won't be called when\npci_host_common_parse_port() fails since the legacy fallback will be used.\n\nSo you need to manually call pci_host_common_delete_ports() in the error path.\n\n- Mani","headers":{"Return-Path":"\n <linux-pci+bounces-52158-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=up9YGgAc;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-52158-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"up9YGgAc\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frQ4T5k7Gz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 00:12:25 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 1317F307C7D3\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  8 Apr 2026 14:10:32 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 8EE123D301F;\n\tWed,  8 Apr 2026 14:10:29 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 696503D2FE1;\n\tWed,  8 Apr 2026 14:10:29 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 4EFE9C19421;\n\tWed,  8 Apr 2026 14:10:23 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775657429; cv=none;\n b=aaw0dwVm573hqLNdPDs+n3U5bSHp2h7ph+dUMD3ON74t76kOikVuIp4ZCd5ATNpiWt6ZIjQX6FFQ+o0HLtvniau82q+/0LIpe//nB4Afe0YRhCa3P8H4BJ6ndE1qV7CXmkzRiNwlr/6xe8tAh74nlRtmxHAarldl7yK2M1kU4N4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775657429; c=relaxed/simple;\n\tbh=i2Dbh2ANq28qBSTN2bv54+q1a50BxTE9oJVrrroT5ZY=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=AVEUYNuvHOdBxfzZJi5/WcllD/9xWDw98jUhFz0THFbdr1VhkrPqJ2kEJPS/axqUILdMJDMURzF9dU9kvD/HifRa2vNGVAMh8gFjkYVq84psArY4IOYE1LNkN5sD7sOi5DMv19FUxINo4kori9VBIvxH+ZAFAntxylq2kkD0kdg=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=up9YGgAc; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775657429;\n\tbh=i2Dbh2ANq28qBSTN2bv54+q1a50BxTE9oJVrrroT5ZY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=up9YGgAc7IHMuoBdh3ONWLG9qnGSwvEiHxfi39HKRZ8mywBhKMEm94Rlzn1VuzHDT\n\t 33HmtrnISdZapkbYCiHQjrmR+XSrquFED4gadV3DPKdWRpj+a/hMReRETWCsZWNl/u\n\t LriCmU95F2JEOGNheFI41iQL3lQ9uv0JkXa8JtM+/1wz1RyGvOL8k24ogA4dd1fe8k\n\t EmnSVEpf8u+JxK3wcf8oYdNQhCF1saI99/xBesze8W5A8sKEDM2Q5iS/EogyuGBgBA\n\t PeOr16P2iVdIVOPPvwAsRk5gcFTlSMaZ8STdL2vqIgXSmSlUJS604tkBltVO1F4cQ+\n\t 0yYXyL5qWsgew==","Date":"Wed, 8 Apr 2026 19:40:19 +0530","From":"Manivannan Sadhasivam <mani@kernel.org>","To":"Sherry Sun <sherry.sun@nxp.com>","Cc":"\"robh@kernel.org\" <robh@kernel.org>,\n\t\"krzk+dt@kernel.org\" <krzk+dt@kernel.org>,\n \"conor+dt@kernel.org\" <conor+dt@kernel.org>,\n\tFrank Li <frank.li@nxp.com>,\n \"s.hauer@pengutronix.de\" <s.hauer@pengutronix.de>,\n\t\"kernel@pengutronix.de\" <kernel@pengutronix.de>,\n \"festevam@gmail.com\" <festevam@gmail.com>,\n\t\"lpieralisi@kernel.org\" <lpieralisi@kernel.org>,\n \"kwilczynski@kernel.org\" <kwilczynski@kernel.org>,\n\t\"bhelgaas@google.com\" <bhelgaas@google.com>,\n Hongxing Zhu <hongxing.zhu@nxp.com>,\n\t\"l.stach@pengutronix.de\" <l.stach@pengutronix.de>,\n \"imx@lists.linux.dev\" <imx@lists.linux.dev>,\n\t\"linux-pci@vger.kernel.org\" <linux-pci@vger.kernel.org>,\n\t\"linux-arm-kernel@lists.infradead.org\"\n <linux-arm-kernel@lists.infradead.org>,\n \"devicetree@vger.kernel.org\" <devicetree@vger.kernel.org>,\n\t\"linux-kernel@vger.kernel.org\" <linux-kernel@vger.kernel.org>","Subject":"Re: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Message-ID":"<yijf6mwclpx6n7giucgykxvrm73baicy2urhzns34sxgloli3z@ygose2qrgvuz>","References":"<20260407104154.2842132-1-sherry.sun@nxp.com>\n <20260407104154.2842132-3-sherry.sun@nxp.com>\n <lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>\n <VI0PR04MB12114A60C4A7E43ED62A32B04925BA@VI0PR04MB12114.eurprd04.prod.outlook.com>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"\n <VI0PR04MB12114A60C4A7E43ED62A32B04925BA@VI0PR04MB12114.eurprd04.prod.outlook.com>"}},{"id":3675052,"web_url":"http://patchwork.ozlabs.org/comment/3675052/","msgid":"<VI0PR04MB1211419BB996B4790AE04170F92582@VI0PR04MB12114.eurprd04.prod.outlook.com>","list_archive_url":null,"date":"2026-04-09T02:58:21","subject":"RE: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","submitter":{"id":77063,"url":"http://patchwork.ozlabs.org/api/people/77063/","name":"Sherry Sun","email":"sherry.sun@nxp.com"},"content":"> On Wed, Apr 08, 2026 at 06:34:02AM +0000, Sherry Sun wrote:\n> \n> [...]\n> \n> > > > +/**\n> > > > + * pci_host_common_parse_port - Parse a single Root Port node\n> > > > + * @dev: Device pointer\n> > > > + * @bridge: PCI host bridge\n> > > > + * @node: Device tree node of the Root Port\n> > > > + *\n> > > > + * Returns: 0 on success, negative error code on failure  */\n> > > > +static int pci_host_common_parse_port(struct device *dev,\n> > > > +\t\t\t\t      struct pci_host_bridge *bridge,\n> > > > +\t\t\t\t      struct device_node *node) {\n> > > > +\tstruct pci_host_port *port;\n> > > > +\tstruct gpio_desc *reset;\n> > > > +\n> > > > +\treset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> > > > +\t\t\t\t      \"reset\", GPIOD_ASIS, \"PERST#\");\n> > >\n> > > Sorry, I missed this earlier.\n> > >\n> > > Since PERST# is optional, you cannot reliably detect whether the\n> > > Root Port binding intentionally skipped the PERST# GPIO or legacy\n> > > binding is used, just by checking for PERST# in Root Port node.\n> > >\n> > > So this helper should do 3 things:\n> > >\n> > > 1. If PERST# is found in Root Port node, use it.\n> > > 2. If not, check the RC node and if present, return -ENOENT to\n> > > fallback to the legacy binding.\n> > > 3. If not found in both nodes, assume that the PERST# is not present\n> > > in the design, and proceed with parsing Root Port binding further.\n> >\n> > Hi Mani, understand, does the following code looks ok for above three\n> cases?\n> >\n> >     /* Check if PERST# is present in Root Port node */\n> >     reset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> >                       \"reset\", GPIOD_ASIS, \"PERST#\");\n> >     if (IS_ERR(reset)) {\n> >         /* If error is not -ENOENT, it's a real error */\n> >         if (PTR_ERR(reset) != -ENOENT)\n> >             return PTR_ERR(reset);\n> >\n> >         /* PERST# not found in Root Port node, check RC node */\n> >         rc_has_reset = of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n> >                    of_property_read_bool(dev->of_node, \"reset-gpio\");\n> \n> Just:\n> \t\tif (of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n> \t\t    of_property_read_bool(dev->of_node, \"reset-gpio\")) {\n> \t\t\treturn -ENOENT;\n> \t\t}\n\nOk, will do.\n\n> \n> >         if (rc_has_reset)\n> >             return -ENOENT;\n> >\n> >         /* No PERST# in either node, assume not present in design */\n> >         reset = NULL;\n> >     }\n> >\n> >     port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> >     if (!port)\n> >         return -ENOMEM;\n> > ...\n> >\n> > >\n> > > But there is one more important limitation here. Right now, this API\n> > > only handles PERST#. But if another vendor tries to use it and if\n> > > they need other properties such as PHY, clocks etc... those\n> > > resources should be fetched optionally only by this helper. But if\n> > > the controller has a hard dependency on those resources, the driver will\n> fail to operate.\n> > >\n> > > I don't think we can fix this limitation though and those platforms\n> > > should ensure that the resource dependency is correctly modeled in\n> > > DT binding and the DTS is validated properly. It'd be good to\n> > > mention this in the kernel doc of this API.\n> >\n> > Ok, I will add a NOTE for this in this API description.\n> >\n> > >\n> > > > +\tif (IS_ERR(reset))\n> > > > +\t\treturn PTR_ERR(reset);\n> > > > +\n> > > > +\tport = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> > > > +\tif (!port)\n> > > > +\t\treturn -ENOMEM;\n> > > > +\n> > > > +\tport->reset = reset;\n> > > > +\tINIT_LIST_HEAD(&port->list);\n> > > > +\tlist_add_tail(&port->list, &bridge->ports);\n> > > > +\n> > > > +\treturn 0;\n> > > > +}\n> > > > +\n> > > > +/**\n> > > > + * pci_host_common_parse_ports - Parse Root Port nodes from\n> > > > +device tree\n> > > > + * @dev: Device pointer\n> > > > + * @bridge: PCI host bridge\n> > > > + *\n> > > > + * This function iterates through child nodes of the host bridge\n> > > > +and parses\n> > > > + * Root Port properties (currently only reset GPIO).\n> > > > + *\n> > > > + * Returns: 0 on success, -ENOENT if no ports found, other\n> > > > +negative error codes\n> > > > + * on failure\n> > > > + */\n> > > > +int pci_host_common_parse_ports(struct device *dev, struct\n> > > > +pci_host_bridge *bridge) {\n> > > > +\tint ret = -ENOENT;\n> > > > +\n> > > > +\tfor_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> > > > +\t\tif (!of_node_is_type(of_port, \"pci\"))\n> > > > +\t\t\tcontinue;\n> > > > +\t\tret = pci_host_common_parse_port(dev, bridge, of_port);\n> > > > +\t\tif (ret)\n> > > > +\t\t\treturn ret;\n> > >\n> > > As Sashiko flagged, you need to make sure that\n> > > devm_add_action_or_reset() is added even during the error path:\n> >\n> > Yes, it needs to be fixed. We can handle it with the following two methods, I\n> am not sure which method is better or more preferable?\n> >\n> > #1: register cleanup action after first successful port parse and use\n> cleanup_registered flag to avoid duplicate register.\n> >     int ret = -ENOENT;\n> >     bool cleanup_registered = false;\n> >\n> >     for_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> >         if (!of_node_is_type(of_port, \"pci\"))\n> >             continue;\n> >         ret = pci_host_common_parse_port(dev, bridge, of_port);\n> >         if (ret)\n> >             return ret;\n> >\n> >         /* Register cleanup action after first successful port parse */\n> >         if (!cleanup_registered) {\n> >             ret = devm_add_action_or_reset(dev,\n> >                                pci_host_common_delete_ports,\n> >                                &bridge->ports);\n> \n> Even if you register devm_add_action_or_reset(), it won't be called when\n> pci_host_common_parse_port() fails since the legacy fallback will be used.\n> \n> So you need to manually call pci_host_common_delete_ports() in the error\n> path.\n\nGet your point, so seems I should just add the err_cleanup handle path like this, right?\n\n    for_each_available_child_of_node_scoped(dev->of_node, of_port) {\n        if (!of_node_is_type(of_port, \"pci\"))\n            continue;\n        ret = pci_host_common_parse_port(dev, bridge, of_port);\n        if (ret)\n            goto err_cleanup;\n    }\n\n    if (ret)\n        return ret;\n\n    return devm_add_action_or_reset(dev, pci_host_common_delete_ports,\n                    &bridge->ports);\n\nerr_cleanup:\n    pci_host_common_delete_ports(&bridge->ports);\n    return ret;\n\nBest Regards\nSherry","headers":{"Return-Path":"\n <linux-pci+bounces-52187-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256\n header.s=selector1 header.b=c5zLvtvP;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52187-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com\n header.b=\"c5zLvtvP\"","smtp.subspace.kernel.org;\n arc=fail smtp.client-ip=52.101.83.42","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=nxp.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=nxp.com","dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=nxp.com;"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frl6X2zK2z1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 13:00:20 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 5FA0030097DA\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  9 Apr 2026 02:58:29 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A7B2F36AB5A;\n\tThu,  9 Apr 2026 02:58:28 +0000 (UTC)","from GVXPR05CU001.outbound.protection.outlook.com\n (mail-swedencentralazon11013042.outbound.protection.outlook.com\n [52.101.83.42])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id F151F1B4223;\n\tThu,  9 Apr 2026 02:58:26 +0000 (UTC)","from VI0PR04MB12114.eurprd04.prod.outlook.com\n (2603:10a6:800:315::13) by GV1PR04MB10992.eurprd04.prod.outlook.com\n (2603:10a6:150:207::20) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17; Thu, 9 Apr\n 2026 02:58:21 +0000","from VI0PR04MB12114.eurprd04.prod.outlook.com\n ([fe80::feda:fd0e:147f:f994]) by VI0PR04MB12114.eurprd04.prod.outlook.com\n ([fe80::feda:fd0e:147f:f994%6]) with mapi id 15.20.9769.018; Thu, 9 Apr 2026\n 02:58:21 +0000"],"ARC-Seal":["i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775703508; cv=fail;\n b=PHjTh2gKR1Qfz3Dc+Q2QJ3JBErYn9hw1Orv82FNzDg6hfI5UEjF2UmjU+NeQEWc8w/QXOrr3FmjutFoG8KWEKt1JFJiztVj1dpwsaZIo3dgu8W+nrhletw5rk7dDErM2lgMkd9SCe6kuJlSxJV0grapeZCz/gXDPGgdkuYtErZM=","i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;\n b=dcAo1NsKn38t5MmvjM8zh30RJgv4u2Zs5MqzyHR7vDB4DeBg3zRTNpYPA74JW8kp38mfUgP9WdpEHiKf/vD9aznAGq5Fpl+PKn1trBsgYn0YoTCDyLk+e7AvjXMpNKL5KZJWyHl3nmYXRdtiUWJzknkMDtMYa6Rrx4amV4jKw0OaBdlNETO4fiOT/4d63H8y0SMuKWUm9MNJ5aF/d0TPzBdx2e4q6FN00qjgHuru7/6sn67qx9dSKtv4RyIs6YPc8Khcg2WRHxyW1tyCgvCvlQOp/Aw1W36ib7+XUV4T8kdnfVG3oEhMWTQmxKDWH4J5q+atWBp9KkGyAX6bk7KrNA=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775703508; c=relaxed/simple;\n\tbh=0wWWTAmRDth+6oOulABEtDQVUJds7SfGVXYG3muD6RU=;\n\th=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To:\n\t Content-Type:MIME-Version;\n b=Z6ZWfOQl5+TQBowaRhY5nfpNO8JulLoxqcJN3GSz/UCiv5FJ80zPtFlEN+MPWXyPly7X1RkFG1l0ZyoMlsi/OFpLBe7PLDPg6M6z1JCjPrfSsgWspeNE2ieVGONjtsppdv3hfm9UENDltgVJDzRf9c+wlP7pY/S0nWfULBH5AVw=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector10001;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;\n bh=0wWWTAmRDth+6oOulABEtDQVUJds7SfGVXYG3muD6RU=;\n b=sR7gBYGnYNHL5xMF+GkJP1N30itMRhyqeygrKZX3mdjBKlQK0zKVPyOCFcqI3yH1Y4r5c62bn5U92F2C6ODUbJ5Aqe73Grpt4lilogfxH0BdsZPCQcpWXnA8H+Wubzxi9+qv9q48CNLxOjn1dl3IQXwsrWUYcw4F2z9k5vSphaLAAPkgRCyvX8shjxfJzHSIYg6nRlq8JA8hzVsT3S2ReeJejgVKEjK0pq1B8w9N/9C6KU4AkI2sjc/HyqNZYj3VlrV1sgsv2f8FwQFdQL6FBDgjQfU79xkajyJXrGiVgWNP5yBFYVZ/cpow0QP+5escqDsidu1BDWdT2m/4KSeJmw=="],"ARC-Authentication-Results":["i=2; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=nxp.com;\n spf=pass smtp.mailfrom=nxp.com;\n dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com\n header.b=c5zLvtvP; arc=fail smtp.client-ip=52.101.83.42","i=1; mx.microsoft.com 1; spf=pass\n smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass\n header.d=nxp.com; arc=none"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=0wWWTAmRDth+6oOulABEtDQVUJds7SfGVXYG3muD6RU=;\n b=c5zLvtvPFs8U1oARx7L6/VsBiRV2omb3mZW34ZnboL4x7Lz2Ge4khqWQF0qcgGtFE0RHKe06lJIVSTOykdmuasWw/shFL3gF9OXH1BVzZrWyhpWO6qo+yIIZ09lYjOxarsZWFEGsy61XKWMKuIFK33bh89oBa2d7zkGLqz+CjrNjYvXlNv3yiqpxSjOOt5ap0iv6omSTnYPE1HM72Fbjt7ShmQkdxFEiHdxoqlIA0H4NjjBOZtPLeXQFaCRQdSjXjsxtG7yKvuZPrP2mbDBoNmsp+kbb49A2atYKvVK+iIBaav8VNtCXtlDPnqKDd7hpSKsvUpxTXJQUN7YYwRTD/Q==","From":"Sherry Sun <sherry.sun@nxp.com>","To":"Manivannan Sadhasivam <mani@kernel.org>","CC":"\"robh@kernel.org\" <robh@kernel.org>, \"krzk+dt@kernel.org\"\n\t<krzk+dt@kernel.org>, \"conor+dt@kernel.org\" <conor+dt@kernel.org>, Frank Li\n\t<frank.li@nxp.com>, \"s.hauer@pengutronix.de\" <s.hauer@pengutronix.de>,\n\t\"kernel@pengutronix.de\" <kernel@pengutronix.de>, \"festevam@gmail.com\"\n\t<festevam@gmail.com>, \"lpieralisi@kernel.org\" <lpieralisi@kernel.org>,\n\t\"kwilczynski@kernel.org\" <kwilczynski@kernel.org>, \"bhelgaas@google.com\"\n\t<bhelgaas@google.com>, Hongxing Zhu <hongxing.zhu@nxp.com>,\n\t\"l.stach@pengutronix.de\" <l.stach@pengutronix.de>, \"imx@lists.linux.dev\"\n\t<imx@lists.linux.dev>, \"linux-pci@vger.kernel.org\"\n\t<linux-pci@vger.kernel.org>, \"linux-arm-kernel@lists.infradead.org\"\n\t<linux-arm-kernel@lists.infradead.org>, \"devicetree@vger.kernel.org\"\n\t<devicetree@vger.kernel.org>, \"linux-kernel@vger.kernel.org\"\n\t<linux-kernel@vger.kernel.org>","Subject":"RE: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Thread-Topic":"[PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Thread-Index":"AQHcxnsnHAAJHNaLCkmHx9RiuF3pD7XTl3qAgAEbHYCAAINPgIAA0amg","Date":"Thu, 9 Apr 2026 02:58:21 +0000","Message-ID":"\n <VI0PR04MB1211419BB996B4790AE04170F92582@VI0PR04MB12114.eurprd04.prod.outlook.com>","References":"<20260407104154.2842132-1-sherry.sun@nxp.com>\n <20260407104154.2842132-3-sherry.sun@nxp.com>\n <lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>\n <VI0PR04MB12114A60C4A7E43ED62A32B04925BA@VI0PR04MB12114.eurprd04.prod.outlook.com>\n <yijf6mwclpx6n7giucgykxvrm73baicy2urhzns34sxgloli3z@ygose2qrgvuz>","In-Reply-To":"<yijf6mwclpx6n7giucgykxvrm73baicy2urhzns34sxgloli3z@ygose2qrgvuz>","Accept-Language":"zh-CN, en-US","Content-Language":"en-US","X-MS-Has-Attach":"","X-MS-TNEF-Correlator":"","authentication-results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256\n header.s=selector1 header.b=c5zLvtvP;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-52187-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com\n header.b=\"c5zLvtvP\"","smtp.subspace.kernel.org;\n arc=fail smtp.client-ip=52.101.83.42","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=nxp.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=nxp.com","dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=nxp.com;"],"x-ms-publictraffictype":"Email","x-ms-traffictypediagnostic":"VI0PR04MB12114:EE_|GV1PR04MB10992:EE_","x-ms-office365-filtering-correlation-id":"025fb1c9-0f66-4e62-58e7-08de95e3dc3f","x-ms-exchange-senderadcheck":"1","x-ms-exchange-antispam-relay":"0","x-microsoft-antispam":"\n BCL:0;ARA:13230040|7416014|376014|1800799024|366016|19092799006|38070700021|56012099003|18002099003|22082099003;","x-microsoft-antispam-message-info":"\n 4jolRD7RxV1kezSvGnM86wiSjEscaw80hBf9zv5Jmw7vkEygLMleCPXO4Q1fW4MEB0qMwm1a5AMyc6HOQzfSLYGXQRGQ5NVgJYCym9r0I2xF+3QMFODcVtZZmKvaahh18FXjSHb4Mth81KMm8QO7Zd+2OzIRhGwGTQLsvEppDUwbo5iDe5fWm6gXT7dMQR2KcisF29O6a1/0SvaaOp1J6NFyXg/S5Z8OHRZdSY7SU5BfzZRWwgfJ5/yqxpmozXaJZHq7KSMDhxEISSgQmk4h5RLO5HcE/ZPMzo8i32MOLQUqmuGLm6y6FNzKBpZXa+qkxyGw9gqZ+Rxe7Kbm42rJ1T9m+CyiGBuyxLbB/D7B66/PqPCdLuQhJF8M4BTWqyB9SQ3Xbr5Yc3wOw+9Ks33RQxJw1KNr12i0p+PgAjUzNQGUwXzUG31FuTJbFjn+O+z7A7jDmSaRwO3itEklSOYE30sHJ5GFpaSSfdo+iwQcJq0XVtY4Mgo3YDe5Z1lShOf02fWynhw6/LERYmEm4s7/PQ+H8QGsXoupg1+W9jVNWXmcsrcQ4SX72d2u7L/WyPAR8n3GCJYtUeQ94DzyPakwYjCaFEXY9rxYnT6mY2QJid+sw0lsKy+Vinn+7kEQMMzXe5gD2cxx7W5td2M2szpf7fgDkHt7u9h0c1C/K1WTBoQpfts0GU+VWvQW/cjUuThP/YWuZZRWVO3dLj4jmQ6eTt1b8CwST4Z/HPpo73ouTH2G0OFgNI5Gpe6QBlOtOIQYrN0TkD0WzRwd/quhG5/Yq/fvFDKKc5s961ew5dWrqUM=","x-forefront-antispam-report":"\n CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI0PR04MB12114.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016)(19092799006)(38070700021)(56012099003)(18002099003)(22082099003);DIR:OUT;SFP:1101;","x-ms-exchange-antispam-messagedata-chunkcount":"1","x-ms-exchange-antispam-messagedata-0":"=?utf-8?q?qTl+MWsU/eIcxqtitNJhFJapW/b1?=\n\t=?utf-8?q?27y7MRJs5q8IlYWLPJ3Rhxg/abyZ4VOQvVxfe6dYwvD+mJbEfvREC5PZztH/qLZ/8?=\n\t=?utf-8?q?WRTCG4ZDAlm930Ve//DbRSHZLMV+aK41vn+1jt/+AHjjPtkEqzadK/hCWhzR77J+n?=\n\t=?utf-8?q?XjWzHbDzmG2iYL4fYnsMpIK0LuhS9+2m2M8+ilozUoU9b8LQO1BUUfYpU2tQff+f5?=\n\t=?utf-8?q?+vD5KK7AV1ySy/cTJoq2wkr+2a1Mkk2U6fr6brZZ3/jOizpQuSbWOGQ09n9l0+oHz?=\n\t=?utf-8?q?oV6mINLU5/Uv8i5/RvdETi54tJKWxKBUxPq+HAtFtwjmm/NT+MLO8AtG6MWxAzP+G?=\n\t=?utf-8?q?430JEM3A8cVEu9YOtBHjgEAfApY3d1+D1C8p+1DRbLKSlFd53TkPBOF4IMk5rbMxt?=\n\t=?utf-8?q?6wVOLYRrCInvojRrQnPOY7VmBkY6zrOVJw1AQwjZ41/kOXwu+NrwPdimTv0xx34iY?=\n\t=?utf-8?q?hVqz1UFlbClinG4wUNOZa1msSeEFMpWhyNt1qlJ0Caj2/j27hxU3/FDO1fKGdc1+c?=\n\t=?utf-8?q?3+bxNgnM25lVdNslpLzeQMWL7Pcb2rXdDbCo9AEQJg1ACAf9rIvVH3yQIVUbEyRjz?=\n\t=?utf-8?q?jRN7FvZuy0AKw76o1bFEGDKi8GDaQCOo8SDXeOZ0uw149VdIKMW3s5CSNOEYUHHdt?=\n\t=?utf-8?q?LuyFYAW/hhPyAydFx9cgh2XA5yPOsse94lj7GyfkwBlp8GKv7yr/VElz4UE0ehUye?=\n\t=?utf-8?q?V61crvm4he3TUAhvJcokKogPsnZ9O6GrCd4lwTntbyk02hbXve8os/5CXXMlml+Kn?=\n\t=?utf-8?q?St2qGWC4wB1SAAYmJ///G7/+iJmWegfqjPUbCeF2AzIS4BKQPhXSnyISN/kuuJ/CF?=\n\t=?utf-8?q?PU+OeUde5MsTrcw4qmI1bofoO8cK0mhNkQnL5Cem/n7pfi/kK+JH1ShapQJLQfEjC?=\n\t=?utf-8?q?cDHih3RmR+gppjYjP1d9eVIRUHwQYwbykbLD5p3meuvbLEvMKEgITGKq637GLOfrg?=\n\t=?utf-8?q?rGhSm4nb7DJqMsA0qwPaDScnLVEJOZM3yGCqll1GhJz5SLyu9oA1ltM3t2VMPkRQt?=\n\t=?utf-8?q?MVE4kThDxYKBSZZKRHGyn7T+LEWQafGQ3e5gnL89cai51NZAr6wpMFzWQ8eiyPAnf?=\n\t=?utf-8?q?ukqGM65QBYGb29tPhlKdiRmit50ruuQvgdUmrC+MwmpLropikoGgLsTb3KqedU/Ty?=\n\t=?utf-8?q?Nb/iKT9ID5Nud9L7YAt8rLaMiwJBYFPlVNaiXiEsyDvG6SMKwuO+oMDsd8airw7Ok?=\n\t=?utf-8?q?t6mv7zuYRyx5DNSdleuOQz4lGvw5wHMy4Cy+rFrrffjCH6V8unzJrpnOGhhub87ax?=\n\t=?utf-8?q?hDCpCdGQDKTwe5eTZSGa7+tZVimGH6sKtSQB80EGQwwdtGy88dmboz3yRoRddrRzf?=\n\t=?utf-8?q?lfIm+3dfZ/TRTTBHYqxEnWEvmRHLiXOD//SAHSdhSDP96idOVnPxje6oAUHxaj2wD?=\n\t=?utf-8?q?Grj9JS85AJ7vlIhQm4d7ORYVac03fA0Tz6amlpkHOg8C2i3sh5SDgN7//enjm9Ufg?=\n\t=?utf-8?q?h+DLSdk6WhHNPRnhtQcQ2i32fDqdX502F+rzDtbjQDXpj7HRxK3HPaoj8vkZ6Cyjf?=\n\t=?utf-8?q?f+ucy20Ai5XL0Wp51XNzsBR5ESBFWN+bSf4HdHVjjh4fJ+neSKztP94sbJJC7yvN5?=\n\t=?utf-8?q?S4dDnNCg6MVLGPDj2Hb7vhbLZ5+B4HTceAPjFq4yJqGWmr0JSc/kUQQ+JZFKGN7KF?=\n\t=?utf-8?q?/2i+Yi4oCw?=","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","X-OriginatorOrg":"nxp.com","X-MS-Exchange-CrossTenant-AuthAs":"Internal","X-MS-Exchange-CrossTenant-AuthSource":"VI0PR04MB12114.eurprd04.prod.outlook.com","X-MS-Exchange-CrossTenant-Network-Message-Id":"\n 025fb1c9-0f66-4e62-58e7-08de95e3dc3f","X-MS-Exchange-CrossTenant-originalarrivaltime":"09 Apr 2026 02:58:21.8065\n (UTC)","X-MS-Exchange-CrossTenant-fromentityheader":"Hosted","X-MS-Exchange-CrossTenant-id":"686ea1d3-bc2b-4c6f-a92c-d99c5c301635","X-MS-Exchange-CrossTenant-mailboxtype":"HOSTED","X-MS-Exchange-CrossTenant-userprincipalname":"\n YanNUdHXHueLT+9c3w+yOv1mQT4sIOWUCsHRhEqyj/za29K+CRdBWbG7OACzBJbxmGTToFZ8KITI2swWGy6l3w==","X-MS-Exchange-Transport-CrossTenantHeadersStamped":"GV1PR04MB10992"}},{"id":3675404,"web_url":"http://patchwork.ozlabs.org/comment/3675404/","msgid":"<yzy3xui6wzc6h4jguju6hj66bqsj37ulnkl4sjsq4ytyb6azgn@lc2zpqbquzwa>","list_archive_url":null,"date":"2026-04-09T16:58:17","subject":"Re: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","submitter":{"id":78905,"url":"http://patchwork.ozlabs.org/api/people/78905/","name":"Manivannan Sadhasivam","email":"mani@kernel.org"},"content":"On Thu, Apr 09, 2026 at 02:58:21AM +0000, Sherry Sun wrote:\n> > On Wed, Apr 08, 2026 at 06:34:02AM +0000, Sherry Sun wrote:\n> > \n> > [...]\n> > \n> > > > > +/**\n> > > > > + * pci_host_common_parse_port - Parse a single Root Port node\n> > > > > + * @dev: Device pointer\n> > > > > + * @bridge: PCI host bridge\n> > > > > + * @node: Device tree node of the Root Port\n> > > > > + *\n> > > > > + * Returns: 0 on success, negative error code on failure  */\n> > > > > +static int pci_host_common_parse_port(struct device *dev,\n> > > > > +\t\t\t\t      struct pci_host_bridge *bridge,\n> > > > > +\t\t\t\t      struct device_node *node) {\n> > > > > +\tstruct pci_host_port *port;\n> > > > > +\tstruct gpio_desc *reset;\n> > > > > +\n> > > > > +\treset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> > > > > +\t\t\t\t      \"reset\", GPIOD_ASIS, \"PERST#\");\n> > > >\n> > > > Sorry, I missed this earlier.\n> > > >\n> > > > Since PERST# is optional, you cannot reliably detect whether the\n> > > > Root Port binding intentionally skipped the PERST# GPIO or legacy\n> > > > binding is used, just by checking for PERST# in Root Port node.\n> > > >\n> > > > So this helper should do 3 things:\n> > > >\n> > > > 1. If PERST# is found in Root Port node, use it.\n> > > > 2. If not, check the RC node and if present, return -ENOENT to\n> > > > fallback to the legacy binding.\n> > > > 3. If not found in both nodes, assume that the PERST# is not present\n> > > > in the design, and proceed with parsing Root Port binding further.\n> > >\n> > > Hi Mani, understand, does the following code looks ok for above three\n> > cases?\n> > >\n> > >     /* Check if PERST# is present in Root Port node */\n> > >     reset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(node),\n> > >                       \"reset\", GPIOD_ASIS, \"PERST#\");\n> > >     if (IS_ERR(reset)) {\n> > >         /* If error is not -ENOENT, it's a real error */\n> > >         if (PTR_ERR(reset) != -ENOENT)\n> > >             return PTR_ERR(reset);\n> > >\n> > >         /* PERST# not found in Root Port node, check RC node */\n> > >         rc_has_reset = of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n> > >                    of_property_read_bool(dev->of_node, \"reset-gpio\");\n> > \n> > Just:\n> > \t\tif (of_property_read_bool(dev->of_node, \"reset-gpios\") ||\n> > \t\t    of_property_read_bool(dev->of_node, \"reset-gpio\")) {\n> > \t\t\treturn -ENOENT;\n> > \t\t}\n> \n> Ok, will do.\n> \n> > \n> > >         if (rc_has_reset)\n> > >             return -ENOENT;\n> > >\n> > >         /* No PERST# in either node, assume not present in design */\n> > >         reset = NULL;\n> > >     }\n> > >\n> > >     port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> > >     if (!port)\n> > >         return -ENOMEM;\n> > > ...\n> > >\n> > > >\n> > > > But there is one more important limitation here. Right now, this API\n> > > > only handles PERST#. But if another vendor tries to use it and if\n> > > > they need other properties such as PHY, clocks etc... those\n> > > > resources should be fetched optionally only by this helper. But if\n> > > > the controller has a hard dependency on those resources, the driver will\n> > fail to operate.\n> > > >\n> > > > I don't think we can fix this limitation though and those platforms\n> > > > should ensure that the resource dependency is correctly modeled in\n> > > > DT binding and the DTS is validated properly. It'd be good to\n> > > > mention this in the kernel doc of this API.\n> > >\n> > > Ok, I will add a NOTE for this in this API description.\n> > >\n> > > >\n> > > > > +\tif (IS_ERR(reset))\n> > > > > +\t\treturn PTR_ERR(reset);\n> > > > > +\n> > > > > +\tport = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);\n> > > > > +\tif (!port)\n> > > > > +\t\treturn -ENOMEM;\n> > > > > +\n> > > > > +\tport->reset = reset;\n> > > > > +\tINIT_LIST_HEAD(&port->list);\n> > > > > +\tlist_add_tail(&port->list, &bridge->ports);\n> > > > > +\n> > > > > +\treturn 0;\n> > > > > +}\n> > > > > +\n> > > > > +/**\n> > > > > + * pci_host_common_parse_ports - Parse Root Port nodes from\n> > > > > +device tree\n> > > > > + * @dev: Device pointer\n> > > > > + * @bridge: PCI host bridge\n> > > > > + *\n> > > > > + * This function iterates through child nodes of the host bridge\n> > > > > +and parses\n> > > > > + * Root Port properties (currently only reset GPIO).\n> > > > > + *\n> > > > > + * Returns: 0 on success, -ENOENT if no ports found, other\n> > > > > +negative error codes\n> > > > > + * on failure\n> > > > > + */\n> > > > > +int pci_host_common_parse_ports(struct device *dev, struct\n> > > > > +pci_host_bridge *bridge) {\n> > > > > +\tint ret = -ENOENT;\n> > > > > +\n> > > > > +\tfor_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> > > > > +\t\tif (!of_node_is_type(of_port, \"pci\"))\n> > > > > +\t\t\tcontinue;\n> > > > > +\t\tret = pci_host_common_parse_port(dev, bridge, of_port);\n> > > > > +\t\tif (ret)\n> > > > > +\t\t\treturn ret;\n> > > >\n> > > > As Sashiko flagged, you need to make sure that\n> > > > devm_add_action_or_reset() is added even during the error path:\n> > >\n> > > Yes, it needs to be fixed. We can handle it with the following two methods, I\n> > am not sure which method is better or more preferable?\n> > >\n> > > #1: register cleanup action after first successful port parse and use\n> > cleanup_registered flag to avoid duplicate register.\n> > >     int ret = -ENOENT;\n> > >     bool cleanup_registered = false;\n> > >\n> > >     for_each_available_child_of_node_scoped(dev->of_node, of_port) {\n> > >         if (!of_node_is_type(of_port, \"pci\"))\n> > >             continue;\n> > >         ret = pci_host_common_parse_port(dev, bridge, of_port);\n> > >         if (ret)\n> > >             return ret;\n> > >\n> > >         /* Register cleanup action after first successful port parse */\n> > >         if (!cleanup_registered) {\n> > >             ret = devm_add_action_or_reset(dev,\n> > >                                pci_host_common_delete_ports,\n> > >                                &bridge->ports);\n> > \n> > Even if you register devm_add_action_or_reset(), it won't be called when\n> > pci_host_common_parse_port() fails since the legacy fallback will be used.\n> > \n> > So you need to manually call pci_host_common_delete_ports() in the error\n> > path.\n> \n> Get your point, so seems I should just add the err_cleanup handle path like this, right?\n> \n>     for_each_available_child_of_node_scoped(dev->of_node, of_port) {\n>         if (!of_node_is_type(of_port, \"pci\"))\n>             continue;\n>         ret = pci_host_common_parse_port(dev, bridge, of_port);\n>         if (ret)\n>             goto err_cleanup;\n>     }\n> \n>     if (ret)\n>         return ret;\n> \n>     return devm_add_action_or_reset(dev, pci_host_common_delete_ports,\n>                     &bridge->ports);\n> \n> err_cleanup:\n>     pci_host_common_delete_ports(&bridge->ports);\n>     return ret;\n> \n\nYes!\n\n- Mani","headers":{"Return-Path":"\n <linux-pci+bounces-52221-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=IFpM1HVL;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=104.64.211.4; helo=sin.lore.kernel.org;\n envelope-from=linux-pci+bounces-52221-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"IFpM1HVL\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fs5jj2R8Nz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 02:58:33 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id 6785E30147B7\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  9 Apr 2026 16:58:31 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A23653E1CEE;\n\tThu,  9 Apr 2026 16:58:27 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C24F3E1CE8;\n\tThu,  9 Apr 2026 16:58:27 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 6A83DC116C6;\n\tThu,  9 Apr 2026 16:58:21 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775753907; cv=none;\n b=BMQwNmWqvuMnSKxKKrzpBVdfZuRV7sRXi9MiSRLLWssTo7P6bL+ib1NiLn+dXAG3ivG2vAR9WtzygxwG5jPC5lcZV/BVJF5X3EFNmPzho8WbHk2nCcTLoWCZudIrAomXr/3Hb8isPij2gDOw08jRZa1NTvzjQImpOkmBjdX+7wk=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775753907; c=relaxed/simple;\n\tbh=jzQepuIPTUxzXw6nvVnnvG0DD/52Qtgmozdmz3RF8Dc=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=GaFYsFZWyLlxzNwFpMa9EtSKtaNXLrFXweJJIyBZHB3GkN1m0W+rElR4AQtD75KxRogCNG5u/al2zhwteiSqtNsIFjP32tt0zfzUpRTqa51I1LPVPmBldgsymhqU5WI2knd7yspUPXYRoEFJfJK8mSM3wXdGZOt9kp6S5u34McY=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=IFpM1HVL; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1775753907;\n\tbh=jzQepuIPTUxzXw6nvVnnvG0DD/52Qtgmozdmz3RF8Dc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IFpM1HVLK0gj/ENLmzP+oNXpi+o1r6eJD99Xz2JAeeE9//s28r0AkFibOJjgDCa7g\n\t 2TZnjHbG7Q1rDYrxUN6wXFWJts0vnvCXSnICth6fI19BYuE+3cRWP1du/bw7vM4BIj\n\t AskhIq+vIHe0s5wQorI5G3iGW3Go/uLcRna5qQkUYdRvdS/D3qGUCYKNa8gY54BsaP\n\t YLawo9o8483hclAtRSauVavPsIeiQ58oxINp5WgqDhPFv+dIlj/x2bxHFliApKfC1W\n\t KJv/GYUqnnJ37bS7izC3i1voWnVIrHVE4Q6et6bDg1q/LsXbCxRP+KZ1rhUALG6uuD\n\t ZuuDmkhKY5i7A==","Date":"Thu, 9 Apr 2026 22:28:17 +0530","From":"Manivannan Sadhasivam <mani@kernel.org>","To":"Sherry Sun <sherry.sun@nxp.com>","Cc":"\"robh@kernel.org\" <robh@kernel.org>,\n\t\"krzk+dt@kernel.org\" <krzk+dt@kernel.org>,\n \"conor+dt@kernel.org\" <conor+dt@kernel.org>,\n\tFrank Li <frank.li@nxp.com>,\n \"s.hauer@pengutronix.de\" <s.hauer@pengutronix.de>,\n\t\"kernel@pengutronix.de\" <kernel@pengutronix.de>,\n \"festevam@gmail.com\" <festevam@gmail.com>,\n\t\"lpieralisi@kernel.org\" <lpieralisi@kernel.org>,\n \"kwilczynski@kernel.org\" <kwilczynski@kernel.org>,\n\t\"bhelgaas@google.com\" <bhelgaas@google.com>,\n Hongxing Zhu <hongxing.zhu@nxp.com>,\n\t\"l.stach@pengutronix.de\" <l.stach@pengutronix.de>,\n \"imx@lists.linux.dev\" <imx@lists.linux.dev>,\n\t\"linux-pci@vger.kernel.org\" <linux-pci@vger.kernel.org>,\n\t\"linux-arm-kernel@lists.infradead.org\"\n <linux-arm-kernel@lists.infradead.org>,\n \"devicetree@vger.kernel.org\" <devicetree@vger.kernel.org>,\n\t\"linux-kernel@vger.kernel.org\" <linux-kernel@vger.kernel.org>","Subject":"Re: [PATCH V11 02/12] PCI: host-generic: Add common helpers for\n parsing Root Port properties","Message-ID":"<yzy3xui6wzc6h4jguju6hj66bqsj37ulnkl4sjsq4ytyb6azgn@lc2zpqbquzwa>","References":"<20260407104154.2842132-1-sherry.sun@nxp.com>\n <20260407104154.2842132-3-sherry.sun@nxp.com>\n <lnzprzrdwra7pn7d6m3sbj5pvjy64blwpjl6i3lmlnfbyho63b@czpyhpgz5vum>\n <VI0PR04MB12114A60C4A7E43ED62A32B04925BA@VI0PR04MB12114.eurprd04.prod.outlook.com>\n <yijf6mwclpx6n7giucgykxvrm73baicy2urhzns34sxgloli3z@ygose2qrgvuz>\n <VI0PR04MB1211419BB996B4790AE04170F92582@VI0PR04MB12114.eurprd04.prod.outlook.com>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"\n <VI0PR04MB1211419BB996B4790AE04170F92582@VI0PR04MB12114.eurprd04.prod.outlook.com>"}}]