* [PATCH] PCI: cadence: Store the core controller in platform drvdata
@ 2026-09-15 3:00 Linmao Li
2026-09-15 3:11 ` sashiko-bot
2026-09-15 5:52 ` Aksh Garg
0 siblings, 2 replies; 3+ messages in thread
From: Linmao Li @ 2026-09-15 3:00 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.
Store the wrapped struct cdns_pcie pointer instead.
Fixes: bd22885aa188 ("PCI: cadence: Refactor driver to use as a core library")
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
drivers/pci/controller/cadence/pcie-cadence-plat.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c b/drivers/pci/controller/cadence/pcie-cadence-plat.c
index 13edc6be21f5..7fef237cdbb7 100644
--- a/drivers/pci/controller/cadence/pcie-cadence-plat.c
+++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c
@@ -55,7 +55,6 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
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;
@@ -114,6 +113,8 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
goto err_init;
}
+ platform_set_drvdata(pdev, cdns_plat_pcie->pcie);
+
return 0;
err_init:
base-commit: 9a9d18547ddc97a73d5d90cff4d5aef90bd8c15d
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: cadence: Store the core controller in platform drvdata
2026-09-15 3:00 [PATCH] PCI: cadence: Store the core controller in platform drvdata Linmao Li
@ 2026-09-15 3:11 ` sashiko-bot
2026-09-15 5:52 ` Aksh Garg
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-15 3:11 UTC (permalink / raw)
To: Linmao Li; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] pci: redundant devm_kzalloc of cdns_plat_pcie
--
commit 39b7fc87ca3505b497481f44dd0a65579dc50f60
Author: Linmao Li <lilinmao@kylinos.cn>
PCI: cadence: Store the core controller in platform drvdata
This commit updates cdns_plat_pcie_probe() to store the wrapped
struct cdns_pcie pointer directly in the platform drvdata. This prevents
suspend/resume callbacks from incorrectly casting the pointer and
reading beyond the wrapper structure.
> diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c b/drivers/pci/controller/cadence/pcie-cadence-plat.c
> index 13edc6be21f59..7fef237cdbb74 100644
> --- a/drivers/pci/controller/cadence/pcie-cadence-plat.c
> +++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c
> @@ -55,7 +55,6 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> if (!cdns_plat_pcie)
> return -ENOMEM;
[Severity: Low]
Does this code leave behind a completely redundant memory allocation?
Since the patch changes the driver to store the inner pcie pointer directly
instead of the cdns_plat_pcie wrapper, the prior allocation of
struct cdns_plat_pcie appears to be completely unnecessary now.
> - platform_set_drvdata(pdev, cdns_plat_pcie);
> if (is_rc) {
> if (!IS_ENABLED(CONFIG_PCIE_CADENCE_PLAT_HOST))
> return -ENODEV;
[ ... ]
> @@ -114,6 +113,8 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> goto err_init;
> }
>
> + platform_set_drvdata(pdev, cdns_plat_pcie->pcie);
> +
[Severity: Low]
Because only the internal pointer is saved here, does this permanently
orphan the allocated container structure from external access?
The cdns_plat_pcie structure is no longer exposed outside of the local
scope of cdns_plat_pcie_probe(), rendering the structure as dead code.
> return 0;
>
> err_init:
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915030044.4019259-1-lilinmao@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PCI: cadence: Store the core controller in platform drvdata
2026-09-15 3:00 [PATCH] PCI: cadence: Store the core controller in platform drvdata Linmao Li
2026-09-15 3:11 ` sashiko-bot
@ 2026-09-15 5:52 ` Aksh Garg
1 sibling, 0 replies; 3+ messages in thread
From: Aksh Garg @ 2026-09-15 5:52 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 08:30, 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.
>
> Store the wrapped struct cdns_pcie pointer instead.
>
> Fixes: bd22885aa188 ("PCI: cadence: Refactor driver to use as a core library")
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
Hi Linmao,
Since commit e111ac7025cb ("PCI: cadence: Drop unused member from struct
cdns_plat_pcie"), struct cdns_plat_pcie only contains a pointer to
struct cdns_pcie.
As sashiko pointed pointed, struct cdns_plat_pcie now becomes redundant
and should be removed.
Regards,
Aksh Garg
> drivers/pci/controller/cadence/pcie-cadence-plat.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/cadence/pcie-cadence-plat.c b/drivers/pci/controller/cadence/pcie-cadence-plat.c
> index 13edc6be21f5..7fef237cdbb7 100644
> --- a/drivers/pci/controller/cadence/pcie-cadence-plat.c
> +++ b/drivers/pci/controller/cadence/pcie-cadence-plat.c
> @@ -55,7 +55,6 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> 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;
> @@ -114,6 +113,8 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
> goto err_init;
> }
>
> + platform_set_drvdata(pdev, cdns_plat_pcie->pcie);
> +
> return 0;
>
> err_init:
>
> base-commit: 9a9d18547ddc97a73d5d90cff4d5aef90bd8c15d
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-15 5:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-15 3:00 [PATCH] PCI: cadence: Store the core controller in platform drvdata Linmao Li
2026-09-15 3:11 ` sashiko-bot
2026-09-15 5:52 ` Aksh Garg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox