clocksource: em_sti: Convert to devm_* managed helpers

Replace kzalloc, clk_get, ioremap and request_irq by their managed
counterparts to simplify error paths.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
This commit is contained in:
Laurent Pinchart 2013-07-30 16:24:37 +02:00 committed by Daniel Lezcano
parent cfb6d656d5
commit 1745e696e1
1 changed files with 14 additions and 35 deletions

View File

@ -315,68 +315,47 @@ static int em_sti_probe(struct platform_device *pdev)
{ {
struct em_sti_priv *p; struct em_sti_priv *p;
struct resource *res; struct resource *res;
int irq, ret; int irq;
p = kzalloc(sizeof(*p), GFP_KERNEL); p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
if (p == NULL) { if (p == NULL) {
dev_err(&pdev->dev, "failed to allocate driver data\n"); dev_err(&pdev->dev, "failed to allocate driver data\n");
ret = -ENOMEM; return -ENOMEM;
goto err0;
} }
p->pdev = pdev; p->pdev = pdev;
platform_set_drvdata(pdev, p); platform_set_drvdata(pdev, p);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "failed to get I/O memory\n");
ret = -EINVAL;
goto err0;
}
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
dev_err(&pdev->dev, "failed to get irq\n"); dev_err(&pdev->dev, "failed to get irq\n");
ret = -EINVAL; return -EINVAL;
goto err0;
} }
/* map memory, let base point to the STI instance */ /* map memory, let base point to the STI instance */
p->base = ioremap_nocache(res->start, resource_size(res)); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (p->base == NULL) { p->base = devm_ioremap_resource(&pdev->dev, res);
dev_err(&pdev->dev, "failed to remap I/O memory\n"); if (IS_ERR(p->base))
ret = -ENXIO; return PTR_ERR(p->base);
goto err0;
}
/* get hold of clock */ /* get hold of clock */
p->clk = clk_get(&pdev->dev, "sclk"); p->clk = devm_clk_get(&pdev->dev, "sclk");
if (IS_ERR(p->clk)) { if (IS_ERR(p->clk)) {
dev_err(&pdev->dev, "cannot get clock\n"); dev_err(&pdev->dev, "cannot get clock\n");
ret = PTR_ERR(p->clk); return PTR_ERR(p->clk);
goto err1;
} }
if (request_irq(irq, em_sti_interrupt, if (devm_request_irq(&pdev->dev, irq, em_sti_interrupt,
IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING, IRQF_TIMER | IRQF_IRQPOLL | IRQF_NOBALANCING,
dev_name(&pdev->dev), p)) { dev_name(&pdev->dev), p)) {
dev_err(&pdev->dev, "failed to request low IRQ\n"); dev_err(&pdev->dev, "failed to request low IRQ\n");
ret = -ENOENT; return -ENOENT;
goto err2;
} }
raw_spin_lock_init(&p->lock); raw_spin_lock_init(&p->lock);
em_sti_register_clockevent(p); em_sti_register_clockevent(p);
em_sti_register_clocksource(p); em_sti_register_clocksource(p);
return 0; return 0;
err2:
clk_put(p->clk);
err1:
iounmap(p->base);
err0:
kfree(p);
return ret;
} }
static int em_sti_remove(struct platform_device *pdev) static int em_sti_remove(struct platform_device *pdev)