diff options
author | Hannu Heikkinen <ext-hannu.m.heikkinen@nokia.com> | 2012-05-29 18:07:40 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 19:22:34 -0400 |
commit | 621bae79f1a250e443eb83d1f473c533bea493dc (patch) | |
tree | 00bd66ff5b79fec03980a2a8d6c99b2fa8eb649f /drivers/rtc/rtc-tegra.c | |
parent | ac2dee5984bc78c8ff1893142f7322320d2baf05 (diff) |
drivers/rtc/rtc-tegra.c: clean up probe/remove routines
Use the devres managed resource functions in the probe routine. Also
affects the remove routine where the previously used free and release
functions are not needed.
The devm_* functions eliminate the need for manual resource releasing and
simplify error handling. Resources allocated by devm_* are freed
automatically on driver detach.
Signed-off-by: Hannu Heikkinen <ext-hannu.m.heikkinen@nokia.com>
Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-tegra.c')
-rw-r--r-- | drivers/rtc/rtc-tegra.c | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c index 75259fe38602..c006025cecc8 100644 --- a/drivers/rtc/rtc-tegra.c +++ b/drivers/rtc/rtc-tegra.c | |||
@@ -309,7 +309,8 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) | |||
309 | struct resource *res; | 309 | struct resource *res; |
310 | int ret; | 310 | int ret; |
311 | 311 | ||
312 | info = kzalloc(sizeof(struct tegra_rtc_info), GFP_KERNEL); | 312 | info = devm_kzalloc(&pdev->dev, sizeof(struct tegra_rtc_info), |
313 | GFP_KERNEL); | ||
313 | if (!info) | 314 | if (!info) |
314 | return -ENOMEM; | 315 | return -ENOMEM; |
315 | 316 | ||
@@ -317,29 +318,18 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) | |||
317 | if (!res) { | 318 | if (!res) { |
318 | dev_err(&pdev->dev, | 319 | dev_err(&pdev->dev, |
319 | "Unable to allocate resources for device.\n"); | 320 | "Unable to allocate resources for device.\n"); |
320 | ret = -EBUSY; | 321 | return -EBUSY; |
321 | goto err_free_info; | ||
322 | } | 322 | } |
323 | 323 | ||
324 | if (!request_mem_region(res->start, resource_size(res), pdev->name)) { | 324 | info->rtc_base = devm_request_and_ioremap(&pdev->dev, res); |
325 | dev_err(&pdev->dev, | 325 | if (!info->rtc_base) { |
326 | "Unable to request mem region for device.\n"); | 326 | dev_err(&pdev->dev, "Unable to request mem region and grab IOs for device.\n"); |
327 | ret = -EBUSY; | 327 | return -EBUSY; |
328 | goto err_free_info; | ||
329 | } | 328 | } |
330 | 329 | ||
331 | info->tegra_rtc_irq = platform_get_irq(pdev, 0); | 330 | info->tegra_rtc_irq = platform_get_irq(pdev, 0); |
332 | if (info->tegra_rtc_irq <= 0) { | 331 | if (info->tegra_rtc_irq <= 0) |
333 | ret = -EBUSY; | 332 | return -EBUSY; |
334 | goto err_release_mem_region; | ||
335 | } | ||
336 | |||
337 | info->rtc_base = ioremap_nocache(res->start, resource_size(res)); | ||
338 | if (!info->rtc_base) { | ||
339 | dev_err(&pdev->dev, "Unable to grab IOs for device.\n"); | ||
340 | ret = -EBUSY; | ||
341 | goto err_release_mem_region; | ||
342 | } | ||
343 | 333 | ||
344 | /* set context info. */ | 334 | /* set context info. */ |
345 | info->pdev = pdev; | 335 | info->pdev = pdev; |
@@ -362,11 +352,12 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) | |||
362 | dev_err(&pdev->dev, | 352 | dev_err(&pdev->dev, |
363 | "Unable to register device (err=%d).\n", | 353 | "Unable to register device (err=%d).\n", |
364 | ret); | 354 | ret); |
365 | goto err_iounmap; | 355 | return ret; |
366 | } | 356 | } |
367 | 357 | ||
368 | ret = request_irq(info->tegra_rtc_irq, tegra_rtc_irq_handler, | 358 | ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq, |
369 | IRQF_TRIGGER_HIGH, "rtc alarm", &pdev->dev); | 359 | tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH, |
360 | "rtc alarm", &pdev->dev); | ||
370 | if (ret) { | 361 | if (ret) { |
371 | dev_err(&pdev->dev, | 362 | dev_err(&pdev->dev, |
372 | "Unable to request interrupt for device (err=%d).\n", | 363 | "Unable to request interrupt for device (err=%d).\n", |
@@ -380,12 +371,6 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev) | |||
380 | 371 | ||
381 | err_dev_unreg: | 372 | err_dev_unreg: |
382 | rtc_device_unregister(info->rtc_dev); | 373 | rtc_device_unregister(info->rtc_dev); |
383 | err_iounmap: | ||
384 | iounmap(info->rtc_base); | ||
385 | err_release_mem_region: | ||
386 | release_mem_region(res->start, resource_size(res)); | ||
387 | err_free_info: | ||
388 | kfree(info); | ||
389 | 374 | ||
390 | return ret; | 375 | return ret; |
391 | } | 376 | } |
@@ -393,17 +378,8 @@ err_free_info: | |||
393 | static int __devexit tegra_rtc_remove(struct platform_device *pdev) | 378 | static int __devexit tegra_rtc_remove(struct platform_device *pdev) |
394 | { | 379 | { |
395 | struct tegra_rtc_info *info = platform_get_drvdata(pdev); | 380 | struct tegra_rtc_info *info = platform_get_drvdata(pdev); |
396 | struct resource *res; | ||
397 | |||
398 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
399 | if (!res) | ||
400 | return -EBUSY; | ||
401 | 381 | ||
402 | free_irq(info->tegra_rtc_irq, &pdev->dev); | ||
403 | rtc_device_unregister(info->rtc_dev); | 382 | rtc_device_unregister(info->rtc_dev); |
404 | iounmap(info->rtc_base); | ||
405 | release_mem_region(res->start, resource_size(res)); | ||
406 | kfree(info); | ||
407 | 383 | ||
408 | platform_set_drvdata(pdev, NULL); | 384 | platform_set_drvdata(pdev, NULL); |
409 | 385 | ||