[PATCH] PCI: cadence: Store the core controller in platform drvdata

Linmao Li posted 1 patch 1 week, 3 days ago
There is a newer version of this series
drivers/pci/controller/cadence/pcie-cadence-plat.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] PCI: cadence: Store the core controller in platform drvdata
Posted by Linmao Li 1 week, 3 days ago
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
Re: [PATCH] PCI: cadence: Store the core controller in platform drvdata
Posted by Aksh Garg 1 week, 3 days ago

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