lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 2 Feb 2022 10:26:59 -0600
From:   Bjorn Helgaas <helgaas@...nel.org>
To:     Bean Huo <huobean@...il.com>
Cc:     songxiaowei@...ilicon.com, wangbinghui@...ilicon.com,
        lorenzo.pieralisi@....com, robh@...nel.org, kw@...ux.com,
        bhelgaas@...gle.com, ffclaire1224@...il.com,
        linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
        beanhuo@...ron.com
Subject: Re: [PATCH] PCI: kirin: Fix kirin960-pcie probe failure issue

[+cc Fan]

If you're fixing a previous commit, please cc the author of that
commit.

I'd prefer the patch below because it avoids the casts of .data and
the of_device_get_match_data() result, it doesn't silently default to
PCIE_KIRIN_INTERNAL_PHY if a device without a .data is added, and it's 
the most common design pattern in drivers/pci/.

What do you think?

On Tue, Feb 01, 2022 at 10:59:41PM +0100, Bean Huo wrote:
> From: Bean Huo <beanhuo@...ron.com>
> 
> of_device_get_match_data() will return 'enum pcie_kirin_phy_type' type
> value, and most likely the return value will be PCIE_KIRIN_INTERNAL_PHY == 0.
> This will cause the PCI probe to fail. And of_device_get_match_data() does not
> require error checking on its return on devicetree based platform.
> 
> So,this patch is to remove unnecessary error checking to fix kirin960-pcie
> probe failure issue.
> 
> Fixes: a622435fbe1a ("PCI: kirin: Prefer of_device_get_match_data()")
> Signed-off-by: Bean Huo <beanhuo@...ron.com>
> ---
>  drivers/pci/controller/dwc/pcie-kirin.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
> index fa6886d66488..e102aa6efb7f 100644
> --- a/drivers/pci/controller/dwc/pcie-kirin.c
> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
> @@ -781,12 +781,7 @@ static int kirin_pcie_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	phy_type = (long)of_device_get_match_data(dev);
> -	if (!phy_type) {
> -		dev_err(dev, "OF data missing\n");
> -		return -EINVAL;
> -	}
> -
> +	phy_type = (enum pcie_kirin_phy_type)of_device_get_match_data(dev);
>  
>  	kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL);
>  	if (!kirin_pcie)


commit 3e21687be135 ("PCI: kirin: Add dev struct for of_device_get_match_data()")
Author: Bjorn Helgaas <bhelgaas@...gle.com>
Date:   Wed Feb 2 09:52:41 2022 -0600

    PCI: kirin: Add dev struct for of_device_get_match_data()
    
    a622435fbe1a ("PCI: kirin: Prefer of_device_get_match_data()") broke
    kirin_pcie_probe() because it assumed match data of 0 was a failure when in
    fact, it meant the match data was "(void *)PCIE_KIRIN_INTERNAL_PHY".
    
    Therefore, probing of "hisilicon,kirin960-pcie" devices failed with -EINVAL
    and an "OF data missing" message.
    
    Add a struct kirin_pcie_data to encode the PHY type.  Then the result of
    of_device_get_match_data() should always be a non-NULL pointer to a struct
    kirin_pcie_data that contains the PHY type.
    
    Fixes: a622435fbe1a ("PCI: kirin: Prefer of_device_get_match_data()")
    Signed-off-by: Bjorn Helgaas <bhelgaas@...gle.com>

diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
index fa6886d66488..0dc4e3395b37 100644
--- a/drivers/pci/controller/dwc/pcie-kirin.c
+++ b/drivers/pci/controller/dwc/pcie-kirin.c
@@ -756,21 +756,27 @@ static int __exit kirin_pcie_remove(struct platform_device *pdev)
 	return 0;
 }
 
+struct kirin_pcie_data {
+	enum pcie_kirin_phy_type	phy_type;
+};
+
+static const struct kirin_pcie_data kirin_960_data = {
+	.phy_type = PCIE_KIRIN_INTERNAL_PHY;
+};
+
+static const struct kirin_pcie_data kirin_970_data = {
+	.phy_type = PCIE_KIRIN_EXTERNAL_PHY;
+};
+
 static const struct of_device_id kirin_pcie_match[] = {
-	{
-		.compatible = "hisilicon,kirin960-pcie",
-		.data = (void *)PCIE_KIRIN_INTERNAL_PHY
-	},
-	{
-		.compatible = "hisilicon,kirin970-pcie",
-		.data = (void *)PCIE_KIRIN_EXTERNAL_PHY
-	},
+	{ .compatible = "hisilicon,kirin960-pcie", .data = &kirin_960_data },
+	{ .compatible = "hisilicon,kirin970-pcie", .data = &kirin_970_data },
 	{},
 };
 
 static int kirin_pcie_probe(struct platform_device *pdev)
 {
-	enum pcie_kirin_phy_type phy_type;
+	struct kirin_pcie_data *data;
 	struct device *dev = &pdev->dev;
 	struct kirin_pcie *kirin_pcie;
 	struct dw_pcie *pci;
@@ -781,13 +787,12 @@ static int kirin_pcie_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	phy_type = (long)of_device_get_match_data(dev);
-	if (!phy_type) {
+	data = of_device_get_match_data(dev);
+	if (!data) {
 		dev_err(dev, "OF data missing\n");
 		return -EINVAL;
 	}
 
-
 	kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL);
 	if (!kirin_pcie)
 		return -ENOMEM;
@@ -800,7 +805,7 @@ static int kirin_pcie_probe(struct platform_device *pdev)
 	pci->ops = &kirin_dw_pcie_ops;
 	pci->pp.ops = &kirin_pcie_host_ops;
 	kirin_pcie->pci = pci;
-	kirin_pcie->type = phy_type;
+	kirin_pcie->type = data->phy_type;
 
 	ret = kirin_pcie_get_resource(kirin_pcie, pdev);
 	if (ret)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ