err_cast.cocci 1.1 KB

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