Commit f712eacf authored by Julia Lawall's avatar Julia Lawall Committed by Wim Van Sebroeck

watchdog: Convert release_resource to release_region/release_mem_region

Request_mem_region should be used with release_mem_region, not
release_resource.

In pnx4008_wdt.c, a missing clk_put is added as well.

The semantic match that finds the first problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,E;
@@
*x = request_mem_region(...)
... when != release_mem_region(x)
    when != x = E
* release_resource(x);
// </smpl>
Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
Cc: stable <stable@kernel.org>
parent f72401e9
...@@ -202,7 +202,6 @@ static struct miscdevice davinci_wdt_miscdev = { ...@@ -202,7 +202,6 @@ static struct miscdevice davinci_wdt_miscdev = {
static int __devinit davinci_wdt_probe(struct platform_device *pdev) static int __devinit davinci_wdt_probe(struct platform_device *pdev)
{ {
int ret = 0, size; int ret = 0, size;
struct resource *res;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
wdt_clk = clk_get(dev, NULL); wdt_clk = clk_get(dev, NULL);
...@@ -216,31 +215,31 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev) ...@@ -216,31 +215,31 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev)
dev_info(dev, "heartbeat %d sec\n", heartbeat); dev_info(dev, "heartbeat %d sec\n", heartbeat);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) { if (wdt_mem == NULL) {
dev_err(dev, "failed to get memory region resource\n"); dev_err(dev, "failed to get memory region resource\n");
return -ENOENT; return -ENOENT;
} }
size = resource_size(res); size = resource_size(wdt_mem);
wdt_mem = request_mem_region(res->start, size, pdev->name); if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
if (wdt_mem == NULL) {
dev_err(dev, "failed to get memory region\n"); dev_err(dev, "failed to get memory region\n");
return -ENOENT; return -ENOENT;
} }
wdt_base = ioremap(res->start, size); wdt_base = ioremap(wdt_mem->start, size);
if (!wdt_base) { if (!wdt_base) {
dev_err(dev, "failed to map memory region\n"); dev_err(dev, "failed to map memory region\n");
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
return -ENOMEM; return -ENOMEM;
} }
ret = misc_register(&davinci_wdt_miscdev); ret = misc_register(&davinci_wdt_miscdev);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "cannot register misc device\n"); dev_err(dev, "cannot register misc device\n");
release_resource(wdt_mem); release_mem_region(wdt_mem->start, size);
kfree(wdt_mem); wdt_mem = NULL;
} else { } else {
set_bit(WDT_DEVICE_INITED, &wdt_status); set_bit(WDT_DEVICE_INITED, &wdt_status);
} }
...@@ -253,8 +252,7 @@ static int __devexit davinci_wdt_remove(struct platform_device *pdev) ...@@ -253,8 +252,7 @@ static int __devexit davinci_wdt_remove(struct platform_device *pdev)
{ {
misc_deregister(&davinci_wdt_miscdev); misc_deregister(&davinci_wdt_miscdev);
if (wdt_mem) { if (wdt_mem) {
release_resource(wdt_mem); release_mem_region(wdt_mem->start, resource_size(wdt_mem));
kfree(wdt_mem);
wdt_mem = NULL; wdt_mem = NULL;
} }
......
...@@ -270,7 +270,6 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev) ...@@ -270,7 +270,6 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
{ {
int ret = 0; int ret = 0;
int size; int size;
struct resource *res;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct max63xx_timeout *table; struct max63xx_timeout *table;
...@@ -294,21 +293,19 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev) ...@@ -294,21 +293,19 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
max63xx_pdev = pdev; max63xx_pdev = pdev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) { if (wdt_mem == NULL) {
dev_err(dev, "failed to get memory region resource\n"); dev_err(dev, "failed to get memory region resource\n");
return -ENOENT; return -ENOENT;
} }
size = resource_size(res); size = resource_size(wdt_mem);
wdt_mem = request_mem_region(res->start, size, pdev->name); if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
if (wdt_mem == NULL) {
dev_err(dev, "failed to get memory region\n"); dev_err(dev, "failed to get memory region\n");
return -ENOENT; return -ENOENT;
} }
wdt_base = ioremap(res->start, size); wdt_base = ioremap(wdt_mem->start, size);
if (!wdt_base) { if (!wdt_base) {
dev_err(dev, "failed to map memory region\n"); dev_err(dev, "failed to map memory region\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -326,8 +323,8 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev) ...@@ -326,8 +323,8 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
out_unmap: out_unmap:
iounmap(wdt_base); iounmap(wdt_base);
out_request: out_request:
release_resource(wdt_mem); release_mem_region(wdt_mem->start, size);
kfree(wdt_mem); wdt_mem = NULL;
return ret; return ret;
} }
...@@ -336,8 +333,7 @@ static int __devexit max63xx_wdt_remove(struct platform_device *pdev) ...@@ -336,8 +333,7 @@ static int __devexit max63xx_wdt_remove(struct platform_device *pdev)
{ {
misc_deregister(&max63xx_wdt_miscdev); misc_deregister(&max63xx_wdt_miscdev);
if (wdt_mem) { if (wdt_mem) {
release_resource(wdt_mem); release_mem_region(wdt_mem->start, resource_size(wdt_mem));
kfree(wdt_mem);
wdt_mem = NULL; wdt_mem = NULL;
} }
......
...@@ -254,7 +254,6 @@ static struct miscdevice pnx4008_wdt_miscdev = { ...@@ -254,7 +254,6 @@ static struct miscdevice pnx4008_wdt_miscdev = {
static int __devinit pnx4008_wdt_probe(struct platform_device *pdev) static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)
{ {
int ret = 0, size; int ret = 0, size;
struct resource *res;
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT) if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
heartbeat = DEFAULT_HEARTBEAT; heartbeat = DEFAULT_HEARTBEAT;
...@@ -262,42 +261,42 @@ static int __devinit pnx4008_wdt_probe(struct platform_device *pdev) ...@@ -262,42 +261,42 @@ static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)
printk(KERN_INFO MODULE_NAME printk(KERN_INFO MODULE_NAME
"PNX4008 Watchdog Timer: heartbeat %d sec\n", heartbeat); "PNX4008 Watchdog Timer: heartbeat %d sec\n", heartbeat);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) { if (wdt_mem == NULL) {
printk(KERN_INFO MODULE_NAME printk(KERN_INFO MODULE_NAME
"failed to get memory region resouce\n"); "failed to get memory region resouce\n");
return -ENOENT; return -ENOENT;
} }
size = resource_size(res); size = resource_size(wdt_mem);
wdt_mem = request_mem_region(res->start, size, pdev->name);
if (wdt_mem == NULL) { if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
printk(KERN_INFO MODULE_NAME "failed to get memory region\n"); printk(KERN_INFO MODULE_NAME "failed to get memory region\n");
return -ENOENT; return -ENOENT;
} }
wdt_base = (void __iomem *)IO_ADDRESS(res->start); wdt_base = (void __iomem *)IO_ADDRESS(wdt_mem->start);
wdt_clk = clk_get(&pdev->dev, NULL); wdt_clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(wdt_clk)) { if (IS_ERR(wdt_clk)) {
ret = PTR_ERR(wdt_clk); ret = PTR_ERR(wdt_clk);
release_resource(wdt_mem); release_mem_region(wdt_mem->start, size);
kfree(wdt_mem); wdt_mem = NULL;
goto out; goto out;
} }
ret = clk_enable(wdt_clk); ret = clk_enable(wdt_clk);
if (ret) { if (ret) {
release_resource(wdt_mem); release_mem_region(wdt_mem->start, size);
kfree(wdt_mem); wdt_mem = NULL;
clk_put(wdt_clk);
goto out; goto out;
} }
ret = misc_register(&pnx4008_wdt_miscdev); ret = misc_register(&pnx4008_wdt_miscdev);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR MODULE_NAME "cannot register misc device\n"); printk(KERN_ERR MODULE_NAME "cannot register misc device\n");
release_resource(wdt_mem); release_mem_region(wdt_mem->start, size);
kfree(wdt_mem); wdt_mem = NULL;
clk_disable(wdt_clk); clk_disable(wdt_clk);
clk_put(wdt_clk); clk_put(wdt_clk);
} else { } else {
...@@ -320,8 +319,7 @@ static int __devexit pnx4008_wdt_remove(struct platform_device *pdev) ...@@ -320,8 +319,7 @@ static int __devexit pnx4008_wdt_remove(struct platform_device *pdev)
clk_put(wdt_clk); clk_put(wdt_clk);
if (wdt_mem) { if (wdt_mem) {
release_resource(wdt_mem); release_mem_region(wdt_mem->start, resource_size(wdt_mem));
kfree(wdt_mem);
wdt_mem = NULL; wdt_mem = NULL;
} }
return 0; return 0;
......
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