rtc: rtc-spear: use devm_*() routines
Free the rtc-spear driver from tension of freeing resources :) devm_* derivatives of multiple routines are used while allocating resources, which would be freed automatically by kernel. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Cc: Deepak Sikri <deepak.sikri@st.com> 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>
This commit is contained in:
parent
942bfb3ed0
commit
bdaa2c63b0
|
@ -363,34 +363,41 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
|
||||||
dev_err(&pdev->dev, "no resource defined\n");
|
dev_err(&pdev->dev, "no resource defined\n");
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
|
|
||||||
dev_err(&pdev->dev, "rtc region already claimed\n");
|
|
||||||
return -EBUSY;
|
|
||||||
}
|
|
||||||
|
|
||||||
config = kzalloc(sizeof(*config), GFP_KERNEL);
|
config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
dev_err(&pdev->dev, "out of memory\n");
|
dev_err(&pdev->dev, "out of memory\n");
|
||||||
status = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_release_region;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config->clk = clk_get(&pdev->dev, NULL);
|
/* alarm irqs */
|
||||||
if (IS_ERR(config->clk)) {
|
irq = platform_get_irq(pdev, 0);
|
||||||
status = PTR_ERR(config->clk);
|
if (irq < 0) {
|
||||||
goto err_kfree;
|
dev_err(&pdev->dev, "no update irq?\n");
|
||||||
|
return irq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status = devm_request_irq(&pdev->dev, irq, spear_rtc_irq, 0, pdev->name,
|
||||||
|
config);
|
||||||
|
if (status) {
|
||||||
|
dev_err(&pdev->dev, "Alarm interrupt IRQ%d already claimed\n",
|
||||||
|
irq);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
config->ioaddr = devm_request_and_ioremap(&pdev->dev, res);
|
||||||
|
if (!config->ioaddr) {
|
||||||
|
dev_err(&pdev->dev, "request-ioremap fail\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
config->clk = devm_clk_get(&pdev->dev, NULL);
|
||||||
|
if (IS_ERR(config->clk))
|
||||||
|
return PTR_ERR(config->clk);
|
||||||
|
|
||||||
status = clk_enable(config->clk);
|
status = clk_enable(config->clk);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
goto err_clk_put;
|
return status;
|
||||||
|
|
||||||
config->ioaddr = ioremap(res->start, resource_size(res));
|
|
||||||
if (!config->ioaddr) {
|
|
||||||
dev_err(&pdev->dev, "ioremap fail\n");
|
|
||||||
status = -ENOMEM;
|
|
||||||
goto err_disable_clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_init(&config->lock);
|
spin_lock_init(&config->lock);
|
||||||
platform_set_drvdata(pdev, config);
|
platform_set_drvdata(pdev, config);
|
||||||
|
@ -401,22 +408,7 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
|
||||||
dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
|
dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
|
||||||
PTR_ERR(config->rtc));
|
PTR_ERR(config->rtc));
|
||||||
status = PTR_ERR(config->rtc);
|
status = PTR_ERR(config->rtc);
|
||||||
goto err_iounmap;
|
goto err_disable_clock;
|
||||||
}
|
|
||||||
|
|
||||||
/* alarm irqs */
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
|
||||||
if (irq < 0) {
|
|
||||||
dev_err(&pdev->dev, "no update irq?\n");
|
|
||||||
status = irq;
|
|
||||||
goto err_clear_platdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = request_irq(irq, spear_rtc_irq, 0, pdev->name, config);
|
|
||||||
if (status) {
|
|
||||||
dev_err(&pdev->dev, "Alarm interrupt IRQ%d already \
|
|
||||||
claimed\n", irq);
|
|
||||||
goto err_clear_platdata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!device_can_wakeup(&pdev->dev))
|
if (!device_can_wakeup(&pdev->dev))
|
||||||
|
@ -424,19 +416,9 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_clear_platdata:
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
|
||||||
rtc_device_unregister(config->rtc);
|
|
||||||
err_iounmap:
|
|
||||||
iounmap(config->ioaddr);
|
|
||||||
err_disable_clock:
|
err_disable_clock:
|
||||||
|
platform_set_drvdata(pdev, NULL);
|
||||||
clk_disable(config->clk);
|
clk_disable(config->clk);
|
||||||
err_clk_put:
|
|
||||||
clk_put(config->clk);
|
|
||||||
err_kfree:
|
|
||||||
kfree(config);
|
|
||||||
err_release_region:
|
|
||||||
release_mem_region(res->start, resource_size(res));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -444,24 +426,11 @@ err_release_region:
|
||||||
static int __devexit spear_rtc_remove(struct platform_device *pdev)
|
static int __devexit spear_rtc_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct spear_rtc_config *config = platform_get_drvdata(pdev);
|
struct spear_rtc_config *config = platform_get_drvdata(pdev);
|
||||||
int irq;
|
|
||||||
struct resource *res;
|
|
||||||
|
|
||||||
/* leave rtc running, but disable irqs */
|
|
||||||
spear_rtc_disable_interrupt(config);
|
|
||||||
device_init_wakeup(&pdev->dev, 0);
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
|
||||||
if (irq)
|
|
||||||
free_irq(irq, pdev);
|
|
||||||
clk_disable(config->clk);
|
|
||||||
clk_put(config->clk);
|
|
||||||
iounmap(config->ioaddr);
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
||||||
if (res)
|
|
||||||
release_mem_region(res->start, resource_size(res));
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
|
||||||
rtc_device_unregister(config->rtc);
|
rtc_device_unregister(config->rtc);
|
||||||
kfree(config);
|
spear_rtc_disable_interrupt(config);
|
||||||
|
clk_disable(config->clk);
|
||||||
|
device_init_wakeup(&pdev->dev, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue