Skip to content

Commit

Permalink
watchdog: Convert release_resource to release_region/release_mem_region
Browse files Browse the repository at this point in the history
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: Julia Lawall <julia@diku.dk>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Cc: stable <stable@kernel.org>
  • Loading branch information
Julia Lawall authored and Wim Van Sebroeck committed Mar 29, 2011
1 parent f72401e commit f712eac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 39 deletions.
22 changes: 10 additions & 12 deletions drivers/watchdog/davinci_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ static struct miscdevice davinci_wdt_miscdev = {
static int __devinit davinci_wdt_probe(struct platform_device *pdev)
{
int ret = 0, size;
struct resource *res;
struct device *dev = &pdev->dev;

wdt_clk = clk_get(dev, NULL);
Expand All @@ -216,31 +215,31 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev)

dev_info(dev, "heartbeat %d sec\n", heartbeat);

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (wdt_mem == NULL) {
dev_err(dev, "failed to get memory region resource\n");
return -ENOENT;
}

size = resource_size(res);
wdt_mem = request_mem_region(res->start, size, pdev->name);

if (wdt_mem == NULL) {
size = resource_size(wdt_mem);
if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
dev_err(dev, "failed to get memory region\n");
return -ENOENT;
}

wdt_base = ioremap(res->start, size);
wdt_base = ioremap(wdt_mem->start, size);
if (!wdt_base) {
dev_err(dev, "failed to map memory region\n");
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
return -ENOMEM;
}

ret = misc_register(&davinci_wdt_miscdev);
if (ret < 0) {
dev_err(dev, "cannot register misc device\n");
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
} else {
set_bit(WDT_DEVICE_INITED, &wdt_status);
}
Expand All @@ -253,8 +252,7 @@ static int __devexit davinci_wdt_remove(struct platform_device *pdev)
{
misc_deregister(&davinci_wdt_miscdev);
if (wdt_mem) {
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, resource_size(wdt_mem));
wdt_mem = NULL;
}

Expand Down
20 changes: 8 additions & 12 deletions drivers/watchdog/max63xx_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
{
int ret = 0;
int size;
struct resource *res;
struct device *dev = &pdev->dev;
struct max63xx_timeout *table;

Expand All @@ -294,21 +293,19 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)

max63xx_pdev = pdev;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (wdt_mem == NULL) {
dev_err(dev, "failed to get memory region resource\n");
return -ENOENT;
}

size = resource_size(res);
wdt_mem = request_mem_region(res->start, size, pdev->name);

if (wdt_mem == NULL) {
size = resource_size(wdt_mem);
if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
dev_err(dev, "failed to get memory region\n");
return -ENOENT;
}

wdt_base = ioremap(res->start, size);
wdt_base = ioremap(wdt_mem->start, size);
if (!wdt_base) {
dev_err(dev, "failed to map memory region\n");
ret = -ENOMEM;
Expand All @@ -326,8 +323,8 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
out_unmap:
iounmap(wdt_base);
out_request:
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;

return ret;
}
Expand All @@ -336,8 +333,7 @@ static int __devexit max63xx_wdt_remove(struct platform_device *pdev)
{
misc_deregister(&max63xx_wdt_miscdev);
if (wdt_mem) {
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, resource_size(wdt_mem));
wdt_mem = NULL;
}

Expand Down
28 changes: 13 additions & 15 deletions drivers/watchdog/pnx4008_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,50 +254,49 @@ static struct miscdevice pnx4008_wdt_miscdev = {
static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)
{
int ret = 0, size;
struct resource *res;

if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
heartbeat = DEFAULT_HEARTBEAT;

printk(KERN_INFO MODULE_NAME
"PNX4008 Watchdog Timer: heartbeat %d sec\n", heartbeat);

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (wdt_mem == NULL) {
printk(KERN_INFO MODULE_NAME
"failed to get memory region resouce\n");
return -ENOENT;
}

size = resource_size(res);
wdt_mem = request_mem_region(res->start, size, pdev->name);
size = resource_size(wdt_mem);

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");
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);
if (IS_ERR(wdt_clk)) {
ret = PTR_ERR(wdt_clk);
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
goto out;
}

ret = clk_enable(wdt_clk);
if (ret) {
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
clk_put(wdt_clk);
goto out;
}

ret = misc_register(&pnx4008_wdt_miscdev);
if (ret < 0) {
printk(KERN_ERR MODULE_NAME "cannot register misc device\n");
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
clk_disable(wdt_clk);
clk_put(wdt_clk);
} else {
Expand All @@ -320,8 +319,7 @@ static int __devexit pnx4008_wdt_remove(struct platform_device *pdev)
clk_put(wdt_clk);

if (wdt_mem) {
release_resource(wdt_mem);
kfree(wdt_mem);
release_mem_region(wdt_mem->start, resource_size(wdt_mem));
wdt_mem = NULL;
}
return 0;
Expand Down

0 comments on commit f712eac

Please sign in to comment.