* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-12 21:34 ` Simon Baatz
0 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-12 21:34 UTC (permalink / raw)
To: linux-mtd
Cc: linux-arm-kernel, boris.brezillon, richard, jason, andrew, dan.carpenter
The clk handling in orion_nand.c had two problems:
- In the probe function, clk_put() was called for an enabled clock,
which violates the API (see documentation for clk_put() in
include/linux/clk.h)
- In the error path of the probe function, clk_put() could be called
twice for the same clock.
In order to clean this up, use the managed function devm_clk_get() and
store the pointer to the clk in the driver data.
Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
Cc: <stable@vger.kernel.org> # v4.5+
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 4a91c5d000be..b355aa738fae 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -23,6 +23,11 @@
#include <asm/sizes.h>
#include <linux/platform_data/mtd-orion_nand.h>
+struct orion_nand_info {
+ struct nand_chip chip;
+ struct clk *clk;
+};
+
static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
{
struct nand_chip *nc = mtd_to_nand(mtd);
@@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
static int __init orion_nand_probe(struct platform_device *pdev)
{
+ struct orion_nand_info *info;
struct mtd_info *mtd;
struct nand_chip *nc;
struct orion_nand_data *board;
struct resource *res;
- struct clk *clk;
void __iomem *io_base;
int ret = 0;
u32 val = 0;
- nc = devm_kzalloc(&pdev->dev,
- sizeof(struct nand_chip),
+ info = devm_kzalloc(&pdev->dev,
+ sizeof(struct orion_nand_info),
GFP_KERNEL);
- if (!nc)
+ if (!info)
return -ENOMEM;
+ nc = &info->chip;
mtd = nand_to_mtd(nc);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
if (board->dev_ready)
nc->dev_ready = board->dev_ready;
- platform_set_drvdata(pdev, mtd);
+ platform_set_drvdata(pdev, info);
/* Not all platforms can gate the clock, so it is not
an error if the clock does not exists. */
- clk = clk_get(&pdev->dev, NULL);
- if (!IS_ERR(clk)) {
- clk_prepare_enable(clk);
- clk_put(clk);
- }
+ info->clk = devm_clk_get(&pdev->dev, NULL);
+ if (!IS_ERR(info->clk))
+ clk_prepare_enable(info->clk);
ret = nand_scan(mtd, 1);
if (ret)
@@ -169,26 +173,22 @@ static int __init orion_nand_probe(struct platform_device *pdev)
return 0;
no_dev:
- if (!IS_ERR(clk)) {
- clk_disable_unprepare(clk);
- clk_put(clk);
- }
+ if (!IS_ERR(info->clk))
+ clk_disable_unprepare(info->clk);
return ret;
}
static int orion_nand_remove(struct platform_device *pdev)
{
- struct mtd_info *mtd = platform_get_drvdata(pdev);
- struct clk *clk;
+ struct orion_nand_info *info = platform_get_drvdata(pdev);
+ struct nand_chip *chip = &info->chip;
+ struct mtd_info *mtd = nand_to_mtd(chip);
nand_release(mtd);
- clk = clk_get(&pdev->dev, NULL);
- if (!IS_ERR(clk)) {
- clk_disable_unprepare(clk);
- clk_put(clk);
- }
+ if (!IS_ERR(info->clk))
+ clk_disable_unprepare(info->clk);
return 0;
}
--
2.9.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-12 21:34 ` Simon Baatz
0 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-12 21:34 UTC (permalink / raw)
To: linux-arm-kernel
The clk handling in orion_nand.c had two problems:
- In the probe function, clk_put() was called for an enabled clock,
which violates the API (see documentation for clk_put() in
include/linux/clk.h)
- In the error path of the probe function, clk_put() could be called
twice for the same clock.
In order to clean this up, use the managed function devm_clk_get() and
store the pointer to the clk in the driver data.
Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
Cc: <stable@vger.kernel.org> # v4.5+
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 4a91c5d000be..b355aa738fae 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -23,6 +23,11 @@
#include <asm/sizes.h>
#include <linux/platform_data/mtd-orion_nand.h>
+struct orion_nand_info {
+ struct nand_chip chip;
+ struct clk *clk;
+};
+
static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
{
struct nand_chip *nc = mtd_to_nand(mtd);
@@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
static int __init orion_nand_probe(struct platform_device *pdev)
{
+ struct orion_nand_info *info;
struct mtd_info *mtd;
struct nand_chip *nc;
struct orion_nand_data *board;
struct resource *res;
- struct clk *clk;
void __iomem *io_base;
int ret = 0;
u32 val = 0;
- nc = devm_kzalloc(&pdev->dev,
- sizeof(struct nand_chip),
+ info = devm_kzalloc(&pdev->dev,
+ sizeof(struct orion_nand_info),
GFP_KERNEL);
- if (!nc)
+ if (!info)
return -ENOMEM;
+ nc = &info->chip;
mtd = nand_to_mtd(nc);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
if (board->dev_ready)
nc->dev_ready = board->dev_ready;
- platform_set_drvdata(pdev, mtd);
+ platform_set_drvdata(pdev, info);
/* Not all platforms can gate the clock, so it is not
an error if the clock does not exists. */
- clk = clk_get(&pdev->dev, NULL);
- if (!IS_ERR(clk)) {
- clk_prepare_enable(clk);
- clk_put(clk);
- }
+ info->clk = devm_clk_get(&pdev->dev, NULL);
+ if (!IS_ERR(info->clk))
+ clk_prepare_enable(info->clk);
ret = nand_scan(mtd, 1);
if (ret)
@@ -169,26 +173,22 @@ static int __init orion_nand_probe(struct platform_device *pdev)
return 0;
no_dev:
- if (!IS_ERR(clk)) {
- clk_disable_unprepare(clk);
- clk_put(clk);
- }
+ if (!IS_ERR(info->clk))
+ clk_disable_unprepare(info->clk);
return ret;
}
static int orion_nand_remove(struct platform_device *pdev)
{
- struct mtd_info *mtd = platform_get_drvdata(pdev);
- struct clk *clk;
+ struct orion_nand_info *info = platform_get_drvdata(pdev);
+ struct nand_chip *chip = &info->chip;
+ struct mtd_info *mtd = nand_to_mtd(chip);
nand_release(mtd);
- clk = clk_get(&pdev->dev, NULL);
- if (!IS_ERR(clk)) {
- clk_disable_unprepare(clk);
- clk_put(clk);
- }
+ if (!IS_ERR(info->clk))
+ clk_disable_unprepare(info->clk);
return 0;
}
--
2.9.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-12 21:34 ` Simon Baatz
@ 2017-03-13 7:12 ` Uwe Kleine-König
-1 siblings, 0 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2017-03-13 7:12 UTC (permalink / raw)
To: Simon Baatz
Cc: linux-mtd, boris.brezillon, jason, andrew, richard,
linux-arm-kernel, dan.carpenter
Hello Simon,
On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> The clk handling in orion_nand.c had two problems:
>
> - In the probe function, clk_put() was called for an enabled clock,
> which violates the API (see documentation for clk_put() in
> include/linux/clk.h)
>
> - In the error path of the probe function, clk_put() could be called
> twice for the same clock.
>
> In order to clean this up, use the managed function devm_clk_get() and
> store the pointer to the clk in the driver data.
>
> Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> Cc: <stable@vger.kernel.org> # v4.5+
> Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> ---
> drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> 1 file changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> index 4a91c5d000be..b355aa738fae 100644
> --- a/drivers/mtd/nand/orion_nand.c
> +++ b/drivers/mtd/nand/orion_nand.c
> @@ -23,6 +23,11 @@
> #include <asm/sizes.h>
> #include <linux/platform_data/mtd-orion_nand.h>
>
> +struct orion_nand_info {
> + struct nand_chip chip;
> + struct clk *clk;
> +};
> +
> static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> {
> struct nand_chip *nc = mtd_to_nand(mtd);
> @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
>
> static int __init orion_nand_probe(struct platform_device *pdev)
> {
> + struct orion_nand_info *info;
> struct mtd_info *mtd;
> struct nand_chip *nc;
> struct orion_nand_data *board;
> struct resource *res;
> - struct clk *clk;
> void __iomem *io_base;
> int ret = 0;
> u32 val = 0;
>
> - nc = devm_kzalloc(&pdev->dev,
> - sizeof(struct nand_chip),
> + info = devm_kzalloc(&pdev->dev,
> + sizeof(struct orion_nand_info),
> GFP_KERNEL);
> - if (!nc)
> + if (!info)
> return -ENOMEM;
> + nc = &info->chip;
> mtd = nand_to_mtd(nc);
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> if (board->dev_ready)
> nc->dev_ready = board->dev_ready;
>
> - platform_set_drvdata(pdev, mtd);
> + platform_set_drvdata(pdev, info);
>
> /* Not all platforms can gate the clock, so it is not
> an error if the clock does not exists. */
> - clk = clk_get(&pdev->dev, NULL);
> - if (!IS_ERR(clk)) {
> - clk_prepare_enable(clk);
> - clk_put(clk);
> - }
> + info->clk = devm_clk_get(&pdev->dev, NULL);
> + if (!IS_ERR(info->clk))
> + clk_prepare_enable(info->clk);
Orthogonal to your patch I suggest:
- info->clk = devm_clk_get(&pdev->dev, NULL);
- if (!IS_ERR(info->clk))
- clk_prepare_enable(info->clk);
+ info->clk = devm_clk_get_optional(&pdev->dev, NULL);
+ if (IS_ERR(info->clk)) {
+ ret = PTR_ERR(info->clk);
+ if (ret != -EPROBE_DEFER)
+ dev_err(...);
+ return ret;
+ }
to correct error handling.
(I didn't check if a plain return is right here, and also other users of
info->clk need adaption.)
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-13 7:12 ` Uwe Kleine-König
0 siblings, 0 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2017-03-13 7:12 UTC (permalink / raw)
To: linux-arm-kernel
Hello Simon,
On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> The clk handling in orion_nand.c had two problems:
>
> - In the probe function, clk_put() was called for an enabled clock,
> which violates the API (see documentation for clk_put() in
> include/linux/clk.h)
>
> - In the error path of the probe function, clk_put() could be called
> twice for the same clock.
>
> In order to clean this up, use the managed function devm_clk_get() and
> store the pointer to the clk in the driver data.
>
> Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> Cc: <stable@vger.kernel.org> # v4.5+
> Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> ---
> drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> 1 file changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> index 4a91c5d000be..b355aa738fae 100644
> --- a/drivers/mtd/nand/orion_nand.c
> +++ b/drivers/mtd/nand/orion_nand.c
> @@ -23,6 +23,11 @@
> #include <asm/sizes.h>
> #include <linux/platform_data/mtd-orion_nand.h>
>
> +struct orion_nand_info {
> + struct nand_chip chip;
> + struct clk *clk;
> +};
> +
> static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> {
> struct nand_chip *nc = mtd_to_nand(mtd);
> @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
>
> static int __init orion_nand_probe(struct platform_device *pdev)
> {
> + struct orion_nand_info *info;
> struct mtd_info *mtd;
> struct nand_chip *nc;
> struct orion_nand_data *board;
> struct resource *res;
> - struct clk *clk;
> void __iomem *io_base;
> int ret = 0;
> u32 val = 0;
>
> - nc = devm_kzalloc(&pdev->dev,
> - sizeof(struct nand_chip),
> + info = devm_kzalloc(&pdev->dev,
> + sizeof(struct orion_nand_info),
> GFP_KERNEL);
> - if (!nc)
> + if (!info)
> return -ENOMEM;
> + nc = &info->chip;
> mtd = nand_to_mtd(nc);
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> if (board->dev_ready)
> nc->dev_ready = board->dev_ready;
>
> - platform_set_drvdata(pdev, mtd);
> + platform_set_drvdata(pdev, info);
>
> /* Not all platforms can gate the clock, so it is not
> an error if the clock does not exists. */
> - clk = clk_get(&pdev->dev, NULL);
> - if (!IS_ERR(clk)) {
> - clk_prepare_enable(clk);
> - clk_put(clk);
> - }
> + info->clk = devm_clk_get(&pdev->dev, NULL);
> + if (!IS_ERR(info->clk))
> + clk_prepare_enable(info->clk);
Orthogonal to your patch I suggest:
- info->clk = devm_clk_get(&pdev->dev, NULL);
- if (!IS_ERR(info->clk))
- clk_prepare_enable(info->clk);
+ info->clk = devm_clk_get_optional(&pdev->dev, NULL);
+ if (IS_ERR(info->clk)) {
+ ret = PTR_ERR(info->clk);
+ if (ret != -EPROBE_DEFER)
+ dev_err(...);
+ return ret;
+ }
to correct error handling.
(I didn't check if a plain return is right here, and also other users of
info->clk need adaption.)
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-13 7:12 ` Uwe Kleine-König
@ 2017-03-13 20:43 ` Simon Baatz
-1 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-13 20:43 UTC (permalink / raw)
To: Uwe Kleine-K?nig
Cc: linux-mtd, boris.brezillon, jason, andrew, richard,
linux-arm-kernel, dan.carpenter
Hello Uwe,
On Mon, Mar 13, 2017 at 08:12:41AM +0100, Uwe Kleine-K?nig wrote:
> Hello Simon,
>
> On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > The clk handling in orion_nand.c had two problems:
> >
> > - In the probe function, clk_put() was called for an enabled clock,
> > which violates the API (see documentation for clk_put() in
> > include/linux/clk.h)
> >
> > - In the error path of the probe function, clk_put() could be called
> > twice for the same clock.
> >
> > In order to clean this up, use the managed function devm_clk_get() and
> > store the pointer to the clk in the driver data.
...
> > /* Not all platforms can gate the clock, so it is not
> > an error if the clock does not exists. */
> > - clk = clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(clk)) {
> > - clk_prepare_enable(clk);
> > - clk_put(clk);
> > - }
> > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > + if (!IS_ERR(info->clk))
> > + clk_prepare_enable(info->clk);
>
> Orthogonal to your patch I suggest:
>
> - info->clk = devm_clk_get(&pdev->dev, NULL);
> - if (!IS_ERR(info->clk))
> - clk_prepare_enable(info->clk);
> + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> + if (IS_ERR(info->clk)) {
> + ret = PTR_ERR(info->clk);
> + if (ret != -EPROBE_DEFER)
> + dev_err(...);
> + return ret;
> + }
>
> to correct error handling.
> (I didn't check if a plain return is right here, and also other users of
> info->clk need adaption.)
Nice! However, I can't find a devm_clk_get_optional() anywhere(?) Is
it in some upcoming patch?
- Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-13 20:43 ` Simon Baatz
0 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-13 20:43 UTC (permalink / raw)
To: linux-arm-kernel
Hello Uwe,
On Mon, Mar 13, 2017 at 08:12:41AM +0100, Uwe Kleine-K?nig wrote:
> Hello Simon,
>
> On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > The clk handling in orion_nand.c had two problems:
> >
> > - In the probe function, clk_put() was called for an enabled clock,
> > which violates the API (see documentation for clk_put() in
> > include/linux/clk.h)
> >
> > - In the error path of the probe function, clk_put() could be called
> > twice for the same clock.
> >
> > In order to clean this up, use the managed function devm_clk_get() and
> > store the pointer to the clk in the driver data.
...
> > /* Not all platforms can gate the clock, so it is not
> > an error if the clock does not exists. */
> > - clk = clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(clk)) {
> > - clk_prepare_enable(clk);
> > - clk_put(clk);
> > - }
> > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > + if (!IS_ERR(info->clk))
> > + clk_prepare_enable(info->clk);
>
> Orthogonal to your patch I suggest:
>
> - info->clk = devm_clk_get(&pdev->dev, NULL);
> - if (!IS_ERR(info->clk))
> - clk_prepare_enable(info->clk);
> + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> + if (IS_ERR(info->clk)) {
> + ret = PTR_ERR(info->clk);
> + if (ret != -EPROBE_DEFER)
> + dev_err(...);
> + return ret;
> + }
>
> to correct error handling.
> (I didn't check if a plain return is right here, and also other users of
> info->clk need adaption.)
Nice! However, I can't find a devm_clk_get_optional() anywhere(?) Is
it in some upcoming patch?
- Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-13 20:43 ` Simon Baatz
@ 2017-03-13 20:58 ` Uwe Kleine-König
-1 siblings, 0 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2017-03-13 20:58 UTC (permalink / raw)
To: Simon Baatz
Cc: linux-mtd, boris.brezillon, jason, andrew, richard,
linux-arm-kernel, dan.carpenter
Hello Simon,
On Mon, Mar 13, 2017 at 09:43:44PM +0100, Simon Baatz wrote:
> Hello Uwe,
>
> On Mon, Mar 13, 2017 at 08:12:41AM +0100, Uwe Kleine-K?nig wrote:
> > Hello Simon,
> >
> > On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > > The clk handling in orion_nand.c had two problems:
> > >
> > > - In the probe function, clk_put() was called for an enabled clock,
> > > which violates the API (see documentation for clk_put() in
> > > include/linux/clk.h)
> > >
> > > - In the error path of the probe function, clk_put() could be called
> > > twice for the same clock.
> > >
> > > In order to clean this up, use the managed function devm_clk_get() and
> > > store the pointer to the clk in the driver data.
>
> ...
>
> > > /* Not all platforms can gate the clock, so it is not
> > > an error if the clock does not exists. */
> > > - clk = clk_get(&pdev->dev, NULL);
> > > - if (!IS_ERR(clk)) {
> > > - clk_prepare_enable(clk);
> > > - clk_put(clk);
> > > - }
> > > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > > + if (!IS_ERR(info->clk))
> > > + clk_prepare_enable(info->clk);
> >
> > Orthogonal to your patch I suggest:
> >
> > - info->clk = devm_clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(info->clk))
> > - clk_prepare_enable(info->clk);
> > + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > + if (IS_ERR(info->clk)) {
> > + ret = PTR_ERR(info->clk);
> > + if (ret != -EPROBE_DEFER)
> > + dev_err(...);
> > + return ret;
> > + }
> >
> > to correct error handling.
> > (I didn't check if a plain return is right here, and also other users of
> > info->clk need adaption.)
>
> Nice! However, I can't find a devm_clk_get_optional() anywhere(?) Is
> it in some upcoming patch?
Oh really. I was sure I already made use of it. Probably consfused it
with the gpio or regulator API which have such variants. (But be aware,
they are sematically different. If you look for a place to copy from
please stick to the gpio sematic.)
Then either send a patch creating clk_get_optional and friends, or only
ignore -ENODEV but propagate the other error values. (Maybe the most
rational path is to do both and switch the driver once clk_get_optional
is available.)
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-13 20:58 ` Uwe Kleine-König
0 siblings, 0 replies; 18+ messages in thread
From: Uwe Kleine-König @ 2017-03-13 20:58 UTC (permalink / raw)
To: linux-arm-kernel
Hello Simon,
On Mon, Mar 13, 2017 at 09:43:44PM +0100, Simon Baatz wrote:
> Hello Uwe,
>
> On Mon, Mar 13, 2017 at 08:12:41AM +0100, Uwe Kleine-K?nig wrote:
> > Hello Simon,
> >
> > On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > > The clk handling in orion_nand.c had two problems:
> > >
> > > - In the probe function, clk_put() was called for an enabled clock,
> > > which violates the API (see documentation for clk_put() in
> > > include/linux/clk.h)
> > >
> > > - In the error path of the probe function, clk_put() could be called
> > > twice for the same clock.
> > >
> > > In order to clean this up, use the managed function devm_clk_get() and
> > > store the pointer to the clk in the driver data.
>
> ...
>
> > > /* Not all platforms can gate the clock, so it is not
> > > an error if the clock does not exists. */
> > > - clk = clk_get(&pdev->dev, NULL);
> > > - if (!IS_ERR(clk)) {
> > > - clk_prepare_enable(clk);
> > > - clk_put(clk);
> > > - }
> > > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > > + if (!IS_ERR(info->clk))
> > > + clk_prepare_enable(info->clk);
> >
> > Orthogonal to your patch I suggest:
> >
> > - info->clk = devm_clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(info->clk))
> > - clk_prepare_enable(info->clk);
> > + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > + if (IS_ERR(info->clk)) {
> > + ret = PTR_ERR(info->clk);
> > + if (ret != -EPROBE_DEFER)
> > + dev_err(...);
> > + return ret;
> > + }
> >
> > to correct error handling.
> > (I didn't check if a plain return is right here, and also other users of
> > info->clk need adaption.)
>
> Nice! However, I can't find a devm_clk_get_optional() anywhere(?) Is
> it in some upcoming patch?
Oh really. I was sure I already made use of it. Probably consfused it
with the gpio or regulator API which have such variants. (But be aware,
they are sematically different. If you look for a place to copy from
please stick to the gpio sematic.)
Then either send a patch creating clk_get_optional and friends, or only
ignore -ENODEV but propagate the other error values. (Maybe the most
rational path is to do both and switch the driver once clk_get_optional
is available.)
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-12 21:34 ` Simon Baatz
@ 2017-03-16 9:05 ` Boris Brezillon
-1 siblings, 0 replies; 18+ messages in thread
From: Boris Brezillon @ 2017-03-16 9:05 UTC (permalink / raw)
To: Simon Baatz
Cc: linux-mtd, linux-arm-kernel, richard, jason, andrew, dan.carpenter
Hi Simon,
On Sun, 12 Mar 2017 22:34:06 +0100
Simon Baatz <gmbnomis@gmail.com> wrote:
> The clk handling in orion_nand.c had two problems:
>
> - In the probe function, clk_put() was called for an enabled clock,
> which violates the API (see documentation for clk_put() in
> include/linux/clk.h)
>
> - In the error path of the probe function, clk_put() could be called
> twice for the same clock.
>
> In order to clean this up, use the managed function devm_clk_get() and
> store the pointer to the clk in the driver data.
>
> Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> Cc: <stable@vger.kernel.org> # v4.5+
> Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> ---
> drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> 1 file changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> index 4a91c5d000be..b355aa738fae 100644
> --- a/drivers/mtd/nand/orion_nand.c
> +++ b/drivers/mtd/nand/orion_nand.c
> @@ -23,6 +23,11 @@
> #include <asm/sizes.h>
> #include <linux/platform_data/mtd-orion_nand.h>
>
> +struct orion_nand_info {
> + struct nand_chip chip;
> + struct clk *clk;
Can we avoid this kind of alignment, which will not be preserved if
someone adds a new field with a type that is longer than "struct
nand_chip "?
Regards,
Boris
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-16 9:05 ` Boris Brezillon
0 siblings, 0 replies; 18+ messages in thread
From: Boris Brezillon @ 2017-03-16 9:05 UTC (permalink / raw)
To: linux-arm-kernel
Hi Simon,
On Sun, 12 Mar 2017 22:34:06 +0100
Simon Baatz <gmbnomis@gmail.com> wrote:
> The clk handling in orion_nand.c had two problems:
>
> - In the probe function, clk_put() was called for an enabled clock,
> which violates the API (see documentation for clk_put() in
> include/linux/clk.h)
>
> - In the error path of the probe function, clk_put() could be called
> twice for the same clock.
>
> In order to clean this up, use the managed function devm_clk_get() and
> store the pointer to the clk in the driver data.
>
> Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> Cc: <stable@vger.kernel.org> # v4.5+
> Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> ---
> drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> 1 file changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> index 4a91c5d000be..b355aa738fae 100644
> --- a/drivers/mtd/nand/orion_nand.c
> +++ b/drivers/mtd/nand/orion_nand.c
> @@ -23,6 +23,11 @@
> #include <asm/sizes.h>
> #include <linux/platform_data/mtd-orion_nand.h>
>
> +struct orion_nand_info {
> + struct nand_chip chip;
> + struct clk *clk;
Can we avoid this kind of alignment, which will not be preserved if
someone adds a new field with a type that is longer than "struct
nand_chip "?
Regards,
Boris
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-13 7:12 ` Uwe Kleine-König
@ 2017-03-16 9:12 ` Boris Brezillon
-1 siblings, 0 replies; 18+ messages in thread
From: Boris Brezillon @ 2017-03-16 9:12 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Simon Baatz, linux-mtd, jason, andrew, richard, linux-arm-kernel,
dan.carpenter
On Mon, 13 Mar 2017 08:12:41 +0100
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> Hello Simon,
>
> On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > The clk handling in orion_nand.c had two problems:
> >
> > - In the probe function, clk_put() was called for an enabled clock,
> > which violates the API (see documentation for clk_put() in
> > include/linux/clk.h)
> >
> > - In the error path of the probe function, clk_put() could be called
> > twice for the same clock.
> >
> > In order to clean this up, use the managed function devm_clk_get() and
> > store the pointer to the clk in the driver data.
> >
> > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > Cc: <stable@vger.kernel.org> # v4.5+
> > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > ---
> > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > 1 file changed, 21 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > index 4a91c5d000be..b355aa738fae 100644
> > --- a/drivers/mtd/nand/orion_nand.c
> > +++ b/drivers/mtd/nand/orion_nand.c
> > @@ -23,6 +23,11 @@
> > #include <asm/sizes.h>
> > #include <linux/platform_data/mtd-orion_nand.h>
> >
> > +struct orion_nand_info {
> > + struct nand_chip chip;
> > + struct clk *clk;
> > +};
> > +
> > static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> > {
> > struct nand_chip *nc = mtd_to_nand(mtd);
> > @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
> >
> > static int __init orion_nand_probe(struct platform_device *pdev)
> > {
> > + struct orion_nand_info *info;
> > struct mtd_info *mtd;
> > struct nand_chip *nc;
> > struct orion_nand_data *board;
> > struct resource *res;
> > - struct clk *clk;
> > void __iomem *io_base;
> > int ret = 0;
> > u32 val = 0;
> >
> > - nc = devm_kzalloc(&pdev->dev,
> > - sizeof(struct nand_chip),
> > + info = devm_kzalloc(&pdev->dev,
> > + sizeof(struct orion_nand_info),
> > GFP_KERNEL);
> > - if (!nc)
> > + if (!info)
> > return -ENOMEM;
> > + nc = &info->chip;
> > mtd = nand_to_mtd(nc);
> >
> > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> > if (board->dev_ready)
> > nc->dev_ready = board->dev_ready;
> >
> > - platform_set_drvdata(pdev, mtd);
> > + platform_set_drvdata(pdev, info);
> >
> > /* Not all platforms can gate the clock, so it is not
> > an error if the clock does not exists. */
> > - clk = clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(clk)) {
> > - clk_prepare_enable(clk);
> > - clk_put(clk);
> > - }
> > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > + if (!IS_ERR(info->clk))
> > + clk_prepare_enable(info->clk);
>
> Orthogonal to your patch I suggest:
>
> - info->clk = devm_clk_get(&pdev->dev, NULL);
> - if (!IS_ERR(info->clk))
> - clk_prepare_enable(info->clk);
> + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> + if (IS_ERR(info->clk)) {
> + ret = PTR_ERR(info->clk);
> + if (ret != -EPROBE_DEFER)
> + dev_err(...);
> + return ret;
> + }
>
In the meantime, maybe you can do:
info->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) {
ret = PTR_ERR(info->clk);
if (ret == -ENOENT) {
/*
* This clk is optional, assign it to NULL when
* it's not present.
*/
info->clk = NULL;
} else {
if (ret == -EPROBE_DEFER)
dev_err(...);
return ret;
}
}
This way, you won't have to check the info->clk value when you call
clk_prepare_enable() or clk_disable_unprepare().
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-16 9:12 ` Boris Brezillon
0 siblings, 0 replies; 18+ messages in thread
From: Boris Brezillon @ 2017-03-16 9:12 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, 13 Mar 2017 08:12:41 +0100
Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de> wrote:
> Hello Simon,
>
> On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > The clk handling in orion_nand.c had two problems:
> >
> > - In the probe function, clk_put() was called for an enabled clock,
> > which violates the API (see documentation for clk_put() in
> > include/linux/clk.h)
> >
> > - In the error path of the probe function, clk_put() could be called
> > twice for the same clock.
> >
> > In order to clean this up, use the managed function devm_clk_get() and
> > store the pointer to the clk in the driver data.
> >
> > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > Cc: <stable@vger.kernel.org> # v4.5+
> > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > ---
> > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > 1 file changed, 21 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > index 4a91c5d000be..b355aa738fae 100644
> > --- a/drivers/mtd/nand/orion_nand.c
> > +++ b/drivers/mtd/nand/orion_nand.c
> > @@ -23,6 +23,11 @@
> > #include <asm/sizes.h>
> > #include <linux/platform_data/mtd-orion_nand.h>
> >
> > +struct orion_nand_info {
> > + struct nand_chip chip;
> > + struct clk *clk;
> > +};
> > +
> > static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> > {
> > struct nand_chip *nc = mtd_to_nand(mtd);
> > @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
> >
> > static int __init orion_nand_probe(struct platform_device *pdev)
> > {
> > + struct orion_nand_info *info;
> > struct mtd_info *mtd;
> > struct nand_chip *nc;
> > struct orion_nand_data *board;
> > struct resource *res;
> > - struct clk *clk;
> > void __iomem *io_base;
> > int ret = 0;
> > u32 val = 0;
> >
> > - nc = devm_kzalloc(&pdev->dev,
> > - sizeof(struct nand_chip),
> > + info = devm_kzalloc(&pdev->dev,
> > + sizeof(struct orion_nand_info),
> > GFP_KERNEL);
> > - if (!nc)
> > + if (!info)
> > return -ENOMEM;
> > + nc = &info->chip;
> > mtd = nand_to_mtd(nc);
> >
> > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> > if (board->dev_ready)
> > nc->dev_ready = board->dev_ready;
> >
> > - platform_set_drvdata(pdev, mtd);
> > + platform_set_drvdata(pdev, info);
> >
> > /* Not all platforms can gate the clock, so it is not
> > an error if the clock does not exists. */
> > - clk = clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(clk)) {
> > - clk_prepare_enable(clk);
> > - clk_put(clk);
> > - }
> > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > + if (!IS_ERR(info->clk))
> > + clk_prepare_enable(info->clk);
>
> Orthogonal to your patch I suggest:
>
> - info->clk = devm_clk_get(&pdev->dev, NULL);
> - if (!IS_ERR(info->clk))
> - clk_prepare_enable(info->clk);
> + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> + if (IS_ERR(info->clk)) {
> + ret = PTR_ERR(info->clk);
> + if (ret != -EPROBE_DEFER)
> + dev_err(...);
> + return ret;
> + }
>
In the meantime, maybe you can do:
info->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) {
ret = PTR_ERR(info->clk);
if (ret == -ENOENT) {
/*
* This clk is optional, assign it to NULL when
* it's not present.
*/
info->clk = NULL;
} else {
if (ret == -EPROBE_DEFER)
dev_err(...);
return ret;
}
}
This way, you won't have to check the info->clk value when you call
clk_prepare_enable() or clk_disable_unprepare().
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-16 9:05 ` Boris Brezillon
@ 2017-03-16 21:44 ` Simon Baatz
-1 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-16 21:44 UTC (permalink / raw)
To: Boris Brezillon
Cc: linux-mtd, linux-arm-kernel, richard, jason, andrew, dan.carpenter
Hello Boris,
On Thu, Mar 16, 2017 at 10:05:39AM +0100, Boris Brezillon wrote:
> Hi Simon,
>
> On Sun, 12 Mar 2017 22:34:06 +0100
> Simon Baatz <gmbnomis@gmail.com> wrote:
>
> > The clk handling in orion_nand.c had two problems:
> >
> > - In the probe function, clk_put() was called for an enabled clock,
> > which violates the API (see documentation for clk_put() in
> > include/linux/clk.h)
> >
> > - In the error path of the probe function, clk_put() could be called
> > twice for the same clock.
> >
> > In order to clean this up, use the managed function devm_clk_get() and
> > store the pointer to the clk in the driver data.
> >
> > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > Cc: <stable@vger.kernel.org> # v4.5+
> > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > ---
> > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > 1 file changed, 21 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > index 4a91c5d000be..b355aa738fae 100644
> > --- a/drivers/mtd/nand/orion_nand.c
> > +++ b/drivers/mtd/nand/orion_nand.c
> > @@ -23,6 +23,11 @@
> > #include <asm/sizes.h>
> > #include <linux/platform_data/mtd-orion_nand.h>
> >
> > +struct orion_nand_info {
> > + struct nand_chip chip;
> > + struct clk *clk;
>
> Can we avoid this kind of alignment, which will not be preserved if
> someone adds a new field with a type that is longer than "struct
> nand_chip "?
>
Sure. I will change that in v2.
- Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-16 21:44 ` Simon Baatz
0 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-16 21:44 UTC (permalink / raw)
To: linux-arm-kernel
Hello Boris,
On Thu, Mar 16, 2017 at 10:05:39AM +0100, Boris Brezillon wrote:
> Hi Simon,
>
> On Sun, 12 Mar 2017 22:34:06 +0100
> Simon Baatz <gmbnomis@gmail.com> wrote:
>
> > The clk handling in orion_nand.c had two problems:
> >
> > - In the probe function, clk_put() was called for an enabled clock,
> > which violates the API (see documentation for clk_put() in
> > include/linux/clk.h)
> >
> > - In the error path of the probe function, clk_put() could be called
> > twice for the same clock.
> >
> > In order to clean this up, use the managed function devm_clk_get() and
> > store the pointer to the clk in the driver data.
> >
> > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > Cc: <stable@vger.kernel.org> # v4.5+
> > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > ---
> > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > 1 file changed, 21 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > index 4a91c5d000be..b355aa738fae 100644
> > --- a/drivers/mtd/nand/orion_nand.c
> > +++ b/drivers/mtd/nand/orion_nand.c
> > @@ -23,6 +23,11 @@
> > #include <asm/sizes.h>
> > #include <linux/platform_data/mtd-orion_nand.h>
> >
> > +struct orion_nand_info {
> > + struct nand_chip chip;
> > + struct clk *clk;
>
> Can we avoid this kind of alignment, which will not be preserved if
> someone adds a new field with a type that is longer than "struct
> nand_chip "?
>
Sure. I will change that in v2.
- Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-16 9:12 ` Boris Brezillon
@ 2017-03-16 21:50 ` Simon Baatz
-1 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-16 21:50 UTC (permalink / raw)
To: Boris Brezillon
Cc: Uwe Kleine-K?nig, linux-mtd, jason, andrew, richard,
linux-arm-kernel, dan.carpenter
On Thu, Mar 16, 2017 at 10:12:11AM +0100, Boris Brezillon wrote:
> On Mon, 13 Mar 2017 08:12:41 +0100
> Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
>
> > Hello Simon,
> >
> > On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > > The clk handling in orion_nand.c had two problems:
> > >
> > > - In the probe function, clk_put() was called for an enabled clock,
> > > which violates the API (see documentation for clk_put() in
> > > include/linux/clk.h)
> > >
> > > - In the error path of the probe function, clk_put() could be called
> > > twice for the same clock.
> > >
> > > In order to clean this up, use the managed function devm_clk_get() and
> > > store the pointer to the clk in the driver data.
> > >
> > > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > > Cc: <stable@vger.kernel.org> # v4.5+
> > > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > > ---
> > > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > > 1 file changed, 21 insertions(+), 21 deletions(-)
> > >
> > > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > > index 4a91c5d000be..b355aa738fae 100644
> > > --- a/drivers/mtd/nand/orion_nand.c
> > > +++ b/drivers/mtd/nand/orion_nand.c
> > > @@ -23,6 +23,11 @@
> > > #include <asm/sizes.h>
> > > #include <linux/platform_data/mtd-orion_nand.h>
> > >
> > > +struct orion_nand_info {
> > > + struct nand_chip chip;
> > > + struct clk *clk;
> > > +};
> > > +
> > > static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> > > {
> > > struct nand_chip *nc = mtd_to_nand(mtd);
> > > @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
> > >
> > > static int __init orion_nand_probe(struct platform_device *pdev)
> > > {
> > > + struct orion_nand_info *info;
> > > struct mtd_info *mtd;
> > > struct nand_chip *nc;
> > > struct orion_nand_data *board;
> > > struct resource *res;
> > > - struct clk *clk;
> > > void __iomem *io_base;
> > > int ret = 0;
> > > u32 val = 0;
> > >
> > > - nc = devm_kzalloc(&pdev->dev,
> > > - sizeof(struct nand_chip),
> > > + info = devm_kzalloc(&pdev->dev,
> > > + sizeof(struct orion_nand_info),
> > > GFP_KERNEL);
> > > - if (!nc)
> > > + if (!info)
> > > return -ENOMEM;
> > > + nc = &info->chip;
> > > mtd = nand_to_mtd(nc);
> > >
> > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> > > if (board->dev_ready)
> > > nc->dev_ready = board->dev_ready;
> > >
> > > - platform_set_drvdata(pdev, mtd);
> > > + platform_set_drvdata(pdev, info);
> > >
> > > /* Not all platforms can gate the clock, so it is not
> > > an error if the clock does not exists. */
> > > - clk = clk_get(&pdev->dev, NULL);
> > > - if (!IS_ERR(clk)) {
> > > - clk_prepare_enable(clk);
> > > - clk_put(clk);
> > > - }
> > > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > > + if (!IS_ERR(info->clk))
> > > + clk_prepare_enable(info->clk);
> >
> > Orthogonal to your patch I suggest:
> >
> > - info->clk = devm_clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(info->clk))
> > - clk_prepare_enable(info->clk);
> > + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > + if (IS_ERR(info->clk)) {
> > + ret = PTR_ERR(info->clk);
> > + if (ret != -EPROBE_DEFER)
> > + dev_err(...);
> > + return ret;
> > + }
> >
>
> In the meantime, maybe you can do:
>
> info->clk = devm_clk_get(&pdev->dev, NULL);
> if (IS_ERR(info->clk)) {
> ret = PTR_ERR(info->clk);
>
> if (ret == -ENOENT) {
> /*
> * This clk is optional, assign it to NULL when
> * it's not present.
> */
> info->clk = NULL;
> } else {
> if (ret == -EPROBE_DEFER)
> dev_err(...);
>
> return ret;
> }
> }
>
> This way, you won't have to check the info->clk value when you call
> clk_prepare_enable() or clk_disable_unprepare().
>
Yes, this makes things simpler. I will add a second patch improving
the error handling in v2 as you and Uwe suggested.
- Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-16 21:50 ` Simon Baatz
0 siblings, 0 replies; 18+ messages in thread
From: Simon Baatz @ 2017-03-16 21:50 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Mar 16, 2017 at 10:12:11AM +0100, Boris Brezillon wrote:
> On Mon, 13 Mar 2017 08:12:41 +0100
> Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de> wrote:
>
> > Hello Simon,
> >
> > On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > > The clk handling in orion_nand.c had two problems:
> > >
> > > - In the probe function, clk_put() was called for an enabled clock,
> > > which violates the API (see documentation for clk_put() in
> > > include/linux/clk.h)
> > >
> > > - In the error path of the probe function, clk_put() could be called
> > > twice for the same clock.
> > >
> > > In order to clean this up, use the managed function devm_clk_get() and
> > > store the pointer to the clk in the driver data.
> > >
> > > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > > Cc: <stable@vger.kernel.org> # v4.5+
> > > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > > ---
> > > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > > 1 file changed, 21 insertions(+), 21 deletions(-)
> > >
> > > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > > index 4a91c5d000be..b355aa738fae 100644
> > > --- a/drivers/mtd/nand/orion_nand.c
> > > +++ b/drivers/mtd/nand/orion_nand.c
> > > @@ -23,6 +23,11 @@
> > > #include <asm/sizes.h>
> > > #include <linux/platform_data/mtd-orion_nand.h>
> > >
> > > +struct orion_nand_info {
> > > + struct nand_chip chip;
> > > + struct clk *clk;
> > > +};
> > > +
> > > static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> > > {
> > > struct nand_chip *nc = mtd_to_nand(mtd);
> > > @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
> > >
> > > static int __init orion_nand_probe(struct platform_device *pdev)
> > > {
> > > + struct orion_nand_info *info;
> > > struct mtd_info *mtd;
> > > struct nand_chip *nc;
> > > struct orion_nand_data *board;
> > > struct resource *res;
> > > - struct clk *clk;
> > > void __iomem *io_base;
> > > int ret = 0;
> > > u32 val = 0;
> > >
> > > - nc = devm_kzalloc(&pdev->dev,
> > > - sizeof(struct nand_chip),
> > > + info = devm_kzalloc(&pdev->dev,
> > > + sizeof(struct orion_nand_info),
> > > GFP_KERNEL);
> > > - if (!nc)
> > > + if (!info)
> > > return -ENOMEM;
> > > + nc = &info->chip;
> > > mtd = nand_to_mtd(nc);
> > >
> > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> > > if (board->dev_ready)
> > > nc->dev_ready = board->dev_ready;
> > >
> > > - platform_set_drvdata(pdev, mtd);
> > > + platform_set_drvdata(pdev, info);
> > >
> > > /* Not all platforms can gate the clock, so it is not
> > > an error if the clock does not exists. */
> > > - clk = clk_get(&pdev->dev, NULL);
> > > - if (!IS_ERR(clk)) {
> > > - clk_prepare_enable(clk);
> > > - clk_put(clk);
> > > - }
> > > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > > + if (!IS_ERR(info->clk))
> > > + clk_prepare_enable(info->clk);
> >
> > Orthogonal to your patch I suggest:
> >
> > - info->clk = devm_clk_get(&pdev->dev, NULL);
> > - if (!IS_ERR(info->clk))
> > - clk_prepare_enable(info->clk);
> > + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > + if (IS_ERR(info->clk)) {
> > + ret = PTR_ERR(info->clk);
> > + if (ret != -EPROBE_DEFER)
> > + dev_err(...);
> > + return ret;
> > + }
> >
>
> In the meantime, maybe you can do:
>
> info->clk = devm_clk_get(&pdev->dev, NULL);
> if (IS_ERR(info->clk)) {
> ret = PTR_ERR(info->clk);
>
> if (ret == -ENOENT) {
> /*
> * This clk is optional, assign it to NULL when
> * it's not present.
> */
> info->clk = NULL;
> } else {
> if (ret == -EPROBE_DEFER)
> dev_err(...);
>
> return ret;
> }
> }
>
> This way, you won't have to check the info->clk value when you call
> clk_prepare_enable() or clk_disable_unprepare().
>
Yes, this makes things simpler. I will add a second patch improving
the error handling in v2 as you and Uwe suggested.
- Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH] mtd: nand: orion: fix clk handling
2017-03-16 21:50 ` Simon Baatz
@ 2017-03-17 6:36 ` Boris Brezillon
-1 siblings, 0 replies; 18+ messages in thread
From: Boris Brezillon @ 2017-03-17 6:36 UTC (permalink / raw)
To: Simon Baatz
Cc: Uwe Kleine-K?nig, linux-mtd, jason, andrew, richard,
linux-arm-kernel, dan.carpenter
On Thu, 16 Mar 2017 22:50:31 +0100
Simon Baatz <gmbnomis@gmail.com> wrote:
> On Thu, Mar 16, 2017 at 10:12:11AM +0100, Boris Brezillon wrote:
> > On Mon, 13 Mar 2017 08:12:41 +0100
> > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> >
> > > Hello Simon,
> > >
> > > On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > > > The clk handling in orion_nand.c had two problems:
> > > >
> > > > - In the probe function, clk_put() was called for an enabled clock,
> > > > which violates the API (see documentation for clk_put() in
> > > > include/linux/clk.h)
> > > >
> > > > - In the error path of the probe function, clk_put() could be called
> > > > twice for the same clock.
> > > >
> > > > In order to clean this up, use the managed function devm_clk_get() and
> > > > store the pointer to the clk in the driver data.
> > > >
> > > > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > > > Cc: <stable@vger.kernel.org> # v4.5+
> > > > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > > > ---
> > > > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > > > 1 file changed, 21 insertions(+), 21 deletions(-)
> > > >
> > > > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > > > index 4a91c5d000be..b355aa738fae 100644
> > > > --- a/drivers/mtd/nand/orion_nand.c
> > > > +++ b/drivers/mtd/nand/orion_nand.c
> > > > @@ -23,6 +23,11 @@
> > > > #include <asm/sizes.h>
> > > > #include <linux/platform_data/mtd-orion_nand.h>
> > > >
> > > > +struct orion_nand_info {
> > > > + struct nand_chip chip;
> > > > + struct clk *clk;
> > > > +};
> > > > +
> > > > static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> > > > {
> > > > struct nand_chip *nc = mtd_to_nand(mtd);
> > > > @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
> > > >
> > > > static int __init orion_nand_probe(struct platform_device *pdev)
> > > > {
> > > > + struct orion_nand_info *info;
> > > > struct mtd_info *mtd;
> > > > struct nand_chip *nc;
> > > > struct orion_nand_data *board;
> > > > struct resource *res;
> > > > - struct clk *clk;
> > > > void __iomem *io_base;
> > > > int ret = 0;
> > > > u32 val = 0;
> > > >
> > > > - nc = devm_kzalloc(&pdev->dev,
> > > > - sizeof(struct nand_chip),
> > > > + info = devm_kzalloc(&pdev->dev,
> > > > + sizeof(struct orion_nand_info),
> > > > GFP_KERNEL);
> > > > - if (!nc)
> > > > + if (!info)
> > > > return -ENOMEM;
> > > > + nc = &info->chip;
> > > > mtd = nand_to_mtd(nc);
> > > >
> > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > > @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> > > > if (board->dev_ready)
> > > > nc->dev_ready = board->dev_ready;
> > > >
> > > > - platform_set_drvdata(pdev, mtd);
> > > > + platform_set_drvdata(pdev, info);
> > > >
> > > > /* Not all platforms can gate the clock, so it is not
> > > > an error if the clock does not exists. */
> > > > - clk = clk_get(&pdev->dev, NULL);
> > > > - if (!IS_ERR(clk)) {
> > > > - clk_prepare_enable(clk);
> > > > - clk_put(clk);
> > > > - }
> > > > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > > > + if (!IS_ERR(info->clk))
> > > > + clk_prepare_enable(info->clk);
> > >
> > > Orthogonal to your patch I suggest:
> > >
> > > - info->clk = devm_clk_get(&pdev->dev, NULL);
> > > - if (!IS_ERR(info->clk))
> > > - clk_prepare_enable(info->clk);
> > > + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > > + if (IS_ERR(info->clk)) {
> > > + ret = PTR_ERR(info->clk);
> > > + if (ret != -EPROBE_DEFER)
> > > + dev_err(...);
> > > + return ret;
> > > + }
> > >
> >
> > In the meantime, maybe you can do:
> >
> > info->clk = devm_clk_get(&pdev->dev, NULL);
> > if (IS_ERR(info->clk)) {
> > ret = PTR_ERR(info->clk);
> >
> > if (ret == -ENOENT) {
> > /*
> > * This clk is optional, assign it to NULL when
> > * it's not present.
> > */
> > info->clk = NULL;
> > } else {
> > if (ret == -EPROBE_DEFER)
I meant != -EPROBE_DEFER here.
> > dev_err(...);
> >
> > return ret;
> > }
> > }
> >
> > This way, you won't have to check the info->clk value when you call
> > clk_prepare_enable() or clk_disable_unprepare().
> >
>
> Yes, this makes things simpler. I will add a second patch improving
> the error handling in v2 as you and Uwe suggested.
>
>
> - Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH] mtd: nand: orion: fix clk handling
@ 2017-03-17 6:36 ` Boris Brezillon
0 siblings, 0 replies; 18+ messages in thread
From: Boris Brezillon @ 2017-03-17 6:36 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, 16 Mar 2017 22:50:31 +0100
Simon Baatz <gmbnomis@gmail.com> wrote:
> On Thu, Mar 16, 2017 at 10:12:11AM +0100, Boris Brezillon wrote:
> > On Mon, 13 Mar 2017 08:12:41 +0100
> > Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de> wrote:
> >
> > > Hello Simon,
> > >
> > > On Sun, Mar 12, 2017 at 10:34:06PM +0100, Simon Baatz wrote:
> > > > The clk handling in orion_nand.c had two problems:
> > > >
> > > > - In the probe function, clk_put() was called for an enabled clock,
> > > > which violates the API (see documentation for clk_put() in
> > > > include/linux/clk.h)
> > > >
> > > > - In the error path of the probe function, clk_put() could be called
> > > > twice for the same clock.
> > > >
> > > > In order to clean this up, use the managed function devm_clk_get() and
> > > > store the pointer to the clk in the driver data.
> > > >
> > > > Fixes: baffab28b13120694fa3ebab08d3e99667a851d2 ('ARM: Orion: fix driver probe error handling with respect to clk')
> > > > Cc: <stable@vger.kernel.org> # v4.5+
> > > > Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
> > > > ---
> > > > drivers/mtd/nand/orion_nand.c | 42 +++++++++++++++++++++---------------------
> > > > 1 file changed, 21 insertions(+), 21 deletions(-)
> > > >
> > > > diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> > > > index 4a91c5d000be..b355aa738fae 100644
> > > > --- a/drivers/mtd/nand/orion_nand.c
> > > > +++ b/drivers/mtd/nand/orion_nand.c
> > > > @@ -23,6 +23,11 @@
> > > > #include <asm/sizes.h>
> > > > #include <linux/platform_data/mtd-orion_nand.h>
> > > >
> > > > +struct orion_nand_info {
> > > > + struct nand_chip chip;
> > > > + struct clk *clk;
> > > > +};
> > > > +
> > > > static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
> > > > {
> > > > struct nand_chip *nc = mtd_to_nand(mtd);
> > > > @@ -75,20 +80,21 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
> > > >
> > > > static int __init orion_nand_probe(struct platform_device *pdev)
> > > > {
> > > > + struct orion_nand_info *info;
> > > > struct mtd_info *mtd;
> > > > struct nand_chip *nc;
> > > > struct orion_nand_data *board;
> > > > struct resource *res;
> > > > - struct clk *clk;
> > > > void __iomem *io_base;
> > > > int ret = 0;
> > > > u32 val = 0;
> > > >
> > > > - nc = devm_kzalloc(&pdev->dev,
> > > > - sizeof(struct nand_chip),
> > > > + info = devm_kzalloc(&pdev->dev,
> > > > + sizeof(struct orion_nand_info),
> > > > GFP_KERNEL);
> > > > - if (!nc)
> > > > + if (!info)
> > > > return -ENOMEM;
> > > > + nc = &info->chip;
> > > > mtd = nand_to_mtd(nc);
> > > >
> > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > > @@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
> > > > if (board->dev_ready)
> > > > nc->dev_ready = board->dev_ready;
> > > >
> > > > - platform_set_drvdata(pdev, mtd);
> > > > + platform_set_drvdata(pdev, info);
> > > >
> > > > /* Not all platforms can gate the clock, so it is not
> > > > an error if the clock does not exists. */
> > > > - clk = clk_get(&pdev->dev, NULL);
> > > > - if (!IS_ERR(clk)) {
> > > > - clk_prepare_enable(clk);
> > > > - clk_put(clk);
> > > > - }
> > > > + info->clk = devm_clk_get(&pdev->dev, NULL);
> > > > + if (!IS_ERR(info->clk))
> > > > + clk_prepare_enable(info->clk);
> > >
> > > Orthogonal to your patch I suggest:
> > >
> > > - info->clk = devm_clk_get(&pdev->dev, NULL);
> > > - if (!IS_ERR(info->clk))
> > > - clk_prepare_enable(info->clk);
> > > + info->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > > + if (IS_ERR(info->clk)) {
> > > + ret = PTR_ERR(info->clk);
> > > + if (ret != -EPROBE_DEFER)
> > > + dev_err(...);
> > > + return ret;
> > > + }
> > >
> >
> > In the meantime, maybe you can do:
> >
> > info->clk = devm_clk_get(&pdev->dev, NULL);
> > if (IS_ERR(info->clk)) {
> > ret = PTR_ERR(info->clk);
> >
> > if (ret == -ENOENT) {
> > /*
> > * This clk is optional, assign it to NULL when
> > * it's not present.
> > */
> > info->clk = NULL;
> > } else {
> > if (ret == -EPROBE_DEFER)
I meant != -EPROBE_DEFER here.
> > dev_err(...);
> >
> > return ret;
> > }
> > }
> >
> > This way, you won't have to check the info->clk value when you call
> > clk_prepare_enable() or clk_disable_unprepare().
> >
>
> Yes, this makes things simpler. I will add a second patch improving
> the error handling in v2 as you and Uwe suggested.
>
>
> - Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2017-03-17 6:36 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 21:34 [PATCH] mtd: nand: orion: fix clk handling Simon Baatz
2017-03-12 21:34 ` Simon Baatz
2017-03-13 7:12 ` Uwe Kleine-König
2017-03-13 7:12 ` Uwe Kleine-König
2017-03-13 20:43 ` Simon Baatz
2017-03-13 20:43 ` Simon Baatz
2017-03-13 20:58 ` Uwe Kleine-König
2017-03-13 20:58 ` Uwe Kleine-König
2017-03-16 9:12 ` Boris Brezillon
2017-03-16 9:12 ` Boris Brezillon
2017-03-16 21:50 ` Simon Baatz
2017-03-16 21:50 ` Simon Baatz
2017-03-17 6:36 ` Boris Brezillon
2017-03-17 6:36 ` Boris Brezillon
2017-03-16 9:05 ` Boris Brezillon
2017-03-16 9:05 ` Boris Brezillon
2017-03-16 21:44 ` Simon Baatz
2017-03-16 21:44 ` Simon Baatz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.