diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2013-02-15 10:13:58 -0500 |
---|---|---|
committer | Chris Ball <cjb@laptop.org> | 2013-02-24 14:37:23 -0500 |
commit | ac51b9611db597aa55e06218c62c3511702d772f (patch) | |
tree | 4a43d9ea483e812ebe010f2c8e0fcaf754f79328 /drivers/mmc | |
parent | 76a411f9f9423cbc9f62e70173459c5af54323f4 (diff) |
mmc: sh_mobile_sdhi: use managed resource allocations
Use managed allocations to get memory, clock and interrupts . This
significantly simplifies clean up paths.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/host/sh_mobile_sdhi.c | 57 |
1 files changed, 14 insertions, 43 deletions
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c index 175ab970952a..fe90853900b4 100644 --- a/drivers/mmc/host/sh_mobile_sdhi.c +++ b/drivers/mmc/host/sh_mobile_sdhi.c | |||
@@ -147,7 +147,7 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
147 | int irq, ret, i = 0; | 147 | int irq, ret, i = 0; |
148 | bool multiplexed_isr = true; | 148 | bool multiplexed_isr = true; |
149 | 149 | ||
150 | priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL); | 150 | priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL); |
151 | if (priv == NULL) { | 151 | if (priv == NULL) { |
152 | dev_err(&pdev->dev, "kzalloc failed\n"); | 152 | dev_err(&pdev->dev, "kzalloc failed\n"); |
153 | return -ENOMEM; | 153 | return -ENOMEM; |
@@ -159,11 +159,11 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
159 | if (p->init) { | 159 | if (p->init) { |
160 | ret = p->init(pdev, &sdhi_ops); | 160 | ret = p->init(pdev, &sdhi_ops); |
161 | if (ret) | 161 | if (ret) |
162 | goto einit; | 162 | return ret; |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | priv->clk = clk_get(&pdev->dev, NULL); | 166 | priv->clk = devm_clk_get(&pdev->dev, NULL); |
167 | if (IS_ERR(priv->clk)) { | 167 | if (IS_ERR(priv->clk)) { |
168 | ret = PTR_ERR(priv->clk); | 168 | ret = PTR_ERR(priv->clk); |
169 | dev_err(&pdev->dev, "cannot get clock: %d\n", ret); | 169 | dev_err(&pdev->dev, "cannot get clock: %d\n", ret); |
@@ -223,33 +223,33 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
223 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT); | 223 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT); |
224 | if (irq >= 0) { | 224 | if (irq >= 0) { |
225 | multiplexed_isr = false; | 225 | multiplexed_isr = false; |
226 | ret = request_irq(irq, tmio_mmc_card_detect_irq, 0, | 226 | ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_card_detect_irq, 0, |
227 | dev_name(&pdev->dev), host); | 227 | dev_name(&pdev->dev), host); |
228 | if (ret) | 228 | if (ret) |
229 | goto eirq_card_detect; | 229 | goto eirq; |
230 | } | 230 | } |
231 | 231 | ||
232 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO); | 232 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO); |
233 | if (irq >= 0) { | 233 | if (irq >= 0) { |
234 | multiplexed_isr = false; | 234 | multiplexed_isr = false; |
235 | ret = request_irq(irq, tmio_mmc_sdio_irq, 0, | 235 | ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdio_irq, 0, |
236 | dev_name(&pdev->dev), host); | 236 | dev_name(&pdev->dev), host); |
237 | if (ret) | 237 | if (ret) |
238 | goto eirq_sdio; | 238 | goto eirq; |
239 | } | 239 | } |
240 | 240 | ||
241 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD); | 241 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD); |
242 | if (irq >= 0) { | 242 | if (irq >= 0) { |
243 | multiplexed_isr = false; | 243 | multiplexed_isr = false; |
244 | ret = request_irq(irq, tmio_mmc_sdcard_irq, 0, | 244 | ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdcard_irq, 0, |
245 | dev_name(&pdev->dev), host); | 245 | dev_name(&pdev->dev), host); |
246 | if (ret) | 246 | if (ret) |
247 | goto eirq_sdcard; | 247 | goto eirq; |
248 | } else if (!multiplexed_isr) { | 248 | } else if (!multiplexed_isr) { |
249 | dev_err(&pdev->dev, | 249 | dev_err(&pdev->dev, |
250 | "Principal SD-card IRQ is missing among named interrupts\n"); | 250 | "Principal SD-card IRQ is missing among named interrupts\n"); |
251 | ret = irq; | 251 | ret = irq; |
252 | goto eirq_sdcard; | 252 | goto eirq; |
253 | } | 253 | } |
254 | 254 | ||
255 | if (multiplexed_isr) { | 255 | if (multiplexed_isr) { |
@@ -258,15 +258,15 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
258 | if (irq < 0) | 258 | if (irq < 0) |
259 | break; | 259 | break; |
260 | i++; | 260 | i++; |
261 | ret = request_irq(irq, tmio_mmc_irq, 0, | 261 | ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0, |
262 | dev_name(&pdev->dev), host); | 262 | dev_name(&pdev->dev), host); |
263 | if (ret) | 263 | if (ret) |
264 | goto eirq_multiplexed; | 264 | goto eirq; |
265 | } | 265 | } |
266 | 266 | ||
267 | /* There must be at least one IRQ source */ | 267 | /* There must be at least one IRQ source */ |
268 | if (!i) | 268 | if (!i) |
269 | goto eirq_multiplexed; | 269 | goto eirq; |
270 | } | 270 | } |
271 | 271 | ||
272 | dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n", | 272 | dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n", |
@@ -276,28 +276,12 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
276 | 276 | ||
277 | return ret; | 277 | return ret; |
278 | 278 | ||
279 | eirq_multiplexed: | 279 | eirq: |
280 | while (i--) { | ||
281 | irq = platform_get_irq(pdev, i); | ||
282 | free_irq(irq, host); | ||
283 | } | ||
284 | eirq_sdcard: | ||
285 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO); | ||
286 | if (irq >= 0) | ||
287 | free_irq(irq, host); | ||
288 | eirq_sdio: | ||
289 | irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT); | ||
290 | if (irq >= 0) | ||
291 | free_irq(irq, host); | ||
292 | eirq_card_detect: | ||
293 | tmio_mmc_host_remove(host); | 280 | tmio_mmc_host_remove(host); |
294 | eprobe: | 281 | eprobe: |
295 | clk_put(priv->clk); | ||
296 | eclkget: | 282 | eclkget: |
297 | if (p && p->cleanup) | 283 | if (p && p->cleanup) |
298 | p->cleanup(pdev); | 284 | p->cleanup(pdev); |
299 | einit: | ||
300 | kfree(priv); | ||
301 | return ret; | 285 | return ret; |
302 | } | 286 | } |
303 | 287 | ||
@@ -305,26 +289,13 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev) | |||
305 | { | 289 | { |
306 | struct mmc_host *mmc = platform_get_drvdata(pdev); | 290 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
307 | struct tmio_mmc_host *host = mmc_priv(mmc); | 291 | struct tmio_mmc_host *host = mmc_priv(mmc); |
308 | struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); | ||
309 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; | 292 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; |
310 | int i = 0, irq; | ||
311 | 293 | ||
312 | tmio_mmc_host_remove(host); | 294 | tmio_mmc_host_remove(host); |
313 | 295 | ||
314 | while (1) { | ||
315 | irq = platform_get_irq(pdev, i++); | ||
316 | if (irq < 0) | ||
317 | break; | ||
318 | free_irq(irq, host); | ||
319 | } | ||
320 | |||
321 | clk_put(priv->clk); | ||
322 | |||
323 | if (p && p->cleanup) | 296 | if (p && p->cleanup) |
324 | p->cleanup(pdev); | 297 | p->cleanup(pdev); |
325 | 298 | ||
326 | kfree(priv); | ||
327 | |||
328 | return 0; | 299 | return 0; |
329 | } | 300 | } |
330 | 301 | ||