1 // SPDX-License-Identifier: GPL-2.0-only
2 // Adds missing of_node_put() before return/break/goto statement within a for_each iterator for child nodes.
3 //# False positives can be due to function calls within the for_each
4 //# loop that may encapsulate an of_node_put.
7 // Copyright: (C) 2020 Sumera Priyadarsini
8 // URL: http://coccinelle.lip6.fr
9 // Options: --no-includes --include-headers
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;
25 expression list [n1] es;
30 for_each_node_by_name(n,e1) S
32 for_each_node_by_type(n,e1) S
34 for_each_compatible_node(n,e1,e2) S
36 for_each_matching_node(n,e1) S
38 for_each_matching_node_and_match(n,e1,e2) S
40 for_each_child_of_node(e1,n) S
42 for_each_available_child_of_node(e1,n) S
44 for_each_node_with_property(n,e1) S
50 @ruleone depends on patch && !context && !org && !report@
52 local idexpression r.n;
55 expression list [r.n1] es;
70 - return of_node_get(n);
79 @ruletwo depends on patch && !context && !org && !report@
81 local idexpression r.n;
84 expression list [r.n1] es;
111 @rulethree depends on patch && !context && !org && !report exists@
113 local idexpression r.n;
117 expression list [r.n1] es;
145 // ----------------------------------------------------------------------------
147 @ruleone_context depends on !patch && (context || org || report) exists@
150 expression list[r.n1] es;
152 local idexpression r.n;
172 @ruleone_disj depends on !patch && (context || org || report)@
173 expression list[r.n1] es;
175 local idexpression r.n;
176 position ruleone_context.j0, ruleone_context.j1;
185 @ruletwo_context depends on !patch && (context || org || report) exists@
188 expression list[r.n1] es;
189 iterator r.i, i1, i2;
190 local idexpression r.n;
216 @ruletwo_disj depends on !patch && (context || org || report)@
219 expression list[r.n1] es;
221 local idexpression r.n;
222 position ruletwo_context.j0, ruletwo_context.j2;
239 @rulethree_context depends on !patch && (context || org || report) exists@
243 expression list[r.n1] es;
244 iterator r.i, i1, i2;
245 local idexpression r.n;
273 @rulethree_disj depends on !patch && (context || org || report) exists@
277 expression list[r.n1] es;
279 local idexpression r.n;
280 position rulethree_context.j0, rulethree_context.j3;
299 // ----------------------------------------------------------------------------
301 @script:python ruleone_org depends on org@
303 j0 << ruleone_context.j0;
304 j1 << ruleone_context. j1;
307 msg = "WARNING: Function \"%s\" should have of_node_put() before return " % (i)
308 coccilib.org.print_safe_todo(j0[0], msg)
309 coccilib.org.print_link(j1[0], "")
311 @script:python ruletwo_org depends on org@
313 j0 << ruletwo_context.j0;
314 j2 << ruletwo_context.j2;
317 msg = "WARNING: Function \"%s\" should have of_node_put() before break " % (i)
318 coccilib.org.print_safe_todo(j0[0], msg)
319 coccilib.org.print_link(j2[0], "")
321 @script:python rulethree_org depends on org@
323 j0 << rulethree_context.j0;
324 j3 << rulethree_context.j3;
327 msg = "WARNING: Function \"%s\" should have of_node_put() before goto " % (i)
328 coccilib.org.print_safe_todo(j0[0], msg)
329 coccilib.org.print_link(j3[0], "")
331 // ----------------------------------------------------------------------------
333 @script:python ruleone_report depends on report@
335 j0 << ruleone_context.j0;
336 j1 << ruleone_context.j1;
339 msg = "WARNING: Function \"%s\" should have of_node_put() before return around line %s." % (i, j1[0].line)
340 coccilib.report.print_report(j0[0], msg)
342 @script:python ruletwo_report depends on report@
344 j0 << ruletwo_context.j0;
345 j2 << ruletwo_context.j2;
348 msg = "WARNING: Function \"%s\" should have of_node_put() before break around line %s." % (i,j2[0].line)
349 coccilib.report.print_report(j0[0], msg)
351 @script:python rulethree_report depends on report@
353 j0 << rulethree_context.j0;
354 j3 << rulethree_context.j3;
357 msg = "WARNING: Function \"%s\" should have of_node_put() before goto around lines %s." % (i,j3[0].line)
358 coccilib.report.print_report(j0[0], msg)