cstptr.cocci 873 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// PTR_ERR should be applied before its argument is reassigned, typically
  3. /// to NULL
  4. ///
  5. // Confidence: High
  6. // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
  7. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
  8. // URL: https://coccinelle.gitlabpages.inria.fr/website
  9. // Comments:
  10. // Options: --no-includes --include-headers
  11. virtual org
  12. virtual report
  13. virtual context
  14. @r exists@
  15. expression e,e1;
  16. constant c;
  17. position p1,p2;
  18. @@
  19. *e@p1 = c
  20. ... when != e = e1
  21. when != &e
  22. when != true IS_ERR(e)
  23. *PTR_ERR@p2(e)
  24. @script:python depends on org@
  25. p1 << r.p1;
  26. p2 << r.p2;
  27. @@
  28. cocci.print_main("PTR_ERR",p2)
  29. cocci.print_secs("assignment",p1)
  30. @script:python depends on report@
  31. p1 << r.p1;
  32. p2 << r.p2;
  33. @@
  34. msg = "ERROR: PTR_ERR applied after initialization to constant on line %s" % (p1[0].line)
  35. coccilib.report.print_report(p2[0],msg)