mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 14:04:27 -04:00
coccinelle: api: check for macro context
A cast on a call to an allocation function that is the body of a macro can be useful, as it ensures tha the macro is used for allocating objects of the right type. Add two new rules to ignore the macro case. Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
This commit is contained in:
@@ -20,6 +20,24 @@ virtual patch
|
||||
virtual org
|
||||
virtual report
|
||||
|
||||
@m1@
|
||||
identifier i;
|
||||
expression e;
|
||||
type T;
|
||||
position p1;
|
||||
@@
|
||||
|
||||
#define i (T@p1 *)e
|
||||
|
||||
@m2@
|
||||
identifier i;
|
||||
expression e;
|
||||
type T;
|
||||
position p2;
|
||||
@@
|
||||
|
||||
#define i(...) (T@p2 *)e
|
||||
|
||||
@initialize:python@
|
||||
@@
|
||||
import re
|
||||
@@ -28,9 +46,10 @@ m = re.compile(pattern)
|
||||
|
||||
@r1 depends on context || patch@
|
||||
type T;
|
||||
position p != {m1.p1,m2.p2};
|
||||
@@
|
||||
|
||||
(T *)
|
||||
(T@p *)
|
||||
\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
|
||||
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
|
||||
dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
|
||||
@@ -90,7 +109,7 @@ type r1.T;
|
||||
|
||||
@r2 depends on org || report@
|
||||
type T;
|
||||
position p;
|
||||
position p != {m1.p1,m2.p2};
|
||||
@@
|
||||
|
||||
(T@p *)
|
||||
|
||||
Reference in New Issue
Block a user