diff mbox

PCI: rcar: Check for OF device match early

Message ID 20170131151044.14062.85997.stgit@bhelgaas-glaptop.roam.corp.google.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Bjorn Helgaas Jan. 31, 2017, 3:10 p.m. UTC
A match in the rcar_pcie_of_match[] table is required, so check that first,
before we start setting up things that need to be undone if it fails.  No
functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pcie-rcar.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Geert Uytterhoeven Jan. 31, 2017, 3:33 p.m. UTC | #1
Hi Bjorn,

On Tue, Jan 31, 2017 at 4:10 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> A match in the rcar_pcie_of_match[] table is required, so check that first,
> before we start setting up things that need to be undone if it fails.  No
> functional change intended.
>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> ---
>  drivers/pci/host/pcie-rcar.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
> index 0d9b96c3c49d..c91ff0b91be8 100644
> --- a/drivers/pci/host/pcie-rcar.c
> +++ b/drivers/pci/host/pcie-rcar.c
> @@ -1129,6 +1129,10 @@ static int rcar_pcie_probe(struct platform_device *pdev)
>         int err;
>         int (*hw_init_fn)(struct rcar_pcie *);
>
> +       of_id = of_match_device(rcar_pcie_of_match, dev);
> +       if (!of_id || !of_id->data)
> +               return -EINVAL;
> +

As this driver is DT-only, none of the above can fail, and you could just do

       hw_init_fn = of_device_get_match_data(dev);

instead, getting rid of of_id completely.

>         pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
>         if (!pcie)
>                 return -ENOMEM;
> @@ -1149,11 +1153,6 @@ static int rcar_pcie_probe(struct platform_device *pdev)
>         if (err)
>                 return err;
>
> -       of_id = of_match_device(rcar_pcie_of_match, dev);
> -       if (!of_id || !of_id->data)
> -               return -EINVAL;
> -       hw_init_fn = of_id->data;
> -
>         pm_runtime_enable(dev);
>         err = pm_runtime_get_sync(dev);
>         if (err < 0) {
> @@ -1162,6 +1161,7 @@ static int rcar_pcie_probe(struct platform_device *pdev)
>         }
>
>         /* Failure to get a link might just be that no cards are inserted */
> +       hw_init_fn = of_id->data;
>         err = hw_init_fn(pcie);
>         if (err) {
>                 dev_info(dev, "PCIe link down\n");
>
diff mbox

Patch

diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 0d9b96c3c49d..c91ff0b91be8 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -1129,6 +1129,10 @@  static int rcar_pcie_probe(struct platform_device *pdev)
 	int err;
 	int (*hw_init_fn)(struct rcar_pcie *);
 
+	of_id = of_match_device(rcar_pcie_of_match, dev);
+	if (!of_id || !of_id->data)
+		return -EINVAL;
+
 	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
 	if (!pcie)
 		return -ENOMEM;
@@ -1149,11 +1153,6 @@  static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	of_id = of_match_device(rcar_pcie_of_match, dev);
-	if (!of_id || !of_id->data)
-		return -EINVAL;
-	hw_init_fn = of_id->data;
-
 	pm_runtime_enable(dev);
 	err = pm_runtime_get_sync(dev);
 	if (err < 0) {
@@ -1162,6 +1161,7 @@  static int rcar_pcie_probe(struct platform_device *pdev)
 	}
 
 	/* Failure to get a link might just be that no cards are inserted */
+	hw_init_fn = of_id->data;
 	err = hw_init_fn(pcie);
 	if (err) {
 		dev_info(dev, "PCIe link down\n");