mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions
@ 2023-04-30 12:51 Ziliang Liao
  2023-04-30 12:51 ` [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe() Ziliang Liao
  2023-05-08 13:34 ` [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Linus Walleij
  0 siblings, 2 replies; 6+ messages in thread
From: Ziliang Liao @ 2023-04-30 12:51 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Linus Walleij
  Cc: hust-os-kernel-patches, Ziliang Liao, Dongliang Mu,
	linux-arm-msm, linux-kernel

Smatch reports:

drivers/bus/qcom-ebi2.c:387 qcom_ebi2_probe() warn: 'ebi2clk' from
clk_prepare_enable() not released on lines: 358.

drivers/bus/qcom-ebi2.c:387 qcom_ebi2_probe() warn: 'ebi2xclk' from
clk_prepare_enabled() not released on lines: 358.

The clk_disable_unprepare() is only used to explicitly release resources
when the qcom_ebi2_probe() fails, and when executed correctly, it may
cause resource leakage due to unknown release time.

Replace devm_clk_get() and clk_prepare_enable() with
devm_clk_get_enabled() to automatically manage the allocated resources.

Fixes: 335a12754808 ("bus: qcom: add EBI2 driver")
Signed-off-by: Ziliang Liao <saraday@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
The issue is found by static analyzer. The patched code has passed
Smatch checker, but remains untested on real device.

 drivers/bus/qcom-ebi2.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/bus/qcom-ebi2.c b/drivers/bus/qcom-ebi2.c
index c1fef1b4bd89..3999e969e1cf 100644
--- a/drivers/bus/qcom-ebi2.c
+++ b/drivers/bus/qcom-ebi2.c
@@ -303,40 +303,28 @@ static int qcom_ebi2_probe(struct platform_device *pdev)
 	u32 val;
 	int ret;
 
-	ebi2xclk = devm_clk_get(dev, "ebi2x");
-	if (IS_ERR(ebi2xclk))
+	ebi2xclk = devm_clk_get_enabled(dev, "ebi2x");
+	if (IS_ERR(ebi2xclk)) {
+		dev_err(dev, "could not enable EBI2X clk");
 		return PTR_ERR(ebi2xclk);
-
-	ret = clk_prepare_enable(ebi2xclk);
-	if (ret) {
-		dev_err(dev, "could not enable EBI2X clk (%d)\n", ret);
-		return ret;
 	}
 
-	ebi2clk = devm_clk_get(dev, "ebi2");
+	ebi2clk = devm_clk_get_enabled(dev, "ebi2");
 	if (IS_ERR(ebi2clk)) {
-		ret = PTR_ERR(ebi2clk);
-		goto err_disable_2x_clk;
-	}
-
-	ret = clk_prepare_enable(ebi2clk);
-	if (ret) {
-		dev_err(dev, "could not enable EBI2 clk\n");
-		goto err_disable_2x_clk;
+		dev_err(dev, "could not enable EBI2 clk");
+		return PTR_ERR(ebi2clk);
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	ebi2_base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(ebi2_base)) {
-		ret = PTR_ERR(ebi2_base);
-		goto err_disable_clk;
+		return PTR_ERR(ebi2_base);
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	ebi2_xmem = devm_ioremap_resource(dev, res);
 	if (IS_ERR(ebi2_xmem)) {
-		ret = PTR_ERR(ebi2_xmem);
-		goto err_disable_clk;
+		return PTR_ERR(ebi2_xmem);
 	}
 
 	/* Allegedly this turns the power save mode off */
@@ -378,13 +366,6 @@ static int qcom_ebi2_probe(struct platform_device *pdev)
 	if (have_children)
 		return of_platform_default_populate(np, NULL, dev);
 	return 0;
-
-err_disable_clk:
-	clk_disable_unprepare(ebi2clk);
-err_disable_2x_clk:
-	clk_disable_unprepare(ebi2xclk);
-
-	return ret;
 }
 
 static const struct of_device_id qcom_ebi2_of_match[] = {
-- 
2.25.1


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

* [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe()
  2023-04-30 12:51 [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Ziliang Liao
@ 2023-04-30 12:51 ` Ziliang Liao
  2023-05-08 13:35   ` Linus Walleij
  2023-05-08 13:34 ` [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Linus Walleij
  1 sibling, 1 reply; 6+ messages in thread
From: Ziliang Liao @ 2023-04-30 12:51 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Linus Walleij
  Cc: hust-os-kernel-patches, Ziliang Liao, Dongliang Mu,
	linux-arm-msm, linux-kernel

The code use platform_get_resource() and devm_ioremap_resource() to
allocate memory resources for the device. It can be simplified by using
devm_platform_ioremap_resource().

Fixes: 335a12754808 ("bus: qcom: add EBI2 driver")
Signed-off-by: Ziliang Liao <saraday@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
 drivers/bus/qcom-ebi2.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/bus/qcom-ebi2.c b/drivers/bus/qcom-ebi2.c
index 3999e969e1cf..bd419398d1c1 100644
--- a/drivers/bus/qcom-ebi2.c
+++ b/drivers/bus/qcom-ebi2.c
@@ -294,7 +294,6 @@ static int qcom_ebi2_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct device_node *child;
 	struct device *dev = &pdev->dev;
-	struct resource *res;
 	void __iomem *ebi2_base;
 	void __iomem *ebi2_xmem;
 	struct clk *ebi2xclk;
@@ -315,14 +314,12 @@ static int qcom_ebi2_probe(struct platform_device *pdev)
 		return PTR_ERR(ebi2clk);
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	ebi2_base = devm_ioremap_resource(dev, res);
+	ebi2_base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(ebi2_base)) {
 		return PTR_ERR(ebi2_base);
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	ebi2_xmem = devm_ioremap_resource(dev, res);
+	ebi2_xmem = devm_platform_ioremap_resource(pdev, 1);
 	if (IS_ERR(ebi2_xmem)) {
 		return PTR_ERR(ebi2_xmem);
 	}
-- 
2.25.1


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

* Re: [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions
  2023-04-30 12:51 [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Ziliang Liao
  2023-04-30 12:51 ` [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe() Ziliang Liao
@ 2023-05-08 13:34 ` Linus Walleij
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2023-05-08 13:34 UTC (permalink / raw)
  To: Ziliang Liao
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	hust-os-kernel-patches, Dongliang Mu, linux-arm-msm,
	linux-kernel

On Sun, Apr 30, 2023 at 2:53 PM Ziliang Liao <saraday@hust.edu.cn> wrote:

> Smatch reports:
>
> drivers/bus/qcom-ebi2.c:387 qcom_ebi2_probe() warn: 'ebi2clk' from
> clk_prepare_enable() not released on lines: 358.
>
> drivers/bus/qcom-ebi2.c:387 qcom_ebi2_probe() warn: 'ebi2xclk' from
> clk_prepare_enabled() not released on lines: 358.
>
> The clk_disable_unprepare() is only used to explicitly release resources
> when the qcom_ebi2_probe() fails, and when executed correctly, it may
> cause resource leakage due to unknown release time.
>
> Replace devm_clk_get() and clk_prepare_enable() with
> devm_clk_get_enabled() to automatically manage the allocated resources.
>
> Fixes: 335a12754808 ("bus: qcom: add EBI2 driver")
> Signed-off-by: Ziliang Liao <saraday@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>

Looks good:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

I think Bjorn can queue this in the Qualcomm ARM tree.

Yours,
Linus Walleij

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

* Re: [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe()
  2023-04-30 12:51 ` [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe() Ziliang Liao
@ 2023-05-08 13:35   ` Linus Walleij
  2023-05-08 16:22     ` Ziliang Liao
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2023-05-08 13:35 UTC (permalink / raw)
  To: Ziliang Liao
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	hust-os-kernel-patches, Dongliang Mu, linux-arm-msm,
	linux-kernel

On Sun, Apr 30, 2023 at 2:54 PM Ziliang Liao <saraday@hust.edu.cn> wrote:

> The code use platform_get_resource() and devm_ioremap_resource() to
> allocate memory resources for the device. It can be simplified by using
> devm_platform_ioremap_resource().
>
> Fixes: 335a12754808 ("bus: qcom: add EBI2 driver")

It doesn't need Fixes: if it's not a bug, but who cares. Maybe
the stable maintainers care.

> Signed-off-by: Ziliang Liao <saraday@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe()
  2023-05-08 13:35   ` Linus Walleij
@ 2023-05-08 16:22     ` Ziliang Liao
  2023-05-09  7:06       ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Ziliang Liao @ 2023-05-08 16:22 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	hust-os-kernel-patches, Dongliang Mu, linux-arm-msm,
	linux-kernel

Thanks for your advice.
Do I need to delete the Fixes in [PATCH 2/2] and resend another patch set?

> On Sun, Apr 30, 2023 at 2:54 PM Ziliang Liao <saraday@hust.edu.cn> wrote:
>
>> The code use platform_get_resource() and devm_ioremap_resource() to
>> allocate memory resources for the device. It can be simplified by using
>> devm_platform_ioremap_resource().
>>
>> Fixes: 335a12754808 ("bus: qcom: add EBI2 driver")
> It doesn't need Fixes: if it's not a bug, but who cares. Maybe
> the stable maintainers care.
>
>> Signed-off-by: Ziliang Liao <saraday@hust.edu.cn>
>> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>
> Yours,
> Linus Walleij

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

* Re: [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe()
  2023-05-08 16:22     ` Ziliang Liao
@ 2023-05-09  7:06       ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2023-05-09  7:06 UTC (permalink / raw)
  To: Ziliang Liao
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio,
	hust-os-kernel-patches, Dongliang Mu, linux-arm-msm,
	linux-kernel

On Mon, May 8, 2023 at 6:22 PM Ziliang Liao <saraday@hust.edu.cn> wrote:

> Thanks for your advice.
> Do I need to delete the Fixes in [PATCH 2/2] and resend another patch set?

No I think Bjorn can delete it while applying the patch.

Yours,
Linus Walleij

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

end of thread, other threads:[~2023-05-09  7:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-30 12:51 [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Ziliang Liao
2023-04-30 12:51 ` [PATCH 2/2] bus: qcom-ebi2: simplify the code in qcom_ebi2_probe() Ziliang Liao
2023-05-08 13:35   ` Linus Walleij
2023-05-08 16:22     ` Ziliang Liao
2023-05-09  7:06       ` Linus Walleij
2023-05-08 13:34 ` [PATCH 1/2] bus: qcom-ebi2: use prefix devm for clock resource allocation functions Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®