Skip to contentSkip to conversation

PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe

PATCH Superseded Qinglang Miao 2 participants 4 messages Nov 3, 2020 – Nov 6, 2020

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe

Fix the missing clk_disable_unprepare() before return from v3_pci_probe() in the error handling case.

Moving the clock enable later to avoid some fixes.

Fixes 6e0832fa432e (" PCI: Collect all native drivers under drivers/pci/controller/")
---
 drivers/pci/controller/pci-v3-semi.c | 40 ++++++++++++++++------------
 1 file changed, 23 insertions(+), 17 deletions(-)
drivers/pci/controller/pci-v3-semi.c +23 -17
index 154a53986..90520555b 100644
@@ -725,18 +725,6 @@ static int v3_pci_probe(struct platform_device *pdev)
 	host->sysdata = v3;
 	v3->dev = dev;
 
-	/* Get and enable host clock */
-	clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(clk)) {
-		dev_err(dev, "clock not found\n");
-		return PTR_ERR(clk);
-	}
-	ret = clk_prepare_enable(clk);
-	if (ret) {
-		dev_err(dev, "unable to enable clock\n");
-		return ret;
-	}
-
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	v3->base = devm_ioremap_resource(dev, regs);
 	if (IS_ERR(v3->base))
@@ -761,17 +749,31 @@ static int v3_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(v3->config_base))
 		return PTR_ERR(v3->config_base);
 
+	/* Get and enable host clock */
+	clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(clk)) {
+		dev_err(dev, "clock not found\n");
+		return PTR_ERR(clk);
+	}
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		dev_err(dev, "unable to enable clock\n");
+		return ret;
+	}
+
 	/* Get and request error IRQ resource */
 	irq = platform_get_irq(pdev, 0);
-	if (irq < 0)
+	if (irq < 0) {
+		clk_disable_unprepare(clk);
 		return irq;
-
+	}
 	ret = devm_request_irq(dev, irq, v3_irq, 0,
 			"PCIv3 error", v3);
 	if (ret < 0) {
 		dev_err(dev,
 			"unable to request PCIv3 error IRQ %d (%d)\n",
 			irq, ret);
+		clk_disable_unprepare(clk);
 		return ret;
 	}
 
@@ -814,13 +816,15 @@ static int v3_pci_probe(struct platform_device *pdev)
 		ret = v3_pci_setup_resource(v3, host, win);
 		if (ret) {
 			dev_err(dev, "error setting up resources\n");
+			clk_disable_unprepare(clk);
 			return ret;
 		}
 	}
 	ret = v3_pci_parse_map_dma_ranges(v3, np);
-	if (ret)
+	if (ret) {
+		clk_disable_unprepare(clk);
 		return ret;
-
+	}
 	/*
 	 * Disable PCI to host IO cycles, enable I/O buffers @3.3V,
 	 * set AD_LOW0 to 1 if one of the LB_MAP registers choose
@@ -862,8 +866,10 @@ static int v3_pci_probe(struct platform_device *pdev)
 	/* Special Integrator initialization */
 	if (of_device_is_compatible(np, "arm,integrator-ap-pci")) {
 		ret = v3_integrator_init(v3);
-		if (ret)
+		if (ret) {
+			clk_disable_unprepare(clk);
 			return ret;
+		}
 	}
 
 	/* Post-init: enable PCI memory and invalidate (master already on) */
Signature · 1 line
2.23.0
reviewer
#1 lore raw
Quoted 7 lines · Qinglang Miao

Fix the missing clk_disable_unprepare() before return from v3_pci_probe() in the error handling case.

Moving the clock enable later to avoid some fixes.

Fixes 6e0832fa432e (" PCI: Collect all native drivers under drivers/pci/controller/")

I don't think this commit caused the problem.

Quoted 82 lines
---
 drivers/pci/controller/pci-v3-semi.c | 40 ++++++++++++++++------------
 1 file changed, 23 insertions(+), 17 deletions(-)
drivers/pci/controller/pci-v3-semi.c +20 -16
index 154a53986..90520555b 100644
@@ -725,18 +725,6 @@ static int v3_pci_probe(struct platform_device *pdev)
        host->sysdata = v3;
        v3->dev = dev;
 
-       /* Get and enable host clock */
-       clk = devm_clk_get(dev, NULL);
-       if (IS_ERR(clk)) {
-               dev_err(dev, "clock not found\n");
-               return PTR_ERR(clk);
-       }
-       ret = clk_prepare_enable(clk);
-       if (ret) {
-               dev_err(dev, "unable to enable clock\n");
-               return ret;
-       }
-
        regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        v3->base = devm_ioremap_resource(dev, regs);
        if (IS_ERR(v3->base))
@@ -761,17 +749,31 @@ static int v3_pci_probe(struct platform_device *pdev)
        if (IS_ERR(v3->config_base))
                return PTR_ERR(v3->config_base);
 
+       /* Get and enable host clock */
+       clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(clk)) {
+               dev_err(dev, "clock not found\n");
+               return PTR_ERR(clk);
+       }
+       ret = clk_prepare_enable(clk);
+       if (ret) {
+               dev_err(dev, "unable to enable clock\n");
+               return ret;
+       }
+
        /* Get and request error IRQ resource */
        irq = platform_get_irq(pdev, 0);
-       if (irq < 0)
+       if (irq < 0) {
+               clk_disable_unprepare(clk);
                return irq;
-
+       }
        ret = devm_request_irq(dev, irq, v3_irq, 0,
                        "PCIv3 error", v3);
        if (ret < 0) {
                dev_err(dev,
                        "unable to request PCIv3 error IRQ %d (%d)\n",
                        irq, ret);
+               clk_disable_unprepare(clk);
                return ret;
        }
 
@@ -814,13 +816,15 @@ static int v3_pci_probe(struct platform_device *pdev)
                ret = v3_pci_setup_resource(v3, host, win);
                if (ret) {
                        dev_err(dev, "error setting up resources\n");
+                       clk_disable_unprepare(clk);
                        return ret;
                }
        }
        ret = v3_pci_parse_map_dma_ranges(v3, np);
-       if (ret)
+       if (ret) {
+               clk_disable_unprepare(clk);
                return ret;
-
+       }
        /*
         * Disable PCI to host IO cycles, enable I/O buffers @3.3V,
         * set AD_LOW0 to 1 if one of the LB_MAP registers choose

drivers/pci/controller/pci-v3-semi.c static int v3_pci_probe(struct platform_device *pdev) · line 870

Quoted 6 lines
drivers/pci/controller/pci-v3-semi.c +2 -1
@@ -862,8 +866,10 @@ static int v3_pci_probe(struct platform_device *pdev)
        /* Special Integrator initialization */
        if (of_device_is_compatible(np, "arm,integrator-ap-pci")) {
                ret = v3_integrator_init(v3);
-               if (ret)
+               if (ret) {
+                       clk_disable_unprepare(clk);

You should make all these a goto and just have one clk_disable_unprepare() call.

You are still missing error handling after pci_host_probe().

Quoted 8 lines
drivers/pci/controller/pci-v3-semi.c +1 -1
                        return ret;
+               }
        }
 
        /* Post-init: enable PCI memory and invalidate (master already on) */
--

2.23.0

#2 lore raw
Quoted 102 lines · Rob Herring
Quoted 7 lines · Qinglang Miao

Fix the missing clk_disable_unprepare() before return from v3_pci_probe() in the error handling case.

Moving the clock enable later to avoid some fixes.

Fixes 6e0832fa432e (" PCI: Collect all native drivers under drivers/pci/controller/")

I don't think this commit caused the problem.

Quoted 82 lines
---
  drivers/pci/controller/pci-v3-semi.c | 40 ++++++++++++++++------------
  1 file changed, 23 insertions(+), 17 deletions(-)
drivers/pci/controller/pci-v3-semi.c +20 -16
index 154a53986..90520555b 100644
@@ -725,18 +725,6 @@ static int v3_pci_probe(struct platform_device *pdev)
         host->sysdata = v3;
         v3->dev = dev;
 
-       /* Get and enable host clock */
-       clk = devm_clk_get(dev, NULL);
-       if (IS_ERR(clk)) {
-               dev_err(dev, "clock not found\n");
-               return PTR_ERR(clk);
-       }
-       ret = clk_prepare_enable(clk);
-       if (ret) {
-               dev_err(dev, "unable to enable clock\n");
-               return ret;
-       }
-
         regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
         v3->base = devm_ioremap_resource(dev, regs);
         if (IS_ERR(v3->base))
@@ -761,17 +749,31 @@ static int v3_pci_probe(struct platform_device *pdev)
         if (IS_ERR(v3->config_base))
                 return PTR_ERR(v3->config_base);
 
+       /* Get and enable host clock */
+       clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(clk)) {
+               dev_err(dev, "clock not found\n");
+               return PTR_ERR(clk);
+       }
+       ret = clk_prepare_enable(clk);
+       if (ret) {
+               dev_err(dev, "unable to enable clock\n");
+               return ret;
+       }
+
         /* Get and request error IRQ resource */
         irq = platform_get_irq(pdev, 0);
-       if (irq < 0)
+       if (irq < 0) {
+               clk_disable_unprepare(clk);
                 return irq;
-
+       }
         ret = devm_request_irq(dev, irq, v3_irq, 0,
                         "PCIv3 error", v3);
         if (ret < 0) {
                 dev_err(dev,
                         "unable to request PCIv3 error IRQ %d (%d)\n",
                         irq, ret);
+               clk_disable_unprepare(clk);
                 return ret;
         }
 
@@ -814,13 +816,15 @@ static int v3_pci_probe(struct platform_device *pdev)
                 ret = v3_pci_setup_resource(v3, host, win);
                 if (ret) {
                         dev_err(dev, "error setting up resources\n");
+                       clk_disable_unprepare(clk);
                         return ret;
                 }
         }
         ret = v3_pci_parse_map_dma_ranges(v3, np);
-       if (ret)
+       if (ret) {
+               clk_disable_unprepare(clk);
                 return ret;
-
+       }
         /*
          * Disable PCI to host IO cycles, enable I/O buffers @3.3V,
          * set AD_LOW0 to 1 if one of the LB_MAP registers choose

drivers/pci/controller/pci-v3-semi.c static int v3_pci_probe(struct platform_device *pdev) · line 870

Quoted 6 lines
drivers/pci/controller/pci-v3-semi.c +2 -1
@@ -862,8 +866,10 @@ static int v3_pci_probe(struct platform_device *pdev)
         /* Special Integrator initialization */
         if (of_device_is_compatible(np, "arm,integrator-ap-pci")) {
                 ret = v3_integrator_init(v3);
-               if (ret)
+               if (ret) {
+                       clk_disable_unprepare(clk);

You should make all these a goto and just have one clk_disable_unprepare() call.

Quoted 1 line

You are still missing error handling after pci_host_probe().

Hi Rob,

I've sent a v3 patch towards this bug.

Thanks a lot for your advice.

Quoted 11 lines
Quoted 9 lines
drivers/pci/controller/pci-v3-semi.c +1 -1
                         return ret;
+               }
         }
 
         /* Post-init: enable PCI memory and invalidate (master already on) */
--

2.23.0

.

#3 lore raw
In reply to Rob Herring
Quoted 102 lines · Rob Herring
Quoted 7 lines · Qinglang Miao

Fix the missing clk_disable_unprepare() before return from v3_pci_probe() in the error handling case.

Moving the clock enable later to avoid some fixes.

Fixes 6e0832fa432e (" PCI: Collect all native drivers under drivers/pci/controller/")

I don't think this commit caused the problem.

Quoted 82 lines
---
  drivers/pci/controller/pci-v3-semi.c | 40 ++++++++++++++++------------
  1 file changed, 23 insertions(+), 17 deletions(-)
drivers/pci/controller/pci-v3-semi.c +20 -16
index 154a53986..90520555b 100644
@@ -725,18 +725,6 @@ static int v3_pci_probe(struct platform_device *pdev)
         host->sysdata = v3;
         v3->dev = dev;
 
-       /* Get and enable host clock */
-       clk = devm_clk_get(dev, NULL);
-       if (IS_ERR(clk)) {
-               dev_err(dev, "clock not found\n");
-               return PTR_ERR(clk);
-       }
-       ret = clk_prepare_enable(clk);
-       if (ret) {
-               dev_err(dev, "unable to enable clock\n");
-               return ret;
-       }
-
         regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
         v3->base = devm_ioremap_resource(dev, regs);
         if (IS_ERR(v3->base))
@@ -761,17 +749,31 @@ static int v3_pci_probe(struct platform_device *pdev)
         if (IS_ERR(v3->config_base))
                 return PTR_ERR(v3->config_base);
 
+       /* Get and enable host clock */
+       clk = devm_clk_get(dev, NULL);
+       if (IS_ERR(clk)) {
+               dev_err(dev, "clock not found\n");
+               return PTR_ERR(clk);
+       }
+       ret = clk_prepare_enable(clk);
+       if (ret) {
+               dev_err(dev, "unable to enable clock\n");
+               return ret;
+       }
+
         /* Get and request error IRQ resource */
         irq = platform_get_irq(pdev, 0);
-       if (irq < 0)
+       if (irq < 0) {
+               clk_disable_unprepare(clk);
                 return irq;
-
+       }
         ret = devm_request_irq(dev, irq, v3_irq, 0,
                         "PCIv3 error", v3);
         if (ret < 0) {
                 dev_err(dev,
                         "unable to request PCIv3 error IRQ %d (%d)\n",
                         irq, ret);
+               clk_disable_unprepare(clk);
                 return ret;
         }
 
@@ -814,13 +816,15 @@ static int v3_pci_probe(struct platform_device *pdev)
                 ret = v3_pci_setup_resource(v3, host, win);
                 if (ret) {
                         dev_err(dev, "error setting up resources\n");
+                       clk_disable_unprepare(clk);
                         return ret;
                 }
         }
         ret = v3_pci_parse_map_dma_ranges(v3, np);
-       if (ret)
+       if (ret) {
+               clk_disable_unprepare(clk);
                 return ret;
-
+       }
         /*
          * Disable PCI to host IO cycles, enable I/O buffers @3.3V,
          * set AD_LOW0 to 1 if one of the LB_MAP registers choose

drivers/pci/controller/pci-v3-semi.c static int v3_pci_probe(struct platform_device *pdev) · line 870

Quoted 6 lines
drivers/pci/controller/pci-v3-semi.c +2 -1
@@ -862,8 +866,10 @@ static int v3_pci_probe(struct platform_device *pdev)
         /* Special Integrator initialization */
         if (of_device_is_compatible(np, "arm,integrator-ap-pci")) {
                 ret = v3_integrator_init(v3);
-               if (ret)
+               if (ret) {
+                       clk_disable_unprepare(clk);

You should make all these a goto and just have one clk_disable_unprepare() call.

Quoted 1 line

You are still missing error handling after pci_host_probe().

I made a mistake on author name on v3 so resent a v4 on this one.

Sorry about that.

Quoted 11 lines
Quoted 9 lines
drivers/pci/controller/pci-v3-semi.c +1 -1
                         return ret;
+               }
         }
 
         /* Post-init: enable PCI memory and invalidate (master already on) */
--

2.23.0

.