Commit 30a61fff3a2b19506c66ea81fecb6a7747af3d47

Authored by Julia Lawall
Committed by Linus Torvalds
1 parent b484625172

edac: fix resource size calculation

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: Doug Thompson <dougthompson@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 14 additions and 14 deletions Side-by-side Diff

drivers/edac/cpc925_edac.c
... ... @@ -885,14 +885,14 @@
885 885  
886 886 if (!devm_request_mem_region(&pdev->dev,
887 887 r->start,
888   - r->end - r->start + 1,
  888 + resource_size(r),
889 889 pdev->name)) {
890 890 cpc925_printk(KERN_ERR, "Unable to request mem region\n");
891 891 res = -EBUSY;
892 892 goto err1;
893 893 }
894 894  
895   - vbase = devm_ioremap(&pdev->dev, r->start, r->end - r->start + 1);
  895 + vbase = devm_ioremap(&pdev->dev, r->start, resource_size(r));
896 896 if (!vbase) {
897 897 cpc925_printk(KERN_ERR, "Unable to ioremap device\n");
898 898 res = -ENOMEM;
... ... @@ -953,7 +953,7 @@
953 953 cpc925_mc_exit(mci);
954 954 edac_mc_free(mci);
955 955 err2:
956   - devm_release_mem_region(&pdev->dev, r->start, r->end-r->start+1);
  956 + devm_release_mem_region(&pdev->dev, r->start, resource_size(r));
957 957 err1:
958 958 devres_release_group(&pdev->dev, cpc925_probe);
959 959 out:
drivers/edac/mv64x60_edac.c
... ... @@ -90,7 +90,7 @@
90 90 return -ENOENT;
91 91 }
92 92  
93   - pci_serr = ioremap(r->start, r->end - r->start + 1);
  93 + pci_serr = ioremap(r->start, resource_size(r));
94 94 if (!pci_serr)
95 95 return -ENOMEM;
96 96  
... ... @@ -140,7 +140,7 @@
140 140  
141 141 if (!devm_request_mem_region(&pdev->dev,
142 142 r->start,
143   - r->end - r->start + 1,
  143 + resource_size(r),
144 144 pdata->name)) {
145 145 printk(KERN_ERR "%s: Error while requesting mem region\n",
146 146 __func__);
... ... @@ -150,7 +150,7 @@
150 150  
151 151 pdata->pci_vbase = devm_ioremap(&pdev->dev,
152 152 r->start,
153   - r->end - r->start + 1);
  153 + resource_size(r));
154 154 if (!pdata->pci_vbase) {
155 155 printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
156 156 res = -ENOMEM;
... ... @@ -306,7 +306,7 @@
306 306  
307 307 if (!devm_request_mem_region(&pdev->dev,
308 308 r->start,
309   - r->end - r->start + 1,
  309 + resource_size(r),
310 310 pdata->name)) {
311 311 printk(KERN_ERR "%s: Error while request mem region\n",
312 312 __func__);
... ... @@ -316,7 +316,7 @@
316 316  
317 317 pdata->sram_vbase = devm_ioremap(&pdev->dev,
318 318 r->start,
319   - r->end - r->start + 1);
  319 + resource_size(r));
320 320 if (!pdata->sram_vbase) {
321 321 printk(KERN_ERR "%s: Unable to setup SRAM err regs\n",
322 322 __func__);
... ... @@ -474,7 +474,7 @@
474 474  
475 475 if (!devm_request_mem_region(&pdev->dev,
476 476 r->start,
477   - r->end - r->start + 1,
  477 + resource_size(r),
478 478 pdata->name)) {
479 479 printk(KERN_ERR "%s: Error while requesting mem region\n",
480 480 __func__);
... ... @@ -484,7 +484,7 @@
484 484  
485 485 pdata->cpu_vbase[0] = devm_ioremap(&pdev->dev,
486 486 r->start,
487   - r->end - r->start + 1);
  487 + resource_size(r));
488 488 if (!pdata->cpu_vbase[0]) {
489 489 printk(KERN_ERR "%s: Unable to setup CPU err regs\n", __func__);
490 490 res = -ENOMEM;
... ... @@ -501,7 +501,7 @@
501 501  
502 502 if (!devm_request_mem_region(&pdev->dev,
503 503 r->start,
504   - r->end - r->start + 1,
  504 + resource_size(r),
505 505 pdata->name)) {
506 506 printk(KERN_ERR "%s: Error while requesting mem region\n",
507 507 __func__);
... ... @@ -511,7 +511,7 @@
511 511  
512 512 pdata->cpu_vbase[1] = devm_ioremap(&pdev->dev,
513 513 r->start,
514   - r->end - r->start + 1);
  514 + resource_size(r));
515 515 if (!pdata->cpu_vbase[1]) {
516 516 printk(KERN_ERR "%s: Unable to setup CPU err regs\n", __func__);
517 517 res = -ENOMEM;
... ... @@ -726,7 +726,7 @@
726 726  
727 727 if (!devm_request_mem_region(&pdev->dev,
728 728 r->start,
729   - r->end - r->start + 1,
  729 + resource_size(r),
730 730 pdata->name)) {
731 731 printk(KERN_ERR "%s: Error while requesting mem region\n",
732 732 __func__);
... ... @@ -736,7 +736,7 @@
736 736  
737 737 pdata->mc_vbase = devm_ioremap(&pdev->dev,
738 738 r->start,
739   - r->end - r->start + 1);
  739 + resource_size(r));
740 740 if (!pdata->mc_vbase) {
741 741 printk(KERN_ERR "%s: Unable to setup MC err regs\n", __func__);
742 742 res = -ENOMEM;