/scripts/coccinelle/iterators/list_entry_update.cocci

http://github.com/mirrors/linux · Unknown · 62 lines · 50 code · 12 blank · 0 comment · 0 complexity · 82b06c66a95113827d1e77bf049808a0 MD5 · raw file

  1. /// list_for_each_entry uses its first argument to get from one element of
  2. /// the list to the next, so it is usually not a good idea to reassign it.
  3. /// The first rule finds such a reassignment and the second rule checks
  4. /// that there is a path from the reassignment back to the top of the loop.
  5. ///
  6. // Confidence: High
  7. // Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
  8. // Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
  9. // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
  10. // URL: http://coccinelle.lip6.fr/
  11. // Comments:
  12. // Options: --no-includes --include-headers
  13. virtual context
  14. virtual org
  15. virtual report
  16. @r@
  17. iterator name list_for_each_entry;
  18. expression x,E;
  19. position p1,p2;
  20. @@
  21. list_for_each_entry@p1(x,...) { <... x =@p2 E ...> }
  22. @depends on context && !org && !report@
  23. expression x,E;
  24. position r.p1,r.p2;
  25. statement S;
  26. @@
  27. *x =@p2 E
  28. ...
  29. list_for_each_entry@p1(x,...) S
  30. // ------------------------------------------------------------------------
  31. @back depends on (org || report) && !context exists@
  32. expression x,E;
  33. position r.p1,r.p2;
  34. statement S;
  35. @@
  36. x =@p2 E
  37. ...
  38. list_for_each_entry@p1(x,...) S
  39. @script:python depends on back && org@
  40. p1 << r.p1;
  41. p2 << r.p2;
  42. @@
  43. cocci.print_main("iterator",p1)
  44. cocci.print_secs("update",p2)
  45. @script:python depends on back && report@
  46. p1 << r.p1;
  47. p2 << r.p2;
  48. @@
  49. msg = "iterator with update on line %s" % (p2[0].line)
  50. coccilib.report.print_report(p1[0],msg)