* [PATCH v2] PCI: cadence: Store the core controller in platform drvdata
@ 2026-09-15 8:28 Linmao Li
2026-09-15 8:39 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Linmao Li @ 2026-09-15 8:28 UTC (permalink / raw)
To: Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam
Cc: Rob Herring, Aksh Garg, Tom Joseph, Vladimir Oltean, linux-pci,
linux-kernel, Linmao Li
cdns_plat_pcie_probe() stores a struct cdns_plat_pcie pointer with
platform_set_drvdata(). cdns_plat_pcie_shutdown() and the callbacks in
cdns_pcie_pm_ops retrieve the same pointer with dev_get_drvdata() and
use it as a struct cdns_pcie pointer. This makes them read phy_count
and phy beyond the wrapper.
struct cdns_plat_pcie only contains a pointer to struct cdns_pcie. Drop
the redundant wrapper and store the struct cdns_pcie pointer directly.
Fixes: bd22885aa188 ("PCI: cadence: Refactor driver to use as a core library")
Suggested-by: Aksh Garg <a-garg7@ti.com>
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
Changes in v2:
- Drop the redundant struct cdns_plat_pcie wrapper (Aksh Garg).
---
.../controller/cadence/pcie-cadence-plat.c | 27 ++++++-------------
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c b/drivers/pci/controller/cadence/pcie-cadence-plat.c
index 13edc6be21f5..4a24302cc5b2 100644
--- a/drivers/pci/controller/cadence/pcie-cadence-plat.c
+++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c
@@ -14,14 +14,6 @@
#define CDNS_PLAT_CPU_TO_BUS_ADDR 0x0FFFFFFF
-/**
- * struct cdns_plat_pcie - private data for this PCIe platform driver
- * @pcie: Cadence PCIe controller
- */
-struct cdns_plat_pcie {
- struct cdns_pcie *pcie;
-};
-
static const struct of_device_id cdns_plat_pcie_of_match[];
static u64 cdns_plat_cpu_addr_fixup(struct cdns_pcie *pcie, u64 cpu_addr)
@@ -36,9 +28,9 @@ static const struct cdns_pcie_ops cdns_plat_ops = {
static int cdns_plat_pcie_probe(struct platform_device *pdev)
{
const struct cdns_plat_pcie_of_data *data;
- struct cdns_plat_pcie *cdns_plat_pcie;
struct device *dev = &pdev->dev;
struct pci_host_bridge *bridge;
+ struct cdns_pcie *pcie;
struct cdns_pcie_ep *ep;
struct cdns_pcie_rc *rc;
bool is_rc;
@@ -51,11 +43,6 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
is_rc = data->is_rc;
pr_debug(" Started %s with is_rc: %d\n", __func__, is_rc);
- cdns_plat_pcie = devm_kzalloc(dev, sizeof(*cdns_plat_pcie), GFP_KERNEL);
- if (!cdns_plat_pcie)
- return -ENOMEM;
-
- platform_set_drvdata(pdev, cdns_plat_pcie);
if (is_rc) {
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_PLAT_HOST))
return -ENODEV;
@@ -67,9 +54,9 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
rc = pci_host_bridge_priv(bridge);
rc->pcie.dev = dev;
rc->pcie.ops = &cdns_plat_ops;
- cdns_plat_pcie->pcie = &rc->pcie;
+ pcie = &rc->pcie;
- ret = cdns_pcie_init_phy(dev, cdns_plat_pcie->pcie);
+ ret = cdns_pcie_init_phy(dev, pcie);
if (ret) {
dev_err(dev, "failed to init phy\n");
return ret;
@@ -94,9 +81,9 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
ep->pcie.dev = dev;
ep->pcie.ops = &cdns_plat_ops;
- cdns_plat_pcie->pcie = &ep->pcie;
+ pcie = &ep->pcie;
- ret = cdns_pcie_init_phy(dev, cdns_plat_pcie->pcie);
+ ret = cdns_pcie_init_phy(dev, pcie);
if (ret) {
dev_err(dev, "failed to init phy\n");
return ret;
@@ -114,13 +101,15 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
goto err_init;
}
+ platform_set_drvdata(pdev, pcie);
+
return 0;
err_init:
err_get_sync:
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
- cdns_pcie_disable_phy(cdns_plat_pcie->pcie);
+ cdns_pcie_disable_phy(pcie);
return ret;
}
base-commit: 9a9d18547ddc97a73d5d90cff4d5aef90bd8c15d
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] PCI: cadence: Store the core controller in platform drvdata
2026-09-15 8:28 [PATCH v2] PCI: cadence: Store the core controller in platform drvdata Linmao Li
@ 2026-09-15 8:39 ` sashiko-bot
2026-09-16 10:38 ` Aksh Garg
[not found] ` <1789614322740341.344.seg@mailgw.kylinos.cn>
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-09-15 8:39 UTC (permalink / raw)
To: Linmao Li; +Cc: linux-pci
> cdns_plat_pcie_probe() stores a struct cdns_plat_pcie pointer with
> platform_set_drvdata(). cdns_plat_pcie_shutdown() and the callbacks in
> cdns_pcie_pm_ops retrieve the same pointer with dev_get_drvdata() and
> use it as a struct cdns_pcie pointer. This makes them read phy_count
> and phy beyond the wrapper.
>
> struct cdns_plat_pcie only contains a pointer to struct cdns_pcie. Drop
> the redundant wrapper and store the struct cdns_pcie pointer directly.
>
> Fixes: bd22885aa188 ("PCI: cadence: Refactor driver to use as a core library")
> Suggested-by: Aksh Garg <a-garg7@ti.com>
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915082826.4135665-1-lilinmao@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] PCI: cadence: Store the core controller in platform drvdata
2026-09-15 8:28 [PATCH v2] PCI: cadence: Store the core controller in platform drvdata Linmao Li
2026-09-15 8:39 ` sashiko-bot
@ 2026-09-16 10:38 ` Aksh Garg
[not found] ` <1789614322740341.344.seg@mailgw.kylinos.cn>
2 siblings, 0 replies; 4+ messages in thread
From: Aksh Garg @ 2026-09-16 10:38 UTC (permalink / raw)
To: Linmao Li, Bjorn Helgaas, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam
Cc: Rob Herring, Tom Joseph, Vladimir Oltean, linux-pci, linux-kernel
On 15/09/26 13:58, Linmao Li wrote:
> cdns_plat_pcie_probe() stores a struct cdns_plat_pcie pointer with
> platform_set_drvdata(). cdns_plat_pcie_shutdown() and the callbacks in
> cdns_pcie_pm_ops retrieve the same pointer with dev_get_drvdata() and
> use it as a struct cdns_pcie pointer. This makes them read phy_count
> and phy beyond the wrapper.
>
> struct cdns_plat_pcie only contains a pointer to struct cdns_pcie. Drop
> the redundant wrapper and store the struct cdns_pcie pointer directly.
>
> Fixes: bd22885aa188 ("PCI: cadence: Refactor driver to use as a core library")
> Suggested-by: Aksh Garg <a-garg7@ti.com>
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
Suggested-by tag can be dropped IMO as the suggestion was not the core
insight of the patch (to store the struct cdns_pcie pointer directly).
Reviewed-by: Aksh Garg <a-garg7@ti.com>
Regards,
Aksh Garg
> Changes in v2:
> - Drop the redundant struct cdns_plat_pcie wrapper (Aksh Garg).
> ---
> .../controller/cadence/pcie-cadence-plat.c | 27 ++++++-------------
> 1 file changed, 8 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c b/drivers/pci/controller/cadence/pcie-cadence-plat.c
> index 13edc6be21f5..4a24302cc5b2 100644
> --- a/drivers/pci/controller/cadence/pcie-cadence-plat.c
> +++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c
> @@ -14,14 +14,6 @@
>
> #define CDNS_PLAT_CPU_TO_BUS_ADDR 0x0FFFFFFF
>
> -/**
> - * struct cdns_plat_pcie - private data for this PCIe platform driver
> - * @pcie: Cadence PCIe controller
> - */
> -struct cdns_plat_pcie {
> - struct cdns_pcie *pcie;
> -};
> -
> static const struct of_device_id cdns_plat_pcie_of_match[];
>
> static u64 cdns_plat_cpu_addr_fixup(struct cdns_pcie *pcie, u64 cpu_addr)
> @@ -36,9 +28,9 @@ static const struct cdns_pcie_ops cdns_plat_ops = {
> static int cdns_plat_pcie_probe(struct platform_device *pdev)
> {
> const struct cdns_plat_pcie_of_data *data;
> - struct cdns_plat_pcie *cdns_plat_pcie;
> struct device *dev = &pdev->dev;
> struct pci_host_bridge *bridge;
> + struct cdns_pcie *pcie;
> struct cdns_pcie_ep *ep;
> struct cdns_pcie_rc *rc;
> bool is_rc;
> @@ -51,11 +43,6 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> is_rc = data->is_rc;
>
> pr_debug(" Started %s with is_rc: %d\n", __func__, is_rc);
> - cdns_plat_pcie = devm_kzalloc(dev, sizeof(*cdns_plat_pcie), GFP_KERNEL);
> - if (!cdns_plat_pcie)
> - return -ENOMEM;
> -
> - platform_set_drvdata(pdev, cdns_plat_pcie);
> if (is_rc) {
> if (!IS_ENABLED(CONFIG_PCIE_CADENCE_PLAT_HOST))
> return -ENODEV;
> @@ -67,9 +54,9 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> rc = pci_host_bridge_priv(bridge);
> rc->pcie.dev = dev;
> rc->pcie.ops = &cdns_plat_ops;
> - cdns_plat_pcie->pcie = &rc->pcie;
> + pcie = &rc->pcie;
>
> - ret = cdns_pcie_init_phy(dev, cdns_plat_pcie->pcie);
> + ret = cdns_pcie_init_phy(dev, pcie);
> if (ret) {
> dev_err(dev, "failed to init phy\n");
> return ret;
> @@ -94,9 +81,9 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
>
> ep->pcie.dev = dev;
> ep->pcie.ops = &cdns_plat_ops;
> - cdns_plat_pcie->pcie = &ep->pcie;
> + pcie = &ep->pcie;
>
> - ret = cdns_pcie_init_phy(dev, cdns_plat_pcie->pcie);
> + ret = cdns_pcie_init_phy(dev, pcie);
> if (ret) {
> dev_err(dev, "failed to init phy\n");
> return ret;
> @@ -114,13 +101,15 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> goto err_init;
> }
>
> + platform_set_drvdata(pdev, pcie);
> +
> return 0;
>
> err_init:
> err_get_sync:
> pm_runtime_put_sync(dev);
> pm_runtime_disable(dev);
> - cdns_pcie_disable_phy(cdns_plat_pcie->pcie);
> + cdns_pcie_disable_phy(pcie);
>
> return ret;
> }
>
> base-commit: 9a9d18547ddc97a73d5d90cff4d5aef90bd8c15d
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] PCI: cadence: Store the core controller in platform drvdata
[not found] ` <1789614322740341.344.seg@mailgw.kylinos.cn>
@ 2026-09-17 3:25 ` Linmao Li
0 siblings, 0 replies; 4+ messages in thread
From: Linmao Li @ 2026-09-17 3:25 UTC (permalink / raw)
To: Aksh Garg, Bjorn Helgaas, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam
Cc: Rob Herring, Tom Joseph, Vladimir Oltean, linux-pci, linux-kernel
在 2026/9/16 18:38, Aksh Garg 写道:
>
>
> On 15/09/26 13:58, Linmao Li wrote:
>> cdns_plat_pcie_probe() stores a struct cdns_plat_pcie pointer with
>> platform_set_drvdata(). cdns_plat_pcie_shutdown() and the callbacks in
>> cdns_pcie_pm_ops retrieve the same pointer with dev_get_drvdata() and
>> use it as a struct cdns_pcie pointer. This makes them read phy_count
>> and phy beyond the wrapper.
>>
>> struct cdns_plat_pcie only contains a pointer to struct cdns_pcie. Drop
>> the redundant wrapper and store the struct cdns_pcie pointer directly.
>>
>> Fixes: bd22885aa188 ("PCI: cadence: Refactor driver to use as a core
>> library")
>> Suggested-by: Aksh Garg <a-garg7@ti.com>
>> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
>> ---
>
> Suggested-by tag can be dropped IMO as the suggestion was not the core
> insight of the patch (to store the struct cdns_pcie pointer directly).
>
> Reviewed-by: Aksh Garg <a-garg7@ti.com>
>
> Regards,
> Aksh Garg
Agreed, please drop the Suggested-by tag when applying. Happy to resend
a v3 with it removed if that's preferred.
Thanks,
Linmao
>
>> Changes in v2:
>> - Drop the redundant struct cdns_plat_pcie wrapper (Aksh Garg).
>> ---
>> .../controller/cadence/pcie-cadence-plat.c | 27 ++++++-------------
>> 1 file changed, 8 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c
>> b/drivers/pci/controller/cadence/pcie-cadence-plat.c
>> index 13edc6be21f5..4a24302cc5b2 100644
>> --- a/drivers/pci/controller/cadence/pcie-cadence-plat.c
>> +++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c
>> @@ -14,14 +14,6 @@
>> #define CDNS_PLAT_CPU_TO_BUS_ADDR 0x0FFFFFFF
>> -/**
>> - * struct cdns_plat_pcie - private data for this PCIe platform driver
>> - * @pcie: Cadence PCIe controller
>> - */
>> -struct cdns_plat_pcie {
>> - struct cdns_pcie *pcie;
>> -};
>> -
>> static const struct of_device_id cdns_plat_pcie_of_match[];
>> static u64 cdns_plat_cpu_addr_fixup(struct cdns_pcie *pcie, u64
>> cpu_addr)
>> @@ -36,9 +28,9 @@ static const struct cdns_pcie_ops cdns_plat_ops = {
>> static int cdns_plat_pcie_probe(struct platform_device *pdev)
>> {
>> const struct cdns_plat_pcie_of_data *data;
>> - struct cdns_plat_pcie *cdns_plat_pcie;
>> struct device *dev = &pdev->dev;
>> struct pci_host_bridge *bridge;
>> + struct cdns_pcie *pcie;
>> struct cdns_pcie_ep *ep;
>> struct cdns_pcie_rc *rc;
>> bool is_rc;
>> @@ -51,11 +43,6 @@ static int cdns_plat_pcie_probe(struct
>> platform_device *pdev)
>> is_rc = data->is_rc;
>> pr_debug(" Started %s with is_rc: %d\n", __func__, is_rc);
>> - cdns_plat_pcie = devm_kzalloc(dev, sizeof(*cdns_plat_pcie),
>> GFP_KERNEL);
>> - if (!cdns_plat_pcie)
>> - return -ENOMEM;
>> -
>> - platform_set_drvdata(pdev, cdns_plat_pcie);
>> if (is_rc) {
>> if (!IS_ENABLED(CONFIG_PCIE_CADENCE_PLAT_HOST))
>> return -ENODEV;
>> @@ -67,9 +54,9 @@ static int cdns_plat_pcie_probe(struct
>> platform_device *pdev)
>> rc = pci_host_bridge_priv(bridge);
>> rc->pcie.dev = dev;
>> rc->pcie.ops = &cdns_plat_ops;
>> - cdns_plat_pcie->pcie = &rc->pcie;
>> + pcie = &rc->pcie;
>> - ret = cdns_pcie_init_phy(dev, cdns_plat_pcie->pcie);
>> + ret = cdns_pcie_init_phy(dev, pcie);
>> if (ret) {
>> dev_err(dev, "failed to init phy\n");
>> return ret;
>> @@ -94,9 +81,9 @@ static int cdns_plat_pcie_probe(struct
>> platform_device *pdev)
>> ep->pcie.dev = dev;
>> ep->pcie.ops = &cdns_plat_ops;
>> - cdns_plat_pcie->pcie = &ep->pcie;
>> + pcie = &ep->pcie;
>> - ret = cdns_pcie_init_phy(dev, cdns_plat_pcie->pcie);
>> + ret = cdns_pcie_init_phy(dev, pcie);
>> if (ret) {
>> dev_err(dev, "failed to init phy\n");
>> return ret;
>> @@ -114,13 +101,15 @@ static int cdns_plat_pcie_probe(struct
>> platform_device *pdev)
>> goto err_init;
>> }
>> + platform_set_drvdata(pdev, pcie);
>> +
>> return 0;
>> err_init:
>> err_get_sync:
>> pm_runtime_put_sync(dev);
>> pm_runtime_disable(dev);
>> - cdns_pcie_disable_phy(cdns_plat_pcie->pcie);
>> + cdns_pcie_disable_phy(pcie);
>> return ret;
>> }
>>
>> base-commit: 9a9d18547ddc97a73d5d90cff4d5aef90bd8c15d
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-17 3:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-15 8:28 [PATCH v2] PCI: cadence: Store the core controller in platform drvdata Linmao Li
2026-09-15 8:39 ` sashiko-bot
2026-09-16 10:38 ` Aksh Garg
[not found] ` <1789614322740341.344.seg@mailgw.kylinos.cn>
2026-09-17 3:25 ` Linmao Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox