ptr_ret.cocci 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ///
  2. /// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
  3. ///
  4. // Confidence: High
  5. // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
  6. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
  7. // URL: http://coccinelle.lip6.fr/
  8. // Options: --no-includes --include-headers
  9. //
  10. // Keywords: ERR_PTR, PTR_ERR, PTR_ERR_OR_ZERO
  11. // Version min: 2.6.39
  12. //
  13. virtual context
  14. virtual patch
  15. virtual org
  16. virtual report
  17. @depends on patch@
  18. expression ptr;
  19. @@
  20. - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
  21. + return PTR_ERR_OR_ZERO(ptr);
  22. @depends on patch@
  23. expression ptr;
  24. @@
  25. - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
  26. + return PTR_ERR_OR_ZERO(ptr);
  27. @depends on patch@
  28. expression ptr;
  29. @@
  30. - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
  31. + PTR_ERR_OR_ZERO(ptr)
  32. @r1 depends on !patch@
  33. expression ptr;
  34. position p1;
  35. @@
  36. * if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
  37. @r2 depends on !patch@
  38. expression ptr;
  39. position p2;
  40. @@
  41. * if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
  42. @r3 depends on !patch@
  43. expression ptr;
  44. position p3;
  45. @@
  46. * IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0
  47. @script:python depends on org@
  48. p << r1.p1;
  49. @@
  50. coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
  51. @script:python depends on org@
  52. p << r2.p2;
  53. @@
  54. coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
  55. @script:python depends on org@
  56. p << r3.p3;
  57. @@
  58. coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
  59. @script:python depends on report@
  60. p << r1.p1;
  61. @@
  62. coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
  63. @script:python depends on report@
  64. p << r2.p2;
  65. @@
  66. coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
  67. @script:python depends on report@
  68. p << r3.p3;
  69. @@
  70. coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")