vma_pages.cocci 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. virtual context
  8. virtual patch
  9. virtual org
  10. virtual report
  11. //----------------------------------------------------------
  12. // For context mode
  13. //----------------------------------------------------------
  14. @r_context depends on context && !patch && !org && !report@
  15. struct vm_area_struct *vma;
  16. @@
  17. * (vma->vm_end - vma->vm_start) >> PAGE_SHIFT
  18. //----------------------------------------------------------
  19. // For patch mode
  20. //----------------------------------------------------------
  21. @r_patch depends on !context && patch && !org && !report@
  22. struct vm_area_struct *vma;
  23. @@
  24. - ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT)
  25. + vma_pages(vma)
  26. //----------------------------------------------------------
  27. // For org mode
  28. //----------------------------------------------------------
  29. @r_org depends on !context && !patch && (org || report)@
  30. struct vm_area_struct *vma;
  31. position p;
  32. @@
  33. (vma->vm_end@p - vma->vm_start) >> PAGE_SHIFT
  34. @script:python depends on report@
  35. p << r_org.p;
  36. x << r_org.vma;
  37. @@
  38. msg="WARNING: Consider using vma_pages helper on %s" % (x)
  39. coccilib.report.print_report(p[0], msg)
  40. @script:python depends on org@
  41. p << r_org.p;
  42. x << r_org.vma;
  43. @@
  44. msg="WARNING: Consider using vma_pages helper on %s" % (x)
  45. msg_safe=msg.replace("[","@(").replace("]",")")
  46. coccilib.org.print_todo(p[0], msg_safe)