aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Baatz <gmbnomis@gmail.com>2017-03-27 14:02:07 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-25 09:44:48 -0400
commite437af936a49680ac509b9d51f1b51b11c8da605 (patch)
tree711c2f8e5bf42407c1b0f206e8273f91b407b8c2
parentdb663641619558c9a1b8b77f5bfd351e131b57a7 (diff)
mtd: nand: orion: fix clk handling
commit 675b11d94ce9baa5eb365a51b35d2793f77c8ab8 upstream. 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') Signed-off-by: Simon Baatz <gmbnomis@gmail.com> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/mtd/nand/orion_nand.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 40a7c4a2cf0d..af2f09135fb0 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -23,6 +23,11 @@
23#include <asm/sizes.h> 23#include <asm/sizes.h>
24#include <linux/platform_data/mtd-orion_nand.h> 24#include <linux/platform_data/mtd-orion_nand.h>
25 25
26struct orion_nand_info {
27 struct nand_chip chip;
28 struct clk *clk;
29};
30
26static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 31static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
27{ 32{
28 struct nand_chip *nc = mtd_to_nand(mtd); 33 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 80
76static int __init orion_nand_probe(struct platform_device *pdev) 81static int __init orion_nand_probe(struct platform_device *pdev)
77{ 82{
83 struct orion_nand_info *info;
78 struct mtd_info *mtd; 84 struct mtd_info *mtd;
79 struct nand_chip *nc; 85 struct nand_chip *nc;
80 struct orion_nand_data *board; 86 struct orion_nand_data *board;
81 struct resource *res; 87 struct resource *res;
82 struct clk *clk;
83 void __iomem *io_base; 88 void __iomem *io_base;
84 int ret = 0; 89 int ret = 0;
85 u32 val = 0; 90 u32 val = 0;
86 91
87 nc = devm_kzalloc(&pdev->dev, 92 info = devm_kzalloc(&pdev->dev,
88 sizeof(struct nand_chip), 93 sizeof(struct orion_nand_info),
89 GFP_KERNEL); 94 GFP_KERNEL);
90 if (!nc) 95 if (!info)
91 return -ENOMEM; 96 return -ENOMEM;
97 nc = &info->chip;
92 mtd = nand_to_mtd(nc); 98 mtd = nand_to_mtd(nc);
93 99
94 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 100 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -145,15 +151,13 @@ static int __init orion_nand_probe(struct platform_device *pdev)
145 if (board->dev_ready) 151 if (board->dev_ready)
146 nc->dev_ready = board->dev_ready; 152 nc->dev_ready = board->dev_ready;
147 153
148 platform_set_drvdata(pdev, mtd); 154 platform_set_drvdata(pdev, info);
149 155
150 /* Not all platforms can gate the clock, so it is not 156 /* Not all platforms can gate the clock, so it is not
151 an error if the clock does not exists. */ 157 an error if the clock does not exists. */
152 clk = clk_get(&pdev->dev, NULL); 158 info->clk = devm_clk_get(&pdev->dev, NULL);
153 if (!IS_ERR(clk)) { 159 if (!IS_ERR(info->clk))
154 clk_prepare_enable(clk); 160 clk_prepare_enable(info->clk);
155 clk_put(clk);
156 }
157 161
158 if (nand_scan(mtd, 1)) { 162 if (nand_scan(mtd, 1)) {
159 ret = -ENXIO; 163 ret = -ENXIO;
@@ -170,26 +174,22 @@ static int __init orion_nand_probe(struct platform_device *pdev)
170 return 0; 174 return 0;
171 175
172no_dev: 176no_dev:
173 if (!IS_ERR(clk)) { 177 if (!IS_ERR(info->clk))
174 clk_disable_unprepare(clk); 178 clk_disable_unprepare(info->clk);
175 clk_put(clk);
176 }
177 179
178 return ret; 180 return ret;
179} 181}
180 182
181static int orion_nand_remove(struct platform_device *pdev) 183static int orion_nand_remove(struct platform_device *pdev)
182{ 184{
183 struct mtd_info *mtd = platform_get_drvdata(pdev); 185 struct orion_nand_info *info = platform_get_drvdata(pdev);
184 struct clk *clk; 186 struct nand_chip *chip = &info->chip;
187 struct mtd_info *mtd = nand_to_mtd(chip);
185 188
186 nand_release(mtd); 189 nand_release(mtd);
187 190
188 clk = clk_get(&pdev->dev, NULL); 191 if (!IS_ERR(info->clk))
189 if (!IS_ERR(clk)) { 192 clk_disable_unprepare(info->clk);
190 clk_disable_unprepare(clk);
191 clk_put(clk);
192 }
193 193
194 return 0; 194 return 0;
195} 195}