warn.cocci 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /// Use WARN(1,...) rather than printk followed by WARN_ON(1)
  2. ///
  3. // Confidence: High
  4. // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
  5. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
  6. // URL: http://coccinelle.lip6.fr/
  7. // Comments:
  8. // Options: --no-includes --include-headers
  9. virtual patch
  10. virtual context
  11. virtual org
  12. virtual report
  13. @bad1@
  14. position p;
  15. @@
  16. printk(...);
  17. printk@p(...);
  18. WARN_ON(1);
  19. @r1 depends on context || report || org@
  20. position p != bad1.p;
  21. @@
  22. printk@p(...);
  23. *WARN_ON(1);
  24. @script:python depends on org@
  25. p << r1.p;
  26. @@
  27. cocci.print_main("printk + WARN_ON can be just WARN",p)
  28. @script:python depends on report@
  29. p << r1.p;
  30. @@
  31. msg = "SUGGESTION: printk + WARN_ON can be just WARN"
  32. coccilib.report.print_report(p[0],msg)
  33. @ok1 depends on patch@
  34. expression list es;
  35. position p != bad1.p;
  36. @@
  37. -printk@p(
  38. +WARN(1,
  39. es);
  40. -WARN_ON(1);
  41. @depends on patch@
  42. expression list ok1.es;
  43. @@
  44. if (...)
  45. - {
  46. WARN(1,es);
  47. - }
  48. // --------------------------------------------------------------------
  49. @bad2@
  50. position p;
  51. @@
  52. printk(...);
  53. printk@p(...);
  54. WARN_ON_ONCE(1);
  55. @r2 depends on context || report || org@
  56. position p != bad1.p;
  57. @@
  58. printk@p(...);
  59. *WARN_ON_ONCE(1);
  60. @script:python depends on org@
  61. p << r2.p;
  62. @@
  63. cocci.print_main("printk + WARN_ON_ONCE can be just WARN_ONCE",p)
  64. @script:python depends on report@
  65. p << r2.p;
  66. @@
  67. msg = "SUGGESTION: printk + WARN_ON_ONCE can be just WARN_ONCE"
  68. coccilib.report.print_report(p[0],msg)
  69. @ok2 depends on patch@
  70. expression list es;
  71. position p != bad2.p;
  72. @@
  73. -printk@p(
  74. +WARN_ONCE(1,
  75. es);
  76. -WARN_ON_ONCE(1);
  77. @depends on patch@
  78. expression list ok2.es;
  79. @@
  80. if (...)
  81. - {
  82. WARN_ONCE(1,es);
  83. - }