2 /// Use kzalloc rather than kmalloc followed by memset with 0
4 /// This considers some simple cases that are common and easy to validate
5 /// Note in particular that there are no ...s in the rule, so all of the
6 /// matched code has to be contiguous
9 // Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2.
10 // Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2.
11 // URL: http://coccinelle.lip6.fr/rules/kzalloc.html
12 // Options: --no-includes --include-headers
14 // Keywords: kmalloc, kzalloc
15 // Version min: < 2.6.12 kmalloc
16 // Version min: 2.6.14 kzalloc
24 //----------------------------------------------------------
26 //----------------------------------------------------------
35 * x = (T)kmalloc(E1,E2);
36 if ((x==NULL) || ...) S
39 //----------------------------------------------------------
41 //----------------------------------------------------------
50 - x = (T)kmalloc(E1,E2);
52 if ((x==NULL) || ...) S
55 //----------------------------------------------------------
57 //----------------------------------------------------------
59 @r depends on org || report@
67 x = (T)kmalloc@p(E1,E2);
68 if ((x==NULL) || ...) S
71 @script:python depends on org@
77 msg_safe=msg.replace("[","@(").replace("]",")")
78 coccilib.org.print_todo(p[0], msg_safe)
80 @script:python depends on report@
85 msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x)
86 coccilib.report.print_report(p[0], msg)