LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] Enable clock before calling clk_get_rate() on it.
@ 2018-04-19 13:02 Stefan Potyra
  2018-04-30 15:02 ` Evgeniy Polyakov
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Potyra @ 2018-04-19 13:02 UTC (permalink / raw)
  To: Evgeniy Polyakov, linux-kernel; +Cc: ldv-project, sil2review

According to the API, you may only call clk_get_rate() after actually
enabling it.

Found by Linux Driver Verification project (linuxtesting.org).

Fixes: a5fd9139f74c w1: add 1-wire master driver for i.MX27 / i.MX31
Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
---
 drivers/w1/masters/mxc_w1.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
index 74f2e6e6202a..a9599027d4ef 100644
--- a/drivers/w1/masters/mxc_w1.c
+++ b/drivers/w1/masters/mxc_w1.c
@@ -112,6 +112,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
+	err = clk_prepare_enable(mdev->clk);
+	if (err)
+		return err;
+
 	clkrate = clk_get_rate(mdev->clk);
 	if (clkrate < 10000000)
 		dev_warn(&pdev->dev,
@@ -128,10 +132,6 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->regs))
 		return PTR_ERR(mdev->regs);
 
-	err = clk_prepare_enable(mdev->clk);
-	if (err)
-		return err;
-
 	/* Software reset 1-Wire module */
 	writeb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);
 	writeb(0, mdev->regs + MXC_W1_RESET);
-- 
2.17.0

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

* Re: [PATCH] Enable clock before calling clk_get_rate() on it.
  2018-04-19 13:02 [PATCH] Enable clock before calling clk_get_rate() on it Stefan Potyra
@ 2018-04-30 15:02 ` Evgeniy Polyakov
  2018-05-02  8:34   ` Stefan Potyra
  0 siblings, 1 reply; 5+ messages in thread
From: Evgeniy Polyakov @ 2018-04-30 15:02 UTC (permalink / raw)
  To: Stefan Potyra, linux-kernel, Greg Kroah-Hartman; +Cc: ldv-project, sil2review

Hi Stefan

Nice catch, thank you!

19.04.2018, 16:02, "Stefan Potyra" <stefan.potyra@elektrobit.com>:
> According to the API, you may only call clk_get_rate() after actually
> enabling it.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Fixes: a5fd9139f74c w1: add 1-wire master driver for i.MX27 / i.MX31
> Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>

Acked-by: Evgeniy Polyakov <zbr@ioremap.net>

Greg, please pull it into your tree. Is this a stable material?

> ---
>  drivers/w1/masters/mxc_w1.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
> index 74f2e6e6202a..a9599027d4ef 100644
> --- a/drivers/w1/masters/mxc_w1.c
> +++ b/drivers/w1/masters/mxc_w1.c
> @@ -112,6 +112,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
>          if (IS_ERR(mdev->clk))
>                  return PTR_ERR(mdev->clk);
>
> + err = clk_prepare_enable(mdev->clk);
> + if (err)
> + return err;
> +
>          clkrate = clk_get_rate(mdev->clk);
>          if (clkrate < 10000000)
>                  dev_warn(&pdev->dev,
> @@ -128,10 +132,6 @@ static int mxc_w1_probe(struct platform_device *pdev)
>          if (IS_ERR(mdev->regs))
>                  return PTR_ERR(mdev->regs);
>
> - err = clk_prepare_enable(mdev->clk);
> - if (err)
> - return err;
> -
>          /* Software reset 1-Wire module */
>          writeb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);
>          writeb(0, mdev->regs + MXC_W1_RESET);
> --
> 2.17.0

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

* Re: [PATCH] Enable clock before calling clk_get_rate() on it.
  2018-04-30 15:02 ` Evgeniy Polyakov
@ 2018-05-02  8:34   ` Stefan Potyra
  2018-05-02  8:55     ` [PATCH v2] w1: mxc_w1: " Stefan Potyra
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Potyra @ 2018-05-02  8:34 UTC (permalink / raw)
  To: Evgeniy Polyakov
  Cc: linux-kernel, Greg Kroah-Hartman, ldv-project, sil2review

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

Hi Evgeniy,

On Mon, Apr 30, 2018 at 06:02:57PM +0300, Evgeniy Polyakov wrote:
> Hi Stefan
> 
> Nice catch, thank you!
> 
> 19.04.2018, 16:02, "Stefan Potyra" <stefan.potyra@elektrobit.com>:
> > According to the API, you may only call clk_get_rate() after actually
> > enabling it.
> >
> > Found by Linux Driver Verification project (linuxtesting.org).
> >
> > Fixes: a5fd9139f74c w1: add 1-wire master driver for i.MX27 / i.MX31
> > Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
> 
> Acked-by: Evgeniy Polyakov <zbr@ioremap.net>

Oops, just saw that now the clock is leaked in the error case of mdev->regs.
I'll respin the patch and fix that.

Cheers,
  Stefan.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH v2] w1: mxc_w1: Enable clock before calling clk_get_rate() on it
  2018-05-02  8:34   ` Stefan Potyra
@ 2018-05-02  8:55     ` Stefan Potyra
  2018-05-08 11:02       ` Evgeniy Polyakov
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Potyra @ 2018-05-02  8:55 UTC (permalink / raw)
  To: Evgeniy Polyakov
  Cc: linux-kernel, Greg Kroah-Hartman, ldv-project, sil2review

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

According to the API, you may only call clk_get_rate() after actually
enabling it.

Found by Linux Driver Verification project (linuxtesting.org).

Fixes: a5fd9139f74c ("w1: add 1-wire master driver for i.MX27 / i.MX31")
Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Cc: stable <stable@vger.kernel.org>
---
 drivers/w1/masters/mxc_w1.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
index 74f2e6e6202a..8851d441e5fd 100644
--- a/drivers/w1/masters/mxc_w1.c
+++ b/drivers/w1/masters/mxc_w1.c
@@ -112,6 +112,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
+	err = clk_prepare_enable(mdev->clk);
+	if (err)
+		return err;
+
 	clkrate = clk_get_rate(mdev->clk);
 	if (clkrate < 10000000)
 		dev_warn(&pdev->dev,
@@ -125,12 +129,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mdev->regs = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(mdev->regs))
-		return PTR_ERR(mdev->regs);
-
-	err = clk_prepare_enable(mdev->clk);
-	if (err)
-		return err;
+	if (IS_ERR(mdev->regs)) {
+		err = PTR_ERR(mdev->regs);
+		goto out_disable_clk;
+	}
 
 	/* Software reset 1-Wire module */
 	writeb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);
@@ -146,8 +148,12 @@ static int mxc_w1_probe(struct platform_device *pdev)
 
 	err = w1_add_master_device(&mdev->bus_master);
 	if (err)
-		clk_disable_unprepare(mdev->clk);
+		goto out_disable_clk;
 
+	return 0;
+
+out_disable_clk:
+	clk_disable_unprepare(mdev->clk);
 	return err;
 }
 
-- 
2.17.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] w1: mxc_w1: Enable clock before calling clk_get_rate() on it
  2018-05-02  8:55     ` [PATCH v2] w1: mxc_w1: " Stefan Potyra
@ 2018-05-08 11:02       ` Evgeniy Polyakov
  0 siblings, 0 replies; 5+ messages in thread
From: Evgeniy Polyakov @ 2018-05-08 11:02 UTC (permalink / raw)
  To: Stefan Potyra; +Cc: linux-kernel, Greg Kroah-Hartman, ldv-project, sil2review

Hi Stefan

02.05.2018, 11:55, "Stefan Potyra" <stefan.potyra@elektrobit.com>:
> According to the API, you may only call clk_get_rate() after actually
> enabling it.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Fixes: a5fd9139f74c ("w1: add 1-wire master driver for i.MX27 / i.MX31")
> Signed-off-by: Stefan Potyra <Stefan.Potyra@elektrobit.com>

Looks good to me, thank you!
Greg, please pull it into your tree, this also sounds like stable material, is it?

Acked-by: Evgeniy Polyakov <zbr@ioremap.net>

> ---
>  drivers/w1/masters/mxc_w1.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
> index 74f2e6e6202a..8851d441e5fd 100644
> --- a/drivers/w1/masters/mxc_w1.c
> +++ b/drivers/w1/masters/mxc_w1.c
> @@ -112,6 +112,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
>          if (IS_ERR(mdev->clk))
>                  return PTR_ERR(mdev->clk);
>
> + err = clk_prepare_enable(mdev->clk);
> + if (err)
> + return err;
> +
>          clkrate = clk_get_rate(mdev->clk);
>          if (clkrate < 10000000)
>                  dev_warn(&pdev->dev,
> @@ -125,12 +129,10 @@ static int mxc_w1_probe(struct platform_device *pdev)
>
>          res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>          mdev->regs = devm_ioremap_resource(&pdev->dev, res);
> - if (IS_ERR(mdev->regs))
> - return PTR_ERR(mdev->regs);
> -
> - err = clk_prepare_enable(mdev->clk);
> - if (err)
> - return err;
> + if (IS_ERR(mdev->regs)) {
> + err = PTR_ERR(mdev->regs);
> + goto out_disable_clk;
> + }
>
>          /* Software reset 1-Wire module */
>          writeb(MXC_W1_RESET_RST, mdev->regs + MXC_W1_RESET);
> @@ -146,8 +148,12 @@ static int mxc_w1_probe(struct platform_device *pdev)
>
>          err = w1_add_master_device(&mdev->bus_master);
>          if (err)
> - clk_disable_unprepare(mdev->clk);
> + goto out_disable_clk;
>
> + return 0;
> +
> +out_disable_clk:
> + clk_disable_unprepare(mdev->clk);
>          return err;
>  }
>
> --
> 2.17.0

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

end of thread, other threads:[~2018-05-08 11:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19 13:02 [PATCH] Enable clock before calling clk_get_rate() on it Stefan Potyra
2018-04-30 15:02 ` Evgeniy Polyakov
2018-05-02  8:34   ` Stefan Potyra
2018-05-02  8:55     ` [PATCH v2] w1: mxc_w1: " Stefan Potyra
2018-05-08 11:02       ` Evgeniy Polyakov

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).