mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-18 06:15:12 +00:00
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>
This commit is contained in:
parent
aa065770f5
commit
75f5a536c0
@ -338,43 +338,37 @@ static int __devinit mpcore_wdt_probe(struct platform_device *pdev)
|
|||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!res) {
|
if (!res)
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
wdt = kzalloc(sizeof(struct mpcore_wdt), GFP_KERNEL);
|
wdt = devm_kzalloc(&pdev->dev, sizeof(struct mpcore_wdt), GFP_KERNEL);
|
||||||
if (!wdt) {
|
if (!wdt)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
wdt->dev = &pdev->dev;
|
wdt->dev = &pdev->dev;
|
||||||
wdt->irq = platform_get_irq(pdev, 0);
|
wdt->irq = platform_get_irq(pdev, 0);
|
||||||
if (wdt->irq < 0) {
|
if (wdt->irq < 0)
|
||||||
ret = -ENXIO;
|
return -ENXIO;
|
||||||
goto err_free;
|
|
||||||
}
|
ret = devm_request_irq(wdt->dev, wdt->irq, mpcore_wdt_fire, 0,
|
||||||
wdt->base = ioremap(res->start, resource_size(res));
|
"mpcore_wdt", wdt);
|
||||||
if (!wdt->base) {
|
if (ret) {
|
||||||
ret = -ENOMEM;
|
dev_printk(KERN_ERR, wdt->dev,
|
||||||
goto err_free;
|
"cannot register IRQ%d for watchdog\n", wdt->irq);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wdt->base = devm_ioremap(wdt->dev, res->start, resource_size(res));
|
||||||
|
if (!wdt->base)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
mpcore_wdt_miscdev.parent = &pdev->dev;
|
mpcore_wdt_miscdev.parent = &pdev->dev;
|
||||||
ret = misc_register(&mpcore_wdt_miscdev);
|
ret = misc_register(&mpcore_wdt_miscdev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_printk(KERN_ERR, wdt->dev,
|
dev_printk(KERN_ERR, wdt->dev,
|
||||||
"cannot register miscdev on minor=%d (err=%d)\n",
|
"cannot register miscdev on minor=%d (err=%d)\n",
|
||||||
WATCHDOG_MINOR, ret);
|
WATCHDOG_MINOR, ret);
|
||||||
goto err_misc;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
ret = request_irq(wdt->irq, mpcore_wdt_fire, 0, "mpcore_wdt", wdt);
|
|
||||||
if (ret) {
|
|
||||||
dev_printk(KERN_ERR, wdt->dev,
|
|
||||||
"cannot register IRQ%d for watchdog\n", wdt->irq);
|
|
||||||
goto err_irq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mpcore_wdt_stop(wdt);
|
mpcore_wdt_stop(wdt);
|
||||||
@ -382,30 +376,16 @@ static int __devinit mpcore_wdt_probe(struct platform_device *pdev)
|
|||||||
mpcore_wdt_pdev = pdev;
|
mpcore_wdt_pdev = pdev;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_irq:
|
|
||||||
misc_deregister(&mpcore_wdt_miscdev);
|
|
||||||
err_misc:
|
|
||||||
iounmap(wdt->base);
|
|
||||||
err_free:
|
|
||||||
kfree(wdt);
|
|
||||||
err_out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __devexit mpcore_wdt_remove(struct platform_device *pdev)
|
static int __devexit mpcore_wdt_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct mpcore_wdt *wdt = platform_get_drvdata(pdev);
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
|
|
||||||
misc_deregister(&mpcore_wdt_miscdev);
|
misc_deregister(&mpcore_wdt_miscdev);
|
||||||
|
|
||||||
mpcore_wdt_pdev = NULL;
|
mpcore_wdt_pdev = NULL;
|
||||||
|
|
||||||
free_irq(wdt->irq, wdt);
|
|
||||||
iounmap(wdt->base);
|
|
||||||
kfree(wdt);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user