// Various iterators manage reference counts internally, and thus typically
// a put is needed before breaking out of the loop, unless the current element
// is saved in some way
//
// Confidence: Moderate
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU.  GPLv2.
// URL: http://coccinelle.lip6.fr/rules/missing_put.html
// Options:

@@
local idexpression d;
expression e;
iterator name for_each_node_by_name;
@@

for_each_node_by_name(d,...)
  {... when != of_node_put(d)
       when != e = d
(
   return d;
|
+  of_node_put(d);
?  return ...;
)
...}

@@
local idexpression d;
expression e, e1;
@@

for_each_node_by_name(d,...)
  {... when != of_node_put(d)
       when != e = d
+ of_node_put(d);
? break;
  ...}
... when != of_node_put(d)
    when != e1 = d
    when != return d;

// --------------------------------
@@
local idexpression d;
expression e;
iterator name for_each_node_by_type;
@@

for_each_node_by_type(d,...)
  {... when != of_node_put(d)
       when != e = d
(
   return d;
|
+  of_node_put(d);
?  return ...;
)
...}

@@
local idexpression d;
expression e, e1;
@@

for_each_node_by_type(d,...)
  {... when != of_node_put(d)
       when != e = d
+ of_node_put(d);
? break;
  ...}
... when != of_node_put(d)
    when != e1 = d
    when != return d;

// --------------------------------
@@
local idexpression d;
expression e;
iterator name for_each_compatible_node;
@@

for_each_compatible_node(d,...)
  {... when != of_node_put(d)
       when != e = d
(
   return d;
|
+  of_node_put(d);
?  return ...;
)
...}

@@
local idexpression d;
expression e, e1;
@@

for_each_compatible_node(d,...)
  {... when != of_node_put(d)
       when != e = d
+ of_node_put(d);
? break;
  ...}
... when != of_node_put(d)
    when != e1 = d
    when != return d;

// --------------------------------
@@
local idexpression d;
expression e;
iterator name shost_for_each_device;
@@

shost_for_each_device(d,...)
  {... when != scsi_device_put(d)
       when != e = d
(
   return d;
|
+  scsi_device_put(d);
?  return ...;
)
...}

@@
local idexpression d;
expression e, e1;
@@

shost_for_each_device(d,...)
  {... when != scsi_device_put(d)
       when != e = d
+ scsi_device_put(d);
? break;
  ...}
... when != scsi_device_put(d)
    when != e1 = d
    when != return d;

@@
local idexpression d;
expression e;
@@

for (d = NULL; (d = of_find_all_nodes(d)) != NULL; )
 {... when != of_node_put(d)
  when != e = d
(
   return d;
|
+  of_node_put(d);
?  return ...;
)
...}