bugon.cocci 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /// Use BUG_ON instead of a if condition followed by BUG.
  2. ///
  3. //# This makes an effort to find cases where BUG() follows an if
  4. //# condition on an expression and replaces the if condition and BUG()
  5. //# with a BUG_ON having the conditional expression of the if statement
  6. //# as argument.
  7. //
  8. // Confidence: High
  9. // Copyright: (C) 2014 Himangi Saraogi. GPLv2.
  10. // Comments:
  11. // Options: --no-includes --include-headers
  12. virtual patch
  13. virtual context
  14. virtual org
  15. virtual report
  16. //----------------------------------------------------------
  17. // For context mode
  18. //----------------------------------------------------------
  19. @depends on context@
  20. expression e;
  21. @@
  22. *if (e) BUG();
  23. //----------------------------------------------------------
  24. // For patch mode
  25. //----------------------------------------------------------
  26. @depends on patch@
  27. expression e;
  28. @@
  29. -if (e) BUG();
  30. +BUG_ON(e);
  31. //----------------------------------------------------------
  32. // For org and report mode
  33. //----------------------------------------------------------
  34. @r@
  35. expression e;
  36. position p;
  37. @@
  38. if (e) BUG@p ();
  39. @script:python depends on org@
  40. p << r.p;
  41. @@
  42. coccilib.org.print_todo(p[0], "WARNING use BUG_ON")
  43. @script:python depends on report@
  44. p << r.p;
  45. @@
  46. msg="WARNING: Use BUG_ON instead of if condition followed by BUG.\nPlease make sure the condition has no side effects (see conditional BUG_ON definition in include/asm-generic/bug.h)"
  47. coccilib.report.print_report(p[0], msg)