aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Baatz <gmbnomis@gmail.com>2017-03-27 14:02:07 -0400
committerBoris Brezillon <boris.brezillon@free-electrons.com>2017-03-29 11:05:34 -0400
commit675b11d94ce9baa5eb365a51b35d2793f77c8ab8 (patch)
tree0d880e4b1591a333d4c923bc3c2dd7b63a4be891
parente713ddd87ccee801be1fd13f478407b1bde93c21 (diff)
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: 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> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
-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 4a91c5d000be..3acdc20485f1 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 ret = nand_scan(mtd, 1); 162 ret = nand_scan(mtd, 1);
159 if (ret) 163 if (ret)
@@ -169,26 +173,22 @@ static int __init orion_nand_probe(struct platform_device *pdev)
169 return 0; 173 return 0;
170 174
171no_dev: 175no_dev:
172 if (!IS_ERR(clk)) { 176 if (!IS_ERR(info->clk))
173 clk_disable_unprepare(clk); 177 clk_disable_unprepare(info->clk);
174 clk_put(clk);
175 }
176 178
177 return ret; 179 return ret;
178} 180}
179 181
180static int orion_nand_remove(struct platform_device *pdev) 182static int orion_nand_remove(struct platform_device *pdev)
181{ 183{
182 struct mtd_info *mtd = platform_get_drvdata(pdev); 184 struct orion_nand_info *info = platform_get_drvdata(pdev);
183 struct clk *clk; 185 struct nand_chip *chip = &info->chip;
186 struct mtd_info *mtd = nand_to_mtd(chip);
184 187
185 nand_release(mtd); 188 nand_release(mtd);
186 189
187 clk = clk_get(&pdev->dev, NULL); 190 if (!IS_ERR(info->clk))
188 if (!IS_ERR(clk)) { 191 clk_disable_unprepare(info->clk);
189 clk_disable_unprepare(clk);
190 clk_put(clk);
191 }
192 192
193 return 0; 193 return 0;
194} 194}