err_cast.cocci 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ///
  2. /// Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...))
  3. ///
  4. // Confidence: High
  5. // Copyright: (C) 2009, 2010 Nicolas Palix, DIKU. GPLv2.
  6. // Copyright: (C) 2009, 2010 Julia Lawall, DIKU. GPLv2.
  7. // Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6. GPLv2.
  8. // URL: http://coccinelle.lip6.fr/
  9. // Options:
  10. //
  11. // Keywords: ERR_PTR, PTR_ERR, ERR_CAST
  12. // Version min: 2.6.25
  13. //
  14. virtual context
  15. virtual patch
  16. virtual org
  17. virtual report
  18. @ depends on context && !patch && !org && !report@
  19. expression x;
  20. @@
  21. * ERR_PTR(PTR_ERR(x))
  22. @ depends on !context && patch && !org && !report @
  23. expression x;
  24. @@
  25. - ERR_PTR(PTR_ERR(x))
  26. + ERR_CAST(x)
  27. @r depends on !context && !patch && (org || report)@
  28. expression x;
  29. position p;
  30. @@
  31. ERR_PTR@p(PTR_ERR(x))
  32. @script:python depends on org@
  33. p << r.p;
  34. x << r.x;
  35. @@
  36. msg="WARNING ERR_CAST can be used with %s" % (x)
  37. msg_safe=msg.replace("[","@(").replace("]",")")
  38. coccilib.org.print_todo(p[0], msg_safe)
  39. @script:python depends on report@
  40. p << r.p;
  41. x << r.x;
  42. @@
  43. msg="WARNING: ERR_CAST can be used with %s" % (x)
  44. coccilib.report.print_report(p[0], msg)