xref: /linux/scripts/coccinelle/api/vma_pages.cocci (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
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
8virtual context
9virtual patch
10virtual org
11virtual report
12
13//----------------------------------------------------------
14//  For context mode
15//----------------------------------------------------------
16
17@r_context depends on context && !patch && !org && !report@
18struct 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@
28struct 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)@
39struct vm_area_struct *vma;
40position p;
41@@
42
43  (vma->vm_end@p - vma->vm_start) >> PAGE_SHIFT
44
45@script:python depends on report@
46p << r_org.p;
47x << r_org.vma;
48@@
49
50msg="WARNING: Consider using vma_pages helper on %s" % (x)
51coccilib.report.print_report(p[0], msg)
52
53@script:python depends on org@
54p << r_org.p;
55x << r_org.vma;
56@@
57
58msg="WARNING: Consider using vma_pages helper on %s" % (x)
59msg_safe=msg.replace("[","@(").replace("]",")")
60coccilib.org.print_todo(p[0], msg_safe)
61