device_node_continue.cocci 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// Device node iterators put the previous value of the index variable, so an
  3. /// explicit put causes a double put.
  4. ///
  5. // Confidence: High
  6. // Copyright: (C) 2015 Julia Lawall, Inria.
  7. // URL: https://coccinelle.gitlabpages.inria.fr/website
  8. // Options: --no-includes --include-headers
  9. // Requires: 1.0.4
  10. // Keywords: for_each_child_of_node, etc.
  11. // This uses a conjunction, which requires at least coccinelle >= 1.0.4
  12. virtual patch
  13. virtual context
  14. virtual org
  15. virtual report
  16. @r exists@
  17. expression e1,e2;
  18. local idexpression n;
  19. iterator name for_each_node_by_name, for_each_node_by_type,
  20. for_each_compatible_node, for_each_matching_node,
  21. for_each_matching_node_and_match, for_each_child_of_node,
  22. for_each_available_child_of_node, for_each_node_with_property;
  23. iterator i;
  24. position p1,p2;
  25. statement S;
  26. @@
  27. (
  28. (
  29. for_each_node_by_name(n,e1) S
  30. |
  31. for_each_node_by_type(n,e1) S
  32. |
  33. for_each_compatible_node(n,e1,e2) S
  34. |
  35. for_each_matching_node(n,e1) S
  36. |
  37. for_each_matching_node_and_match(n,e1,e2) S
  38. |
  39. for_each_child_of_node(e1,n) S
  40. |
  41. for_each_available_child_of_node(e1,n) S
  42. |
  43. for_each_node_with_property(n,e1) S
  44. )
  45. &
  46. i@p1(...) {
  47. ... when != of_node_get(n)
  48. when any
  49. of_node_put@p2(n);
  50. ... when any
  51. }
  52. )
  53. @s exists@
  54. local idexpression r.n;
  55. statement S;
  56. position r.p1,r.p2;
  57. iterator i;
  58. @@
  59. of_node_put@p2(n);
  60. ... when any
  61. i@p1(..., n, ...)
  62. S
  63. @t depends on s && patch && !context && !org && !report@
  64. local idexpression n;
  65. position r.p2;
  66. @@
  67. - of_node_put@p2(n);
  68. // ----------------------------------------------------------------------------
  69. @t_context depends on s && !patch && (context || org || report)@
  70. local idexpression n;
  71. position r.p2;
  72. position j0;
  73. @@
  74. * of_node_put@j0@p2(n);
  75. // ----------------------------------------------------------------------------
  76. @script:python t_org depends on org@
  77. j0 << t_context.j0;
  78. @@
  79. msg = "ERROR: probable double put."
  80. coccilib.org.print_todo(j0[0], msg)
  81. // ----------------------------------------------------------------------------
  82. @script:python t_report depends on report@
  83. j0 << t_context.j0;
  84. @@
  85. msg = "ERROR: probable double put."
  86. coccilib.report.print_report(j0[0], msg)