aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Kbuild.include14
-rw-r--r--scripts/Makefile.clean4
-rw-r--r--scripts/Makefile.extrawarn21
-rw-r--r--scripts/Makefile.host61
-rw-r--r--scripts/coccinelle/api/alloc/alloc_cast.cocci72
-rw-r--r--scripts/coccinelle/misc/array_size.cocci87
-rw-r--r--scripts/coccinelle/misc/badty.cocci76
-rw-r--r--scripts/coccinelle/misc/bugon.cocci (renamed from scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci)47
-rw-r--r--scripts/coccinelle/null/badzero.cocci3
9 files changed, 288 insertions, 97 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 122f95c95869..8a9a4e1c7eab 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -215,11 +215,13 @@ else
215arg-check = $(if $(strip $(cmd_$@)),,1) 215arg-check = $(if $(strip $(cmd_$@)),,1)
216endif 216endif
217 217
218# >'< substitution is for echo to work, 218# Replace >$< with >$$< to preserve $ when reloading the .cmd file
219# >$< substitution to preserve $ when reloading .cmd file 219# (needed for make)
220# note: when using inline perl scripts [perl -e '...$$t=1;...'] 220# Replace >#< with >\#< to avoid starting a comment in the .cmd file
221# in $(cmd_xxx) double $$ your perl vars 221# (needed for make)
222make-cmd = $(subst \\,\\\\,$(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))))) 222# Replace >'< with >'\''< to be able to enclose the whole string in '...'
223# (needed for the shell)
224make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
223 225
224# Find any prerequisites that is newer than target or that does not exist. 226# Find any prerequisites that is newer than target or that does not exist.
225# PHONY targets skipped in both cases. 227# PHONY targets skipped in both cases.
@@ -230,7 +232,7 @@ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
230if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 232if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
231 @set -e; \ 233 @set -e; \
232 $(echo-cmd) $(cmd_$(1)); \ 234 $(echo-cmd) $(cmd_$(1)); \
233 echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) 235 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
234 236
235# Execute the command and also postprocess generated .d dependencies file. 237# Execute the command and also postprocess generated .d dependencies file.
236if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ 238if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 686cb0d31c7c..a651cee84f2a 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -40,8 +40,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
40# build a list of files to remove, usually relative to the current 40# build a list of files to remove, usually relative to the current
41# directory 41# directory
42 42
43__clean-files := $(extra-y) $(always) \ 43__clean-files := $(extra-y) $(extra-m) $(extra-) \
44 $(targets) $(clean-files) \ 44 $(always) $(targets) $(clean-files) \
45 $(host-progs) \ 45 $(host-progs) \
46 $(hostprogs-y) $(hostprogs-m) $(hostprogs-) 46 $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
47 47
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 65643506c71c..f734033af219 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -26,16 +26,6 @@ warning-1 += $(call cc-option, -Wmissing-include-dirs)
26warning-1 += $(call cc-option, -Wunused-but-set-variable) 26warning-1 += $(call cc-option, -Wunused-but-set-variable)
27warning-1 += $(call cc-disable-warning, missing-field-initializers) 27warning-1 += $(call cc-disable-warning, missing-field-initializers)
28 28
29# Clang
30warning-1 += $(call cc-disable-warning, initializer-overrides)
31warning-1 += $(call cc-disable-warning, unused-value)
32warning-1 += $(call cc-disable-warning, format)
33warning-1 += $(call cc-disable-warning, unknown-warning-option)
34warning-1 += $(call cc-disable-warning, sign-compare)
35warning-1 += $(call cc-disable-warning, format-zero-length)
36warning-1 += $(call cc-disable-warning, uninitialized)
37warning-1 += $(call cc-option, -fcatch-undefined-behavior)
38
39warning-2 := -Waggregate-return 29warning-2 := -Waggregate-return
40warning-2 += -Wcast-align 30warning-2 += -Wcast-align
41warning-2 += -Wdisabled-optimization 31warning-2 += -Wdisabled-optimization
@@ -64,4 +54,15 @@ ifeq ("$(strip $(warning))","")
64endif 54endif
65 55
66KBUILD_CFLAGS += $(warning) 56KBUILD_CFLAGS += $(warning)
57else
58
59ifeq ($(COMPILER),clang)
60KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
61KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
62KBUILD_CFLAGS += $(call cc-disable-warning, format)
63KBUILD_CFLAGS += $(call cc-disable-warning, unknown-warning-option)
64KBUILD_CFLAGS += $(call cc-disable-warning, sign-compare)
65KBUILD_CFLAGS += $(call cc-disable-warning, format-zero-length)
66KBUILD_CFLAGS += $(call cc-disable-warning, uninitialized)
67endif
67endif 68endif
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
index 66893643fd7d..ab5980f91714 100644
--- a/scripts/Makefile.host
+++ b/scripts/Makefile.host
@@ -20,21 +20,12 @@
20# Will compile qconf as a C++ program, and menu as a C program. 20# Will compile qconf as a C++ program, and menu as a C program.
21# They are linked as C++ code to the executable qconf 21# They are linked as C++ code to the executable qconf
22 22
23# hostprogs-y := conf
24# conf-objs := conf.o libkconfig.so
25# libkconfig-objs := expr.o type.o
26# Will create a shared library named libkconfig.so that consists of
27# expr.o and type.o (they are both compiled as C code and the object files
28# are made as position independent code).
29# conf.c is compiled as a C program, and conf.o is linked together with
30# libkconfig.so as the executable conf.
31# Note: Shared libraries consisting of C++ files are not supported
32
33__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) 23__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
34 24
35# C code 25# C code
36# Executables compiled from a single .c file 26# Executables compiled from a single .c file
37host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m))) 27host-csingle := $(foreach m,$(__hostprogs), \
28 $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
38 29
39# C executables linked based on several .o files 30# C executables linked based on several .o files
40host-cmulti := $(foreach m,$(__hostprogs),\ 31host-cmulti := $(foreach m,$(__hostprogs),\
@@ -44,33 +35,17 @@ host-cmulti := $(foreach m,$(__hostprogs),\
44host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) 35host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
45 36
46# C++ code 37# C++ code
47# C++ executables compiled from at least on .cc file 38# C++ executables compiled from at least one .cc file
48# and zero or more .c files 39# and zero or more .c files
49host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m))) 40host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
50 41
51# C++ Object (.o) files compiled from .cc files 42# C++ Object (.o) files compiled from .cc files
52host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) 43host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
53 44
54# Shared libaries (only .c supported)
55# Shared libraries (.so) - all .so files referenced in "xxx-objs"
56host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
57# Remove .so files from "xxx-objs"
58host-cobjs := $(filter-out %.so,$(host-cobjs))
59
60#Object (.o) files used by the shared libaries
61host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
62
63# output directory for programs/.o files 45# output directory for programs/.o files
64# hostprogs-y := tools/build may have been specified. Retrieve directory 46# hostprogs-y := tools/build may have been specified.
65host-objdirs := $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f)))) 47# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
66# directory of .o files from prog-objs notation 48host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs))
67host-objdirs += $(foreach f,$(host-cmulti), \
68 $(foreach m,$($(f)-objs), \
69 $(if $(dir $(m)),$(dir $(m)))))
70# directory of .o files from prog-cxxobjs notation
71host-objdirs += $(foreach f,$(host-cxxmulti), \
72 $(foreach m,$($(f)-cxxobjs), \
73 $(if $(dir $(m)),$(dir $(m)))))
74 49
75host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) 50host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs))))
76 51
@@ -81,8 +56,6 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
81host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) 56host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) 57host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
83host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) 58host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
84host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
85host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
86host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) 59host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
87 60
88obj-dirs += $(host-objdirs) 61obj-dirs += $(host-objdirs)
@@ -123,7 +96,7 @@ quiet_cmd_host-cmulti = HOSTLD $@
123 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ 96 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
124 $(addprefix $(obj)/,$($(@F)-objs)) \ 97 $(addprefix $(obj)/,$($(@F)-objs)) \
125 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 98 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
126$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE 99$(host-cmulti): $(obj)/%: $(host-cobjs) FORCE
127 $(call if_changed,host-cmulti) 100 $(call if_changed,host-cmulti)
128 101
129# Create .o file from a single .c file 102# Create .o file from a single .c file
@@ -140,7 +113,7 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
140 $(foreach o,objs cxxobjs,\ 113 $(foreach o,objs cxxobjs,\
141 $(addprefix $(obj)/,$($(@F)-$(o)))) \ 114 $(addprefix $(obj)/,$($(@F)-$(o)))) \
142 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 115 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
143$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE 116$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) FORCE
144 $(call if_changed,host-cxxmulti) 117 $(call if_changed,host-cxxmulti)
145 118
146# Create .o file from a single .cc (C++) file 119# Create .o file from a single .cc (C++) file
@@ -149,21 +122,5 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
149$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE 122$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
150 $(call if_changed_dep,host-cxxobjs) 123 $(call if_changed_dep,host-cxxobjs)
151 124
152# Compile .c file, create position independent .o file
153# host-cshobjs -> .o
154quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
155 cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
156$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
157 $(call if_changed_dep,host-cshobjs)
158
159# Link a shared library, based on position independent .o files
160# *.o -> .so shared library (host-cshlib)
161quiet_cmd_host-cshlib = HOSTLLD -shared $@
162 cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
163 $(addprefix $(obj)/,$($(@F:.so=-objs))) \
164 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
165$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
166 $(call if_changed,host-cshlib)
167
168targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ 125targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
169 $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) 126 $(host-cxxmulti) $(host-cxxobjs)
diff --git a/scripts/coccinelle/api/alloc/alloc_cast.cocci b/scripts/coccinelle/api/alloc/alloc_cast.cocci
new file mode 100644
index 000000000000..6c308ee19b32
--- /dev/null
+++ b/scripts/coccinelle/api/alloc/alloc_cast.cocci
@@ -0,0 +1,72 @@
1/// Remove casting the values returned by memory allocation functions
2/// like kmalloc, kzalloc, kmem_cache_alloc, kmem_cache_zalloc etc.
3///
4//# This makes an effort to find cases of casting of values returned by
5//# kmalloc, kzalloc, kcalloc, kmem_cache_alloc, kmem_cache_zalloc,
6//# kmem_cache_alloc_node, kmalloc_node and kzalloc_node and removes
7//# the casting as it is not required. The result in the patch case may
8//#need some reformatting.
9//
10// Confidence: High
11// Copyright: 2014, Himangi Saraogi GPLv2.
12// Comments:
13// Options: --no-includes --include-headers
14//
15
16virtual context
17virtual patch
18virtual org
19virtual report
20
21//----------------------------------------------------------
22// For context mode
23//----------------------------------------------------------
24
25@depends on context@
26type T;
27@@
28
29* (T *)
30 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
31 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)
32
33//----------------------------------------------------------
34// For patch mode
35//----------------------------------------------------------
36
37@depends on patch@
38type T;
39@@
40
41- (T *)
42 (\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
43 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...))
44
45//----------------------------------------------------------
46// For org and report mode
47//----------------------------------------------------------
48
49@r depends on org || report@
50type T;
51position p;
52@@
53
54 (T@p *)\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
55 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)
56
57@script:python depends on org@
58p << r.p;
59t << r.T;
60@@
61
62coccilib.org.print_safe_todo(p[0], t)
63
64@script:python depends on report@
65p << r.p;
66t << r.T;
67@@
68
69msg="WARNING: casting value returned by memory allocation function to (%s *) is useless." % (t)
70coccilib.report.print_report(p[0], msg)
71
72
diff --git a/scripts/coccinelle/misc/array_size.cocci b/scripts/coccinelle/misc/array_size.cocci
new file mode 100644
index 000000000000..81e279cd347b
--- /dev/null
+++ b/scripts/coccinelle/misc/array_size.cocci
@@ -0,0 +1,87 @@
1/// Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element
2///
3//# This makes an effort to find cases where ARRAY_SIZE can be used such as
4//# where there is a division of sizeof the array by the sizeof its first
5//# element or by any indexed element or the element type. It replaces the
6//# division of the two sizeofs by ARRAY_SIZE.
7//
8// Confidence: High
9// Copyright: (C) 2014 Himangi Saraogi. GPLv2.
10// Comments:
11// Options: --no-includes --include-headers
12
13virtual patch
14virtual context
15virtual org
16virtual report
17
18@i@
19@@
20
21#include <linux/kernel.h>
22
23//----------------------------------------------------------
24// For context mode
25//----------------------------------------------------------
26
27@depends on i&&context@
28type T;
29T[] E;
30@@
31(
32* (sizeof(E)/sizeof(*E))
33|
34* (sizeof(E)/sizeof(E[...]))
35|
36* (sizeof(E)/sizeof(T))
37)
38
39//----------------------------------------------------------
40// For patch mode
41//----------------------------------------------------------
42
43@depends on i&&patch@
44type T;
45T[] E;
46@@
47(
48- (sizeof(E)/sizeof(*E))
49+ ARRAY_SIZE(E)
50|
51- (sizeof(E)/sizeof(E[...]))
52+ ARRAY_SIZE(E)
53|
54- (sizeof(E)/sizeof(T))
55+ ARRAY_SIZE(E)
56)
57
58//----------------------------------------------------------
59// For org and report mode
60//----------------------------------------------------------
61
62@r@
63type T;
64T[] E;
65position p;
66@@
67(
68 (sizeof(E)@p /sizeof(*E))
69|
70 (sizeof(E)@p /sizeof(E[...]))
71|
72 (sizeof(E)@p /sizeof(T))
73)
74
75@script:python depends on i&&org@
76p << r.p;
77@@
78
79coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE")
80
81@script:python depends on i&&report@
82p << r.p;
83@@
84
85msg="WARNING: Use ARRAY_SIZE"
86coccilib.report.print_report(p[0], msg)
87
diff --git a/scripts/coccinelle/misc/badty.cocci b/scripts/coccinelle/misc/badty.cocci
new file mode 100644
index 000000000000..2fc06fc71927
--- /dev/null
+++ b/scripts/coccinelle/misc/badty.cocci
@@ -0,0 +1,76 @@
1/// Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element
2///
3//# This makes an effort to find cases where the argument to sizeof is wrong
4//# in memory allocation functions by checking the type of the allocated memory
5//# when it is a double pointer and ensuring the sizeof argument takes a pointer
6//# to the the memory being allocated. There are false positives in cases the
7//# sizeof argument is not used in constructing the return value. The result
8//# may need some reformatting.
9//
10// Confidence: Moderate
11// Copyright: (C) 2014 Himangi Saraogi. GPLv2.
12// Comments:
13// Options:
14
15virtual patch
16virtual context
17virtual org
18virtual report
19
20//----------------------------------------------------------
21// For context mode
22//----------------------------------------------------------
23
24@depends on context disable sizeof_type_expr@
25type T;
26T **x;
27@@
28
29 x =
30 <+...sizeof(
31* T
32 )...+>
33
34//----------------------------------------------------------
35// For patch mode
36//----------------------------------------------------------
37
38@depends on patch disable sizeof_type_expr@
39type T;
40T **x;
41@@
42
43 x =
44 <+...sizeof(
45- T
46+ *x
47 )...+>
48
49//----------------------------------------------------------
50// For org and report mode
51//----------------------------------------------------------
52
53@r disable sizeof_type_expr@
54type T;
55T **x;
56position p;
57@@
58
59 x =
60 <+...sizeof(
61 T@p
62 )...+>
63
64@script:python depends on org@
65p << r.p;
66@@
67
68coccilib.org.print_todo(p[0], "WARNING sizeof argument should be pointer type, not structure type")
69
70@script:python depends on report@
71p << r.p;
72@@
73
74msg="WARNING: Use correct pointer type argument for sizeof"
75coccilib.report.print_report(p[0], msg)
76
diff --git a/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci b/scripts/coccinelle/misc/bugon.cocci
index bd5d08b882ee..556456ca761c 100644
--- a/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci
+++ b/scripts/coccinelle/misc/bugon.cocci
@@ -1,20 +1,17 @@
1/// Use BUG_ON instead of a if condition followed by BUG.
1/// 2///
2/// Casting (void *) value returned by kmalloc is useless 3//# This makes an effort to find cases where BUG() follows an if
3/// as mentioned in Documentation/CodingStyle, Chap 14. 4//# condition on an expression and replaces the if condition and BUG()
4/// 5//# with a BUG_ON having the conditional expression of the if statement
5// Confidence: High 6//# as argument.
6// Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Options: --no-includes --include-headers
9//
10// Keywords: kmalloc, kzalloc, kcalloc
11// Version min: < 2.6.12 kmalloc
12// Version min: < 2.6.12 kcalloc
13// Version min: 2.6.14 kzalloc
14// 7//
8// Confidence: High
9// Copyright: (C) 2014 Himangi Saraogi. GPLv2.
10// Comments:
11// Options: --no-includes, --include-headers
15 12
16virtual context
17virtual patch 13virtual patch
14virtual context
18virtual org 15virtual org
19virtual report 16virtual report
20 17
@@ -23,45 +20,43 @@ virtual report
23//---------------------------------------------------------- 20//----------------------------------------------------------
24 21
25@depends on context@ 22@depends on context@
26type T; 23expression e;
27@@ 24@@
28 25
29* (T *) 26*if (e) BUG();
30 \(kmalloc\|kzalloc\|kcalloc\)(...)
31 27
32//---------------------------------------------------------- 28//----------------------------------------------------------
33// For patch mode 29// For patch mode
34//---------------------------------------------------------- 30//----------------------------------------------------------
35 31
36@depends on patch@ 32@depends on patch@
37type T; 33expression e;
38@@ 34@@
39 35
40- (T *) 36-if (e) BUG();
41 \(kmalloc\|kzalloc\|kcalloc\)(...) 37+BUG_ON(e);
42 38
43//---------------------------------------------------------- 39//----------------------------------------------------------
44// For org and report mode 40// For org and report mode
45//---------------------------------------------------------- 41//----------------------------------------------------------
46 42
47@r depends on org || report@ 43@r@
48type T; 44expression e;
49position p; 45position p;
50@@ 46@@
51 47
52 (T@p *)\(kmalloc\|kzalloc\|kcalloc\)(...) 48 if (e) BUG@p ();
53 49
54@script:python depends on org@ 50@script:python depends on org@
55p << r.p; 51p << r.p;
56t << r.T;
57@@ 52@@
58 53
59coccilib.org.print_safe_todo(p[0], t) 54coccilib.org.print_todo(p[0], "WARNING use BUG_ON")
60 55
61@script:python depends on report@ 56@script:python depends on report@
62p << r.p; 57p << r.p;
63t << r.T;
64@@ 58@@
65 59
66msg="WARNING: casting value returned by k[cmz]alloc to (%s *) is useless." % (t) 60msg="WARNING: Use BUG_ON"
67coccilib.report.print_report(p[0], msg) 61coccilib.report.print_report(p[0], msg)
62
diff --git a/scripts/coccinelle/null/badzero.cocci b/scripts/coccinelle/null/badzero.cocci
index d79baf7220e7..5551da2b4fe3 100644
--- a/scripts/coccinelle/null/badzero.cocci
+++ b/scripts/coccinelle/null/badzero.cocci
@@ -10,7 +10,7 @@
10// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. 10// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
11// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 11// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/ 12// URL: http://coccinelle.lip6.fr/
13// Comments: 13// Comments: Requires Coccinelle version 1.0.0-rc20 or later
14// Options: 14// Options:
15 15
16virtual patch 16virtual patch
@@ -19,6 +19,7 @@ virtual org
19virtual report 19virtual report
20 20
21@initialize:ocaml@ 21@initialize:ocaml@
22@@
22let negtable = Hashtbl.create 101 23let negtable = Hashtbl.create 101
23 24
24@depends on patch@ 25@depends on patch@