vma_pages.cocci 1.5 KB

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