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