Commit 86855b0c authored by Julia Lawall's avatar Julia Lawall Committed by Jean Delvare

hwmon: 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 avatarJean Delvare <khali@linux-fr.org>
parent 6055fae8
...@@ -435,7 +435,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev) ...@@ -435,7 +435,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
/* This will need to be revisited when we add support for /* This will need to be revisited when we add support for
temperature and voltage monitoring. */ temperature and voltage monitoring. */
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) { if (!request_region(res->start, resource_size(res), DRVNAME)) {
err = -EBUSY; err = -EBUSY;
dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n", dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n",
(unsigned long)res->start, (unsigned long)res->end); (unsigned long)res->start, (unsigned long)res->end);
...@@ -475,7 +475,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev) ...@@ -475,7 +475,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
} }
exit_release_region: exit_release_region:
release_region(res->start, res->end - res->start + 1); release_region(res->start, resource_size(res));
exit_kfree: exit_kfree:
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
kfree(data); kfree(data);
...@@ -500,7 +500,7 @@ static int __devexit pc87427_remove(struct platform_device *pdev) ...@@ -500,7 +500,7 @@ static int __devexit pc87427_remove(struct platform_device *pdev)
kfree(data); kfree(data);
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
release_region(res->start, res->end - res->start + 1); release_region(res->start, resource_size(res));
return 0; return 0;
} }
......
...@@ -1136,7 +1136,7 @@ static int __devinit vt1211_probe(struct platform_device *pdev) ...@@ -1136,7 +1136,7 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
} }
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) { if (!request_region(res->start, resource_size(res), DRVNAME)) {
err = -EBUSY; err = -EBUSY;
dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
(unsigned long)res->start, (unsigned long)res->end); (unsigned long)res->start, (unsigned long)res->end);
...@@ -1209,7 +1209,7 @@ static int __devinit vt1211_probe(struct platform_device *pdev) ...@@ -1209,7 +1209,7 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
dev_err(dev, "Sysfs interface creation failed (%d)\n", err); dev_err(dev, "Sysfs interface creation failed (%d)\n", err);
EXIT_DEV_REMOVE_SILENT: EXIT_DEV_REMOVE_SILENT:
vt1211_remove_sysfs(pdev); vt1211_remove_sysfs(pdev);
release_region(res->start, res->end - res->start + 1); release_region(res->start, resource_size(res));
EXIT_KFREE: EXIT_KFREE:
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
kfree(data); kfree(data);
...@@ -1228,7 +1228,7 @@ static int __devexit vt1211_remove(struct platform_device *pdev) ...@@ -1228,7 +1228,7 @@ static int __devexit vt1211_remove(struct platform_device *pdev)
kfree(data); kfree(data);
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
release_region(res->start, res->end - res->start + 1); release_region(res->start, resource_size(res));
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