^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /// These iterators only exit normally when the loop cursor is NULL, so there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /// is no point to call of_node_put on the final value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) ///
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Confidence: High
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Copyright: (C) 2010-2012 Nicolas Palix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // URL: http://coccinelle.lip6.fr/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) // Comments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) // Options: --no-includes --include-headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) virtual patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) virtual context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) virtual org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) virtual report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) @depends on patch@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) iterator name for_each_node_by_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) expression np,E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) identifier l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) for_each_node_by_name(np,...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) ... when != np = E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) - of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) @depends on patch@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) iterator name for_each_node_by_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) expression np,E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) identifier l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) for_each_node_by_type(np,...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ... when != np = E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) - of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) @depends on patch@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) iterator name for_each_compatible_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) expression np,E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) identifier l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) for_each_compatible_node(np,...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ... when != np = E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) - of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) @depends on patch@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) iterator name for_each_matching_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) expression np,E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) identifier l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) for_each_matching_node(np,...) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ... when != np = E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) - of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) // ----------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) @r depends on !patch forall@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) //iterator name for_each_node_by_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) //iterator name for_each_node_by_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) //iterator name for_each_compatible_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) //iterator name for_each_matching_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) expression np,E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) identifier l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) position p1,p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *for_each_node_by_name@p1(np,...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *for_each_node_by_type@p1(np,...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *for_each_compatible_node@p1(np,...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *for_each_matching_node@p1(np,...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ... when != break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) when != goto l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ... when != np = E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * of_node_put@p2(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) @script:python depends on org@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) p1 << r.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) p2 << r.p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) cocci.print_main("unneeded of_node_put",p2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) cocci.print_secs("iterator",p1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) @script:python depends on report@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) p1 << r.p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) p2 << r.p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) msg = "ERROR: of_node_put not needed after iterator on line %s" % (p1[0].line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) coccilib.report.print_report(p2[0], msg)