From: Radu Rendec <rrendec@redhat.com>
To: Marc Zyngier <maz@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Manivannan Sadhasivam <mani@kernel.org>
Cc: "Will Deacon" <will@kernel.org>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] PCI: host-common: Do not set drvdata in pci_host_common_init()
Date: Tue, 18 Nov 2025 17:12:43 -0500 [thread overview]
Message-ID: <20251118221244.372423-2-rrendec@redhat.com> (raw)
In-Reply-To: <20251118221244.372423-1-rrendec@redhat.com>
Currently pci_host_common_init() uses the platform device's drvdata to
store the pointer to the allocated struct pci_host_bridge. This makes
sense for drivers that use pci_host_common_{probe,remove}() directly as
the platform probe/remove functions, but leaves no option for more
complex drivers to store a pointer to their own private data.
Change pci_host_common_init() to return the pointer to the allocated
struct pci_host_bridge, and move the platform_set_drvdata() call to
pci_host_common_probe(). This way, drivers that implement their own
probe function can still use pci_host_common_init() but store their own
pointer in the platform device's drvdata.
For symmetry, move the release code to a new function that takes a
pointer to struct pci_host_bridge, and make pci_host_common_release() a
wrapper to it that extracts the pointer from the platform device's
drvdata. This way, drivers that store their own private pointer in the
platform device's drvdata can still use the library release code.
No functional change to the existing users of pci-host-common is
intended, with the exception of the pcie-apple driver, which is modified
in a subsequent patch.
Signed-off-by: Radu Rendec <rrendec@redhat.com>
---
drivers/pci/controller/pci-host-common.c | 36 ++++++++++++++++--------
drivers/pci/controller/pci-host-common.h | 6 ++--
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
index 810d1c8de24e9..86002195c93ac 100644
--- a/drivers/pci/controller/pci-host-common.c
+++ b/drivers/pci/controller/pci-host-common.c
@@ -52,25 +52,24 @@ struct pci_config_window *pci_host_common_ecam_create(struct device *dev,
}
EXPORT_SYMBOL_GPL(pci_host_common_ecam_create);
-int pci_host_common_init(struct platform_device *pdev,
- const struct pci_ecam_ops *ops)
+struct pci_host_bridge *pci_host_common_init(struct platform_device *pdev,
+ const struct pci_ecam_ops *ops)
{
struct device *dev = &pdev->dev;
struct pci_host_bridge *bridge;
struct pci_config_window *cfg;
+ int rc;
bridge = devm_pci_alloc_host_bridge(dev, 0);
if (!bridge)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
of_pci_check_probe_only();
- platform_set_drvdata(pdev, bridge);
-
/* Parse and map our Configuration Space windows */
cfg = pci_host_common_ecam_create(dev, bridge, ops);
if (IS_ERR(cfg))
- return PTR_ERR(cfg);
+ return (struct pci_host_bridge *)cfg;
bridge->sysdata = cfg;
bridge->ops = (struct pci_ops *)&ops->pci_ops;
@@ -78,31 +77,46 @@ int pci_host_common_init(struct platform_device *pdev,
bridge->disable_device = ops->disable_device;
bridge->msi_domain = true;
- return pci_host_probe(bridge);
+ rc = pci_host_probe(bridge);
+ if (rc)
+ return ERR_PTR(rc);
+
+ return bridge;
}
EXPORT_SYMBOL_GPL(pci_host_common_init);
int pci_host_common_probe(struct platform_device *pdev)
{
const struct pci_ecam_ops *ops;
+ struct pci_host_bridge *bridge;
ops = of_device_get_match_data(&pdev->dev);
if (!ops)
return -ENODEV;
- return pci_host_common_init(pdev, ops);
+ bridge = pci_host_common_init(pdev, ops);
+ if (IS_ERR(bridge))
+ return PTR_ERR(bridge);
+
+ platform_set_drvdata(pdev, bridge);
+
+ return 0;
}
EXPORT_SYMBOL_GPL(pci_host_common_probe);
-void pci_host_common_remove(struct platform_device *pdev)
+void pci_host_common_release(struct pci_host_bridge *bridge)
{
- struct pci_host_bridge *bridge = platform_get_drvdata(pdev);
-
pci_lock_rescan_remove();
pci_stop_root_bus(bridge->bus);
pci_remove_root_bus(bridge->bus);
pci_unlock_rescan_remove();
}
+EXPORT_SYMBOL_GPL(pci_host_common_release);
+
+void pci_host_common_remove(struct platform_device *pdev)
+{
+ pci_host_common_release(platform_get_drvdata(pdev));
+}
EXPORT_SYMBOL_GPL(pci_host_common_remove);
MODULE_DESCRIPTION("Common library for PCI host controller drivers");
diff --git a/drivers/pci/controller/pci-host-common.h b/drivers/pci/controller/pci-host-common.h
index 51c35ec0cf37d..018e593bafe47 100644
--- a/drivers/pci/controller/pci-host-common.h
+++ b/drivers/pci/controller/pci-host-common.h
@@ -11,11 +11,13 @@
#define _PCI_HOST_COMMON_H
struct pci_ecam_ops;
+struct pci_host_bridge;
int pci_host_common_probe(struct platform_device *pdev);
-int pci_host_common_init(struct platform_device *pdev,
- const struct pci_ecam_ops *ops);
+struct pci_host_bridge *pci_host_common_init(struct platform_device *pdev,
+ const struct pci_ecam_ops *ops);
void pci_host_common_remove(struct platform_device *pdev);
+void pci_host_common_release(struct pci_host_bridge *bridge);
struct pci_config_window *pci_host_common_ecam_create(struct device *dev,
struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops);
--
2.51.1
next prev parent reply other threads:[~2025-11-18 22:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 22:12 [PATCH 0/2] PCI: host-common: Allow drivers to use the device's drvdata pointer Radu Rendec
2025-11-18 22:12 ` Radu Rendec [this message]
2025-11-19 12:01 ` [PATCH 1/2] PCI: host-common: Do not set drvdata in pci_host_common_init() Marc Zyngier
2025-11-19 16:19 ` Radu Rendec
2025-11-20 9:23 ` Marc Zyngier
2025-11-18 22:12 ` [PATCH 2/2] PCI: apple: Store private pointer in platform device's drvdata Radu Rendec
2025-11-19 11:30 ` Marc Zyngier
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=20251118221244.372423-2-rrendec@redhat.com \
--to=rrendec@redhat.com \
--cc=bhelgaas@google.com \
--cc=kwilczynski@kernel.org \
--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=maz@kernel.org \
--cc=robh@kernel.org \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).