odd_ptr_err.cocci 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /// PTR_ERR should access the value just tested by IS_ERR
  2. //# There can be false positives in the patch case, where it is the call to
  3. //# IS_ERR that is wrong.
  4. ///
  5. // Confidence: High
  6. // Copyright: (C) 2012, 2015 Julia Lawall, INRIA. GPLv2.
  7. // Copyright: (C) 2012, 2015 Gilles Muller, INRIA. GPLv2.
  8. // URL: http://coccinelle.lip6.fr/
  9. // Options: --no-includes --include-headers
  10. virtual patch
  11. virtual context
  12. virtual org
  13. virtual report
  14. @ok1 exists@
  15. expression x,e;
  16. position p;
  17. @@
  18. if (IS_ERR(x=e) || ...) {
  19. <...
  20. PTR_ERR@p(x)
  21. ...>
  22. }
  23. @ok2 exists@
  24. expression x,e1,e2;
  25. position p;
  26. @@
  27. if (IS_ERR(x) || ...) {
  28. <...
  29. (
  30. PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
  31. |
  32. PTR_ERR@p(x)
  33. )
  34. ...>
  35. }
  36. @r1 depends on patch && !context && !org && !report exists@
  37. expression x,y;
  38. position p != {ok1.p,ok2.p};
  39. @@
  40. if (IS_ERR(x) || ...) {
  41. ... when any
  42. when != IS_ERR(...)
  43. (
  44. PTR_ERR(x)
  45. |
  46. PTR_ERR@p(
  47. - y
  48. + x
  49. )
  50. )
  51. ... when any
  52. }
  53. // ----------------------------------------------------------------------------
  54. @r1_context depends on !patch && (context || org || report) exists@
  55. position p != {ok1.p,ok2.p};
  56. expression x, y;
  57. position j0, j1;
  58. @@
  59. if (IS_ERR@j0(x) || ...) {
  60. ... when any
  61. when != IS_ERR(...)
  62. (
  63. PTR_ERR(x)
  64. |
  65. PTR_ERR@j1@p(
  66. y
  67. )
  68. )
  69. ... when any
  70. }
  71. @r1_disj depends on !patch && (context || org || report) exists@
  72. position p != {ok1.p,ok2.p};
  73. expression x, y;
  74. position r1_context.j0, r1_context.j1;
  75. @@
  76. * if (IS_ERR@j0(x) || ...) {
  77. ... when any
  78. when != IS_ERR(...)
  79. * PTR_ERR@j1@p(
  80. y
  81. )
  82. ... when any
  83. }
  84. // ----------------------------------------------------------------------------
  85. @script:python r1_org depends on org@
  86. j0 << r1_context.j0;
  87. j1 << r1_context.j1;
  88. @@
  89. msg = "inconsistent IS_ERR and PTR_ERR"
  90. coccilib.org.print_todo(j0[0], msg)
  91. coccilib.org.print_link(j1[0], "")
  92. // ----------------------------------------------------------------------------
  93. @script:python r1_report depends on report@
  94. j0 << r1_context.j0;
  95. j1 << r1_context.j1;
  96. @@
  97. msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line)
  98. coccilib.report.print_report(j0[0], msg)