Commit 72398e4b authored by Julia Lawall's avatar Julia Lawall Committed by Dmitry Torokhov

Input: use resource_size when allocating resources

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 avatarDmitry Torokhov <dtor@mail.ru>
parent 666cbe34
...@@ -116,7 +116,7 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev) ...@@ -116,7 +116,7 @@ static int __devinit cobalt_buttons_probe(struct platform_device *pdev)
} }
bdev->poll_dev = poll_dev; bdev->poll_dev = poll_dev;
bdev->reg = ioremap(res->start, res->end - res->start + 1); bdev->reg = ioremap(res->start, resource_size(res));
dev_set_drvdata(&pdev->dev, bdev); dev_set_drvdata(&pdev->dev, bdev);
error = input_register_polled_device(poll_dev); error = input_register_polled_device(poll_dev);
......
...@@ -231,7 +231,7 @@ static int __init psif_probe(struct platform_device *pdev) ...@@ -231,7 +231,7 @@ static int __init psif_probe(struct platform_device *pdev)
goto out_free_io; goto out_free_io;
} }
psif->regs = ioremap(regs->start, regs->end - regs->start + 1); psif->regs = ioremap(regs->start, resource_size(regs));
if (!psif->regs) { if (!psif->regs) {
ret = -ENOMEM; ret = -ENOMEM;
dev_dbg(&pdev->dev, "could not map I/O memory\n"); dev_dbg(&pdev->dev, "could not map I/O memory\n");
......
...@@ -204,14 +204,14 @@ static int __devinit atmel_tsadcc_probe(struct platform_device *pdev) ...@@ -204,14 +204,14 @@ static int __devinit atmel_tsadcc_probe(struct platform_device *pdev)
goto err_free_dev; goto err_free_dev;
} }
if (!request_mem_region(res->start, res->end - res->start + 1, if (!request_mem_region(res->start, resource_size(res),
"atmel tsadcc regs")) { "atmel tsadcc regs")) {
dev_err(&pdev->dev, "resources is unavailable.\n"); dev_err(&pdev->dev, "resources is unavailable.\n");
err = -EBUSY; err = -EBUSY;
goto err_free_dev; goto err_free_dev;
} }
tsc_base = ioremap(res->start, res->end - res->start + 1); tsc_base = ioremap(res->start, resource_size(res));
if (!tsc_base) { if (!tsc_base) {
dev_err(&pdev->dev, "failed to map registers.\n"); dev_err(&pdev->dev, "failed to map registers.\n");
err = -ENOMEM; err = -ENOMEM;
...@@ -286,7 +286,7 @@ static int __devinit atmel_tsadcc_probe(struct platform_device *pdev) ...@@ -286,7 +286,7 @@ static int __devinit atmel_tsadcc_probe(struct platform_device *pdev)
err_unmap_regs: err_unmap_regs:
iounmap(tsc_base); iounmap(tsc_base);
err_release_mem: err_release_mem:
release_mem_region(res->start, res->end - res->start + 1); release_mem_region(res->start, resource_size(res));
err_free_dev: err_free_dev:
input_free_device(ts_dev->input); input_free_device(ts_dev->input);
err_free_mem: err_free_mem:
...@@ -305,7 +305,7 @@ static int __devexit atmel_tsadcc_remove(struct platform_device *pdev) ...@@ -305,7 +305,7 @@ static int __devexit atmel_tsadcc_remove(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
iounmap(tsc_base); iounmap(tsc_base);
release_mem_region(res->start, res->end - res->start + 1); release_mem_region(res->start, resource_size(res));
clk_disable(ts_dev->clk); clk_disable(ts_dev->clk);
clk_put(ts_dev->clk); clk_put(ts_dev->clk);
......
...@@ -241,13 +241,13 @@ static int __devinit w90x900ts_probe(struct platform_device *pdev) ...@@ -241,13 +241,13 @@ static int __devinit w90x900ts_probe(struct platform_device *pdev)
goto fail1; goto fail1;
} }
if (!request_mem_region(res->start, res->end - res->start + 1, if (!request_mem_region(res->start, resource_size(res),
pdev->name)) { pdev->name)) {
err = -EBUSY; err = -EBUSY;
goto fail1; goto fail1;
} }
w90p910_ts->ts_reg = ioremap(res->start, res->end - res->start + 1); w90p910_ts->ts_reg = ioremap(res->start, resource_size(res));
if (!w90p910_ts->ts_reg) { if (!w90p910_ts->ts_reg) {
err = -ENOMEM; err = -ENOMEM;
goto fail2; goto fail2;
...@@ -296,7 +296,7 @@ static int __devinit w90x900ts_probe(struct platform_device *pdev) ...@@ -296,7 +296,7 @@ static int __devinit w90x900ts_probe(struct platform_device *pdev)
fail4: free_irq(w90p910_ts->irq_num, w90p910_ts); fail4: free_irq(w90p910_ts->irq_num, w90p910_ts);
fail3: iounmap(w90p910_ts->ts_reg); fail3: iounmap(w90p910_ts->ts_reg);
fail2: release_mem_region(res->start, res->end - res->start + 1); fail2: release_mem_region(res->start, resource_size(res));
fail1: input_free_device(input_dev); fail1: input_free_device(input_dev);
kfree(w90p910_ts); kfree(w90p910_ts);
return err; return err;
...@@ -312,7 +312,7 @@ static int __devexit w90x900ts_remove(struct platform_device *pdev) ...@@ -312,7 +312,7 @@ static int __devexit w90x900ts_remove(struct platform_device *pdev)
iounmap(w90p910_ts->ts_reg); iounmap(w90p910_ts->ts_reg);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, res->end - res->start + 1); release_mem_region(res->start, resource_size(res));
input_unregister_device(w90p910_ts->input); input_unregister_device(w90p910_ts->input);
kfree(w90p910_ts); kfree(w90p910_ts);
......
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