This semantic patch replaces explicit computations of vma page count with explicit function call.
Unified · Split
| @@ -0,0 +1,60 @@ | ||
| 1 | +/// | |
| 2 | +/// Use vma_pages function on vma object instead of explicit computation. | |
| 3 | +/// | |
| 4 | +// Confidence: High | |
| 5 | +// Keywords: vma_pages vma | |
| 6 | +// Comment: Based on resource_size.cocci | |
| 7 | + | |
| 8 | +virtual context | |
| 9 | +virtual patch | |
| 10 | +virtual org | |
| 11 | +virtual report | |
| 12 | + | |
| 13 | +//---------------------------------------------------------- | |
| 14 | +// For context mode | |
| 15 | +//---------------------------------------------------------- | |
| 16 | + | |
| 17 | +@r_context depends on context && !patch && !org && !report@ | |
| 18 | +struct vm_area_struct *vma; | |
| 19 | +@@ | |
| 20 | + | |
| 21 | +* (vma->vm_end - vma->vm_start) >> PAGE_SHIFT | |
| 22 | + | |
| 23 | +//---------------------------------------------------------- | |
| 24 | +// For patch mode | |
| 25 | +//---------------------------------------------------------- | |
| 26 | + | |
| 27 | +@r_patch depends on !context && patch && !org && !report@ | |
| 28 | +struct vm_area_struct *vma; | |
| 29 | +@@ | |
| 30 | + | |
| 31 | +- ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) | |
| 32 | ++ vma_pages(vma) | |
| 33 | + | |
| 34 | +//---------------------------------------------------------- | |
| 35 | +// For org mode | |
| 36 | +//---------------------------------------------------------- | |
| 37 | + | |
| 38 | +@r_org depends on !context && !patch && (org || report)@ | |
| 39 | +struct vm_area_struct *vma; | |
| 40 | +position p; | |
| 41 | +@@ | |
| 42 | + | |
| 43 | + (vma->vm_end@p - vma->vm_start) >> PAGE_SHIFT | |
| 44 | + | |
| 45 | +@script:python depends on report@ | |
| 46 | +p << r_org.p; | |
| 47 | +x << r_org.vma; | |
| 48 | +@@ | |
| 49 | + | |
| 50 | +msg="WARNING: Consider using vma_pages helper on %s" % (x) | |
| 51 | +coccilib.report.print_report(p[0], msg) | |
| 52 | + | |
| 53 | +@script:python depends on org@ | |
| 54 | +p << r_org.p; | |
| 55 | +x << r_org.vma; | |
| 56 | +@@ | |
| 57 | + | |
| 58 | +msg="WARNING: Consider using vma_pages helper on %s" % (x) | |
| 59 | +msg_safe=msg.replace("[","@(").replace("]",")") | |
| 60 | +coccilib.org.print_todo(p[0], msg_safe) | |