odd_ptr_err.cocci 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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
  3. //# IS_ERR that is wrong.
  4. ///
  5. // Confidence: High
  6. // Copyright: (C) 2012 Julia Lawall, INRIA. GPLv2.
  7. // Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2.
  8. // URL: http://coccinelle.lip6.fr/
  9. // Comments:
  10. // Options: -no_includes -include_headers
  11. virtual patch
  12. virtual context
  13. virtual org
  14. virtual report
  15. @depends on patch@
  16. expression e,e1;
  17. @@
  18. (
  19. if (IS_ERR(e)) { ... PTR_ERR(e) ... }
  20. |
  21. if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... }
  22. |
  23. if (IS_ERR(e))
  24. { ...
  25. PTR_ERR(
  26. - e1
  27. + e
  28. )
  29. ... }
  30. )
  31. @r depends on !patch@
  32. expression e,e1;
  33. position p1,p2;
  34. @@
  35. (
  36. if (IS_ERR(e)) { ... PTR_ERR(e) ... }
  37. |
  38. if (IS_ERR(e=e1)) { ... PTR_ERR(e) ... }
  39. |
  40. *if (IS_ERR@p1(e))
  41. { ...
  42. * PTR_ERR@p2(e1)
  43. ... }
  44. )
  45. @script:python depends on org@
  46. p1 << r.p1;
  47. p2 << r.p2;
  48. @@
  49. cocci.print_main("inconsistent IS_ERR and PTR_ERR",p1)
  50. cocci.print_secs("PTR_ERR",p2)
  51. @script:python depends on report@
  52. p1 << r.p1;
  53. p2 << r.p2;
  54. @@
  55. msg = "inconsistent IS_ERR and PTR_ERR, PTR_ERR on line %s" % (p2[0].line)
  56. coccilib.report.print_report(p1[0],msg)