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: Julia Lawall <julia@diku.dk>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
This commit is contained in:
Julia Lawall 2009-07-05 08:37:50 +02:00 committed by Ben Dooks
parent 7605fa3b0a
commit 593308259b
4 changed files with 8 additions and 8 deletions

View File

@ -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 @@ static int davinci_i2c_probe(struct platform_device *pdev)
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;
}

View File

@ -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 @@ omap_i2c_probe(struct platform_device *pdev)
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;
}

View File

@ -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) {

View File

@ -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) {