linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe
@ 2020-10-30  1:34 Qinglang Miao
  2020-11-02 13:48 ` Rob Herring
  0 siblings, 1 reply; 3+ messages in thread
From: Qinglang Miao @ 2020-10-30  1:34 UTC (permalink / raw)
  To: Linus Walleij, Lorenzo Pieralisi, Rob Herring, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, Qinglang Miao

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

Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/pci/controller/pci-v3-semi.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
index 154a53986..e24abc5b4 100644
--- a/drivers/pci/controller/pci-v3-semi.c
+++ b/drivers/pci/controller/pci-v3-semi.c
@@ -739,8 +739,10 @@ static int v3_pci_probe(struct platform_device *pdev)
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	v3->base = devm_ioremap_resource(dev, regs);
-	if (IS_ERR(v3->base))
+	if (IS_ERR(v3->base)) {
+		clk_disable_unprepare(clk);
 		return PTR_ERR(v3->base);
+	}
 	/*
 	 * The hardware has a register with the physical base address
 	 * of the V3 controller itself, verify that this is the same
@@ -754,17 +756,22 @@ static int v3_pci_probe(struct platform_device *pdev)
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (resource_size(regs) != SZ_16M) {
 		dev_err(dev, "config mem is not 16MB!\n");
+		clk_disable_unprepare(clk);
 		return -EINVAL;
 	}
 	v3->config_mem = regs->start;
 	v3->config_base = devm_ioremap_resource(dev, regs);
-	if (IS_ERR(v3->config_base))
+	if (IS_ERR(v3->config_base)) {
+		clk_disable_unprepare(clk);
 		return PTR_ERR(v3->config_base);
+	}
 
 	/* 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);
@@ -772,6 +779,7 @@ static int v3_pci_probe(struct platform_device *pdev)
 		dev_err(dev,
 			"unable to request PCIv3 error IRQ %d (%d)\n",
 			irq, ret);
+		clk_disable_unprepare(clk);
 		return ret;
 	}
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe
  2020-10-30  1:34 [PATCH] PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe Qinglang Miao
@ 2020-11-02 13:48 ` Rob Herring
  2020-11-03  7:27   ` miaoqinglang
  0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2020-11-02 13:48 UTC (permalink / raw)
  To: Qinglang Miao
  Cc: Linus Walleij, Lorenzo Pieralisi, Bjorn Helgaas, PCI, linux-kernel

On Thu, Oct 29, 2020 at 8:28 PM Qinglang Miao <miaoqinglang@huawei.com> wrote:
>
> Fix the missing clk_disable_unprepare() before return
> from v3_pci_probe() in the error handling case.
>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---
>  drivers/pci/controller/pci-v3-semi.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
> index 154a53986..e24abc5b4 100644
> --- a/drivers/pci/controller/pci-v3-semi.c
> +++ b/drivers/pci/controller/pci-v3-semi.c
> @@ -739,8 +739,10 @@ static int v3_pci_probe(struct platform_device *pdev)
>
>         regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>         v3->base = devm_ioremap_resource(dev, regs);
> -       if (IS_ERR(v3->base))
> +       if (IS_ERR(v3->base)) {
> +               clk_disable_unprepare(clk);

You can reorder things moving the clock enable later (after mapping
resources, but before devm_request_irq) and avoid some of these. Also
move this check down:

if (readl(v3->base + V3_LB_IO_BASE) != (regs->start >> 16))


>                 return PTR_ERR(v3->base);
> +       }
>         /*
>          * The hardware has a register with the physical base address
>          * of the V3 controller itself, verify that this is the same
> @@ -754,17 +756,22 @@ static int v3_pci_probe(struct platform_device *pdev)
>         regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>         if (resource_size(regs) != SZ_16M) {
>                 dev_err(dev, "config mem is not 16MB!\n");
> +               clk_disable_unprepare(clk);
>                 return -EINVAL;
>         }
>         v3->config_mem = regs->start;
>         v3->config_base = devm_ioremap_resource(dev, regs);
> -       if (IS_ERR(v3->config_base))
> +       if (IS_ERR(v3->config_base)) {
> +               clk_disable_unprepare(clk);
>                 return PTR_ERR(v3->config_base);
> +       }
>
>         /* 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);
> @@ -772,6 +779,7 @@ static int v3_pci_probe(struct platform_device *pdev)
>                 dev_err(dev,
>                         "unable to request PCIv3 error IRQ %d (%d)\n",
>                         irq, ret);
> +               clk_disable_unprepare(clk);
>                 return ret;

You still leave the clock enabled if pci_host_probe() fails.

Rob

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe
  2020-11-02 13:48 ` Rob Herring
@ 2020-11-03  7:27   ` miaoqinglang
  0 siblings, 0 replies; 3+ messages in thread
From: miaoqinglang @ 2020-11-03  7:27 UTC (permalink / raw)
  To: Rob Herring
  Cc: Linus Walleij, Lorenzo Pieralisi, Bjorn Helgaas, PCI, linux-kernel



在 2020/11/2 21:48, Rob Herring 写道:
> On Thu, Oct 29, 2020 at 8:28 PM Qinglang Miao <miaoqinglang@huawei.com> wrote:
>>
>> Fix the missing clk_disable_unprepare() before return
>> from v3_pci_probe() in the error handling case.
>>
>> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
>> ---
>>   drivers/pci/controller/pci-v3-semi.c | 14 +++++++++++---
>>   1 file changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/pci/controller/pci-v3-semi.c b/drivers/pci/controller/pci-v3-semi.c
>> index 154a53986..e24abc5b4 100644
>> --- a/drivers/pci/controller/pci-v3-semi.c
>> +++ b/drivers/pci/controller/pci-v3-semi.c
>> @@ -739,8 +739,10 @@ static int v3_pci_probe(struct platform_device *pdev)
>>
>>          regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>          v3->base = devm_ioremap_resource(dev, regs);
>> -       if (IS_ERR(v3->base))
>> +       if (IS_ERR(v3->base)) {
>> +               clk_disable_unprepare(clk);
> 
> You can reorder things moving the clock enable later (after mapping
> resources, but before devm_request_irq) and avoid some of these. Also
> move this check down:
> 
> if (readl(v3->base + V3_LB_IO_BASE) != (regs->start >> 16))
> 
Hi Rob,

I've sent a new patch which reorder things and cover all error branches.

But I'm not sure why and where should I move this check down:
if (readl(v3->base + V3_LB_IO_BASE) != (regs->start >> 16)).  So I 
didn't move it in current version.

If you think it's still necessary, please let me know.

Thanks.
> 
>>                  return PTR_ERR(v3->base);
>> +       }
>>          /*
>>           * The hardware has a register with the physical base address
>>           * of the V3 controller itself, verify that this is the same
>> @@ -754,17 +756,22 @@ static int v3_pci_probe(struct platform_device *pdev)
>>          regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>>          if (resource_size(regs) != SZ_16M) {
>>                  dev_err(dev, "config mem is not 16MB!\n");
>> +               clk_disable_unprepare(clk);
>>                  return -EINVAL;
>>          }
>>          v3->config_mem = regs->start;
>>          v3->config_base = devm_ioremap_resource(dev, regs);
>> -       if (IS_ERR(v3->config_base))
>> +       if (IS_ERR(v3->config_base)) {
>> +               clk_disable_unprepare(clk);
>>                  return PTR_ERR(v3->config_base);
>> +       }
>>
>>          /* 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);
>> @@ -772,6 +779,7 @@ static int v3_pci_probe(struct platform_device *pdev)
>>                  dev_err(dev,
>>                          "unable to request PCIv3 error IRQ %d (%d)\n",
>>                          irq, ret);
>> +               clk_disable_unprepare(clk);
>>                  return ret;
> 
> You still leave the clock enabled if pci_host_probe() fails.
> 
> Rob
> .
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-03  7:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30  1:34 [PATCH] PCI: v3: fix missing clk_disable_unprepare() on error in v3_pci_probe Qinglang Miao
2020-11-02 13:48 ` Rob Herring
2020-11-03  7:27   ` miaoqinglang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).