Commit 59330825 authored by Julia Lawall's avatar Julia Lawall Committed by Ben Dooks

i2c: Use resource_size

Use the function resource_size, which reduces the chance of introducing
off-by-one errors in calculating the resource size.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
struct resource *res;
@@

- (res->end - res->start) + 1
+ resource_size(res)
// </smpl>
Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarBen Dooks <ben-linux@fluff.org>
parent 7605fa3b
......@@ -515,7 +515,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
return -ENODEV;
}
ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
ioarea = request_mem_region(mem->start, resource_size(mem),
pdev->name);
if (!ioarea) {
dev_err(&pdev->dev, "I2C region already claimed\n");
......@@ -578,7 +578,7 @@ err_free_mem:
put_device(&pdev->dev);
kfree(dev);
err_release_region:
release_mem_region(mem->start, (mem->end - mem->start) + 1);
release_mem_region(mem->start, resource_size(mem));
return r;
}
......@@ -601,7 +601,7 @@ static int davinci_i2c_remove(struct platform_device *pdev)
kfree(dev);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, (mem->end - mem->start) + 1);
release_mem_region(mem->start, resource_size(mem));
return 0;
}
......
......@@ -806,7 +806,7 @@ omap_i2c_probe(struct platform_device *pdev)
return -ENODEV;
}
ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
ioarea = request_mem_region(mem->start, resource_size(mem),
pdev->name);
if (!ioarea) {
dev_err(&pdev->dev, "I2C region already claimed\n");
......@@ -905,7 +905,7 @@ err_free_mem:
platform_set_drvdata(pdev, NULL);
kfree(dev);
err_release_region:
release_mem_region(mem->start, (mem->end - mem->start) + 1);
release_mem_region(mem->start, resource_size(mem));
return r;
}
......@@ -925,7 +925,7 @@ omap_i2c_remove(struct platform_device *pdev)
iounmap(dev->base);
kfree(dev);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(mem->start, (mem->end - mem->start) + 1);
release_mem_region(mem->start, resource_size(mem));
return 0;
}
......
......@@ -563,7 +563,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
goto err_irq;
}
size = (res->end - res->start) + 1;
size = resource_size(res);
pd->reg = ioremap(res->start, size);
if (pd->reg == NULL) {
......
......@@ -92,7 +92,7 @@ static int simtec_i2c_probe(struct platform_device *dev)
goto err;
}
size = (res->end-res->start)+1;
size = resource_size(res);
pd->ioarea = request_mem_region(res->start, size, dev->name);
if (pd->ioarea == NULL) {
......
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