warn.cocci 1.7 KB

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