1 /// Find uses of standard freeing functons on values allocated using devm_
2 /// functions. Values allocated using the devm_functions are freed when
3 /// the device is detached, and thus the use of the standard freeing
4 /// function would cause a double free.
5 /// See Documentation/driver-model/devres.txt for more information.
7 /// A difficulty of detecting this problem is that the standard freeing
8 /// function might be called from a different function than the one
9 /// containing the allocation function. It is thus necessary to make the
10 /// connection between the allocation function and the freeing function.
11 /// Here this is done using the specific argument text, which is prone to
12 /// false positives. There is no rule for the request_region and
13 /// request_mem_region variants because this heuristic seems to be a bit
14 /// less reliable in these cases.
16 // Confidence: Moderate
17 // Copyright: (C) 2011 Julia Lawall, INRIA/LIP6. GPLv2.
18 // Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2.
19 // URL: http://coccinelle.lip6.fr/
21 // Options: --no-includes --include-headers
27 @r depends on context || org || report@
34 x = devm_kvasprintf(...)
36 x = devm_kasprintf(...)
40 x = devm_kmalloc_array(...)
48 x = devm_get_free_pages(...)
50 x = devm_request_irq(...)
54 x = devm_ioremap_nocache(...)
56 x = devm_ioport_map(...)
59 @safe depends on context || org || report exists@
73 x = kmalloc_array(...)
81 x = get_free_pages(...)
87 x = ioremap_nocache(...)
114 position p != safe.p;
122 * __krealloc@p(x, ...)
126 * free_pages@p(x, ...)
137 @script:python depends on org@
141 msg="WARNING: invalid free of devm_ allocated data"
142 coccilib.org.print_todo(p[0], msg)
144 @script:python depends on report@
148 msg="WARNING: invalid free of devm_ allocated data"
149 coccilib.report.print_report(p[0], msg)