Commit 675b11d9 authored by Simon Baatz's avatar Simon Baatz Committed by Boris Brezillon

mtd: nand: orion: fix clk handling

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: baffab28 ('ARM: Orion: fix driver probe error handling with respect to clk')
Cc: <stable@vger.kernel.org> # v4.5+
Signed-off-by: default avatarSimon Baatz <gmbnomis@gmail.com>
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
parent e713ddd8
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
#include <asm/sizes.h> #include <asm/sizes.h>
#include <linux/platform_data/mtd-orion_nand.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) static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
{ {
struct nand_chip *nc = mtd_to_nand(mtd); 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) ...@@ -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) static int __init orion_nand_probe(struct platform_device *pdev)
{ {
struct orion_nand_info *info;
struct mtd_info *mtd; struct mtd_info *mtd;
struct nand_chip *nc; struct nand_chip *nc;
struct orion_nand_data *board; struct orion_nand_data *board;
struct resource *res; struct resource *res;
struct clk *clk;
void __iomem *io_base; void __iomem *io_base;
int ret = 0; int ret = 0;
u32 val = 0; u32 val = 0;
nc = devm_kzalloc(&pdev->dev, info = devm_kzalloc(&pdev->dev,
sizeof(struct nand_chip), sizeof(struct orion_nand_info),
GFP_KERNEL); GFP_KERNEL);
if (!nc) if (!info)
return -ENOMEM; return -ENOMEM;
nc = &info->chip;
mtd = nand_to_mtd(nc); mtd = nand_to_mtd(nc);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...@@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev) ...@@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
if (board->dev_ready) if (board->dev_ready)
nc->dev_ready = 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 /* Not all platforms can gate the clock, so it is not
an error if the clock does not exists. */ an error if the clock does not exists. */
clk = clk_get(&pdev->dev, NULL); info->clk = devm_clk_get(&pdev->dev, NULL);
if (!IS_ERR(clk)) { if (!IS_ERR(info->clk))
clk_prepare_enable(clk); clk_prepare_enable(info->clk);
clk_put(clk);
}
ret = nand_scan(mtd, 1); ret = nand_scan(mtd, 1);
if (ret) if (ret)
...@@ -169,26 +173,22 @@ static int __init orion_nand_probe(struct platform_device *pdev) ...@@ -169,26 +173,22 @@ static int __init orion_nand_probe(struct platform_device *pdev)
return 0; return 0;
no_dev: no_dev:
if (!IS_ERR(clk)) { if (!IS_ERR(info->clk))
clk_disable_unprepare(clk); clk_disable_unprepare(info->clk);
clk_put(clk);
}
return ret; return ret;
} }
static int orion_nand_remove(struct platform_device *pdev) static int orion_nand_remove(struct platform_device *pdev)
{ {
struct mtd_info *mtd = platform_get_drvdata(pdev); struct orion_nand_info *info = platform_get_drvdata(pdev);
struct clk *clk; struct nand_chip *chip = &info->chip;
struct mtd_info *mtd = nand_to_mtd(chip);
nand_release(mtd); nand_release(mtd);
clk = clk_get(&pdev->dev, NULL); if (!IS_ERR(info->clk))
if (!IS_ERR(clk)) { clk_disable_unprepare(info->clk);
clk_disable_unprepare(clk);
clk_put(clk);
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment