diff options
author | Viresh Kumar <viresh.kumar@st.com> | 2012-03-12 00:21:59 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2012-03-27 14:14:15 -0400 |
commit | 75f5a536c0b605b9b8406325f51f62f67141973e (patch) | |
tree | 657168af4ffe1dbe0aee01903e8e2079567cc4e7 /drivers/watchdog | |
parent | aa065770f55f44ed24f0a9b76ec6e2135264d43b (diff) |
watchdog: mpcore_wdt: Use devm routines
mpcore_wdt driver currently uses normal kzalloc, request_irq, ioremap, etc
routines. This patch replaces these routines with devm_kzalloc and
devm_request_mem_region etc, so that we don't need to handle freeing of
resources for error cases and module removal routine.
Also, request_irq is moved before registering misc device, so that we are ready
for irq as soon as device is registered.
Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r-- | drivers/watchdog/mpcore_wdt.c | 58 |
1 files changed, 19 insertions, 39 deletions
diff --git a/drivers/watchdog/mpcore_wdt.c b/drivers/watchdog/mpcore_wdt.c index ca0810ed00a8..2d8c0a006b87 100644 --- a/drivers/watchdog/mpcore_wdt.c +++ b/drivers/watchdog/mpcore_wdt.c | |||
@@ -338,43 +338,37 @@ static int __devinit mpcore_wdt_probe(struct platform_device *pdev) | |||
338 | return -ENODEV; | 338 | return -ENODEV; |
339 | 339 | ||
340 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 340 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
341 | if (!res) { | 341 | if (!res) |
342 | ret = -ENODEV; | 342 | return -ENODEV; |
343 | goto err_out; | ||
344 | } | ||
345 | 343 | ||
346 | wdt = kzalloc(sizeof(struct mpcore_wdt), GFP_KERNEL); | 344 | wdt = devm_kzalloc(&pdev->dev, sizeof(struct mpcore_wdt), GFP_KERNEL); |
347 | if (!wdt) { | 345 | if (!wdt) |
348 | ret = -ENOMEM; | 346 | return -ENOMEM; |
349 | goto err_out; | ||
350 | } | ||
351 | 347 | ||
352 | wdt->dev = &pdev->dev; | 348 | wdt->dev = &pdev->dev; |
353 | wdt->irq = platform_get_irq(pdev, 0); | 349 | wdt->irq = platform_get_irq(pdev, 0); |
354 | if (wdt->irq < 0) { | 350 | if (wdt->irq < 0) |
355 | ret = -ENXIO; | 351 | return -ENXIO; |
356 | goto err_free; | 352 | |
357 | } | 353 | ret = devm_request_irq(wdt->dev, wdt->irq, mpcore_wdt_fire, 0, |
358 | wdt->base = ioremap(res->start, resource_size(res)); | 354 | "mpcore_wdt", wdt); |
359 | if (!wdt->base) { | 355 | if (ret) { |
360 | ret = -ENOMEM; | 356 | dev_printk(KERN_ERR, wdt->dev, |
361 | goto err_free; | 357 | "cannot register IRQ%d for watchdog\n", wdt->irq); |
358 | return ret; | ||
362 | } | 359 | } |
363 | 360 | ||
361 | wdt->base = devm_ioremap(wdt->dev, res->start, resource_size(res)); | ||
362 | if (!wdt->base) | ||
363 | return -ENOMEM; | ||
364 | |||
364 | mpcore_wdt_miscdev.parent = &pdev->dev; | 365 | mpcore_wdt_miscdev.parent = &pdev->dev; |
365 | ret = misc_register(&mpcore_wdt_miscdev); | 366 | ret = misc_register(&mpcore_wdt_miscdev); |
366 | if (ret) { | 367 | if (ret) { |
367 | dev_printk(KERN_ERR, wdt->dev, | 368 | dev_printk(KERN_ERR, wdt->dev, |
368 | "cannot register miscdev on minor=%d (err=%d)\n", | 369 | "cannot register miscdev on minor=%d (err=%d)\n", |
369 | WATCHDOG_MINOR, ret); | 370 | WATCHDOG_MINOR, ret); |
370 | goto err_misc; | 371 | return ret; |
371 | } | ||
372 | |||
373 | ret = request_irq(wdt->irq, mpcore_wdt_fire, 0, "mpcore_wdt", wdt); | ||
374 | if (ret) { | ||
375 | dev_printk(KERN_ERR, wdt->dev, | ||
376 | "cannot register IRQ%d for watchdog\n", wdt->irq); | ||
377 | goto err_irq; | ||
378 | } | 372 | } |
379 | 373 | ||
380 | mpcore_wdt_stop(wdt); | 374 | mpcore_wdt_stop(wdt); |
@@ -382,30 +376,16 @@ static int __devinit mpcore_wdt_probe(struct platform_device *pdev) | |||
382 | mpcore_wdt_pdev = pdev; | 376 | mpcore_wdt_pdev = pdev; |
383 | 377 | ||
384 | return 0; | 378 | return 0; |
385 | |||
386 | err_irq: | ||
387 | misc_deregister(&mpcore_wdt_miscdev); | ||
388 | err_misc: | ||
389 | iounmap(wdt->base); | ||
390 | err_free: | ||
391 | kfree(wdt); | ||
392 | err_out: | ||
393 | return ret; | ||
394 | } | 379 | } |
395 | 380 | ||
396 | static int __devexit mpcore_wdt_remove(struct platform_device *pdev) | 381 | static int __devexit mpcore_wdt_remove(struct platform_device *pdev) |
397 | { | 382 | { |
398 | struct mpcore_wdt *wdt = platform_get_drvdata(pdev); | ||
399 | |||
400 | platform_set_drvdata(pdev, NULL); | 383 | platform_set_drvdata(pdev, NULL); |
401 | 384 | ||
402 | misc_deregister(&mpcore_wdt_miscdev); | 385 | misc_deregister(&mpcore_wdt_miscdev); |
403 | 386 | ||
404 | mpcore_wdt_pdev = NULL; | 387 | mpcore_wdt_pdev = NULL; |
405 | 388 | ||
406 | free_irq(wdt->irq, wdt); | ||
407 | iounmap(wdt->base); | ||
408 | kfree(wdt); | ||
409 | return 0; | 389 | return 0; |
410 | } | 390 | } |
411 | 391 | ||