1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Find uses of standard freeing functons on values allocated using devm_
3 /// functions. Values allocated using the devm_functions are freed when
4 /// the device is detached, and thus the use of the standard freeing
5 /// function would cause a double free.
6 /// See Documentation/driver-api/driver-model/devres.rst for more information.
8 /// A difficulty of detecting this problem is that the standard freeing
9 /// function might be called from a different function than the one
10 /// containing the allocation function. It is thus necessary to make the
11 /// connection between the allocation function and the freeing function.
12 /// Here this is done using the specific argument text, which is prone to
13 /// false positives. There is no rule for the request_region and
14 /// request_mem_region variants because this heuristic seems to be a bit
15 /// less reliable in these cases.
17 // Confidence: Moderate
18 // Copyright: (C) 2011 Julia Lawall, INRIA/LIP6.
19 // Copyright: (C) 2011 Gilles Muller, INRIA/LiP6.
20 // URL: http://coccinelle.lip6.fr/
22 // Options: --no-includes --include-headers
28 @r depends on context || org || report@
35 x = devm_kvasprintf(...)
37 x = devm_kasprintf(...)
41 x = devm_kmalloc_array(...)
49 x = devm_get_free_pages(...)
51 x = devm_request_irq(...)
55 x = devm_ioport_map(...)
58 @safe depends on context || org || report exists@
72 x = kmalloc_array(...)
80 x = get_free_pages(...)
109 position p != safe.p;
119 * free_pages@p(x, ...)
130 @script:python depends on org@
134 msg="WARNING: invalid free of devm_ allocated data"
135 coccilib.org.print_todo(p[0], msg)
137 @script:python depends on report@
141 msg="WARNING: invalid free of devm_ allocated data"
142 coccilib.report.print_report(p[0], msg)