Commit 74dd9ec6 authored by Tarun Kanti DebBarma's avatar Tarun Kanti DebBarma Committed by Tony Lindgren

ARM: OMAP: dmtimer: use devm_ API and do some cleanup in probe()

Replace the regular kzalloc and ioremap with the devm_ equivalent
to simplify error handling. We don't need kree() any more in
omap_dm_timer_remove().

Also added *dev* pointer to reference pdev->dev which makes the
usage shorter in code.

Cc: Cousson, Benoit <b-cousson@ti.com>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: Kevin Hilman <khilman@ti.com>
Cc: Rajendra Nayak <rnayak@ti.com>
Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
Signed-off-by: default avatarTarun Kanti DebBarma <tarun.kanti@ti.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent ac5b0ea3
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/slab.h> #include <linux/device.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
...@@ -689,49 +689,39 @@ EXPORT_SYMBOL_GPL(omap_dm_timers_active); ...@@ -689,49 +689,39 @@ EXPORT_SYMBOL_GPL(omap_dm_timers_active);
*/ */
static int __devinit omap_dm_timer_probe(struct platform_device *pdev) static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
{ {
int ret;
unsigned long flags; unsigned long flags;
struct omap_dm_timer *timer; struct omap_dm_timer *timer;
struct resource *mem, *irq, *ioarea; struct resource *mem, *irq;
struct device *dev = &pdev->dev;
struct dmtimer_platform_data *pdata = pdev->dev.platform_data; struct dmtimer_platform_data *pdata = pdev->dev.platform_data;
if (!pdata) { if (!pdata) {
dev_err(&pdev->dev, "%s: no platform data.\n", __func__); dev_err(dev, "%s: no platform data.\n", __func__);
return -ENODEV; return -ENODEV;
} }
irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (unlikely(!irq)) { if (unlikely(!irq)) {
dev_err(&pdev->dev, "%s: no IRQ resource.\n", __func__); dev_err(dev, "%s: no IRQ resource.\n", __func__);
return -ENODEV; return -ENODEV;
} }
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (unlikely(!mem)) { if (unlikely(!mem)) {
dev_err(&pdev->dev, "%s: no memory resource.\n", __func__); dev_err(dev, "%s: no memory resource.\n", __func__);
return -ENODEV; return -ENODEV;
} }
ioarea = request_mem_region(mem->start, resource_size(mem), timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
pdev->name);
if (!ioarea) {
dev_err(&pdev->dev, "%s: region already claimed.\n", __func__);
return -EBUSY;
}
timer = kzalloc(sizeof(struct omap_dm_timer), GFP_KERNEL);
if (!timer) { if (!timer) {
dev_err(&pdev->dev, "%s: no memory for omap_dm_timer.\n", dev_err(dev, "%s: memory alloc failed!\n", __func__);
__func__); return -ENOMEM;
ret = -ENOMEM;
goto err_free_ioregion;
} }
timer->io_base = ioremap(mem->start, resource_size(mem)); timer->io_base = devm_request_and_ioremap(dev, mem);
if (!timer->io_base) { if (!timer->io_base) {
dev_err(&pdev->dev, "%s: ioremap failed.\n", __func__); dev_err(dev, "%s: region already claimed.\n", __func__);
ret = -ENOMEM; return -ENOMEM;
goto err_free_mem;
} }
timer->id = pdev->id; timer->id = pdev->id;
...@@ -742,14 +732,14 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev) ...@@ -742,14 +732,14 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
/* Skip pm_runtime_enable for OMAP1 */ /* Skip pm_runtime_enable for OMAP1 */
if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) { if (!(timer->capability & OMAP_TIMER_NEEDS_RESET)) {
pm_runtime_enable(&pdev->dev); pm_runtime_enable(dev);
pm_runtime_irq_safe(&pdev->dev); pm_runtime_irq_safe(dev);
} }
if (!timer->reserved) { if (!timer->reserved) {
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(dev);
__omap_dm_timer_init_regs(timer); __omap_dm_timer_init_regs(timer);
pm_runtime_put(&pdev->dev); pm_runtime_put(dev);
} }
/* add the timer element to the list */ /* add the timer element to the list */
...@@ -757,17 +747,9 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev) ...@@ -757,17 +747,9 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
list_add_tail(&timer->node, &omap_timer_list); list_add_tail(&timer->node, &omap_timer_list);
spin_unlock_irqrestore(&dm_timer_lock, flags); spin_unlock_irqrestore(&dm_timer_lock, flags);
dev_dbg(&pdev->dev, "Device Probed.\n"); dev_dbg(dev, "Device Probed.\n");
return 0; return 0;
err_free_mem:
kfree(timer);
err_free_ioregion:
release_mem_region(mem->start, resource_size(mem));
return ret;
} }
/** /**
...@@ -788,7 +770,6 @@ static int __devexit omap_dm_timer_remove(struct platform_device *pdev) ...@@ -788,7 +770,6 @@ static int __devexit omap_dm_timer_remove(struct platform_device *pdev)
list_for_each_entry(timer, &omap_timer_list, node) list_for_each_entry(timer, &omap_timer_list, node)
if (timer->pdev->id == pdev->id) { if (timer->pdev->id == pdev->id) {
list_del(&timer->node); list_del(&timer->node);
kfree(timer);
ret = 0; ret = 0;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment