resource_size.cocci 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. ///
  3. /// Use resource_size function on resource object
  4. /// instead of explicit computation.
  5. ///
  6. // Confidence: High
  7. // Copyright: (C) 2009, 2010 Nicolas Palix, DIKU.
  8. // Copyright: (C) 2009, 2010 Julia Lawall, DIKU.
  9. // Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6.
  10. // URL: https://coccinelle.gitlabpages.inria.fr/website
  11. // Options:
  12. //
  13. // Keywords: resource_size
  14. // Version min: 2.6.27 resource_size
  15. //
  16. virtual context
  17. virtual patch
  18. virtual org
  19. virtual report
  20. //----------------------------------------------------------
  21. // For context mode
  22. //----------------------------------------------------------
  23. @r_context depends on context && !patch && !org@
  24. struct resource *res;
  25. @@
  26. * (res->end - res->start) + 1
  27. //----------------------------------------------------------
  28. // For patch mode
  29. //----------------------------------------------------------
  30. @r_patch depends on !context && patch && !org@
  31. struct resource *res;
  32. @@
  33. - (res->end - res->start) + 1
  34. + resource_size(res)
  35. //----------------------------------------------------------
  36. // For org mode
  37. //----------------------------------------------------------
  38. @r_org depends on !context && !patch && (org || report)@
  39. struct resource *res;
  40. position p;
  41. @@
  42. (res->end@p - res->start) + 1
  43. @rbad_org depends on !context && !patch && (org || report)@
  44. struct resource *res;
  45. position p != r_org.p;
  46. @@
  47. res->end@p - res->start
  48. @script:python depends on org@
  49. p << r_org.p;
  50. x << r_org.res;
  51. @@
  52. msg="ERROR with %s" % (x)
  53. msg_safe=msg.replace("[","@(").replace("]",")")
  54. coccilib.org.print_todo(p[0], msg_safe)
  55. @script:python depends on report@
  56. p << r_org.p;
  57. x << r_org.res;
  58. @@
  59. msg="ERROR: Missing resource_size with %s" % (x)
  60. coccilib.report.print_report(p[0], msg)
  61. @script:python depends on org@
  62. p << rbad_org.p;
  63. x << rbad_org.res;
  64. @@
  65. msg="WARNING with %s" % (x)
  66. msg_safe=msg.replace("[","@(").replace("]",")")
  67. coccilib.org.print_todo(p[0], msg_safe)
  68. @script:python depends on report@
  69. p << rbad_org.p;
  70. x << rbad_org.res;
  71. @@
  72. msg="WARNING: Suspicious code. resource_size is maybe missing with %s" % (x)
  73. coccilib.report.print_report(p[0], msg)