// pci_get_device, etc call pci_dev_get, and thus pci_dev_put must be used
// before dropping a reference to the location.
//
// Confidence: Moderate
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU.  GPLv2.
// URL: http://coccinelle.lip6.fr/rules/add_pci_dev.html
// Options:

@@
local idexpression d;
expression e;
expression *ptr != NULL;
@@

while ((d = \(pci_get_device\|pci_get_device_reverse\|pci_get_subsys\|pci_get_class\)(..., d)) != NULL)
 {... when != pci_dev_put(d)
      when != e = d
(
    return \(<+...d...+>\|ptr\);
|
+   pci_dev_put(d);
?   return ...;
)
...}

@@
local idexpression d;
expression e;
expression *ptr != NULL;
iterator name for_each_pci_dev;
@@

for_each_pci_dev(d)
   {... when != pci_dev_put(d)
        when != e = d
(
    return \(<+...d...+>\|ptr\);
|
+  pci_dev_put(d);
?  return ...;
)
...}