|
@@ -1,20 +1,17 @@
|
|
|
+/// Use BUG_ON instead of a if condition followed by BUG.
|
|
|
///
|
|
|
-/// Casting (void *) value returned by kmalloc is useless
|
|
|
-/// as mentioned in Documentation/CodingStyle, Chap 14.
|
|
|
-///
|
|
|
-// Confidence: High
|
|
|
-// Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2.
|
|
|
-// URL: http://coccinelle.lip6.fr/
|
|
|
-// Options: --no-includes --include-headers
|
|
|
-//
|
|
|
-// Keywords: kmalloc, kzalloc, kcalloc
|
|
|
-// Version min: < 2.6.12 kmalloc
|
|
|
-// Version min: < 2.6.12 kcalloc
|
|
|
-// Version min: 2.6.14 kzalloc
|
|
|
+//# This makes an effort to find cases where BUG() follows an if
|
|
|
+//# condition on an expression and replaces the if condition and BUG()
|
|
|
+//# with a BUG_ON having the conditional expression of the if statement
|
|
|
+//# as argument.
|
|
|
//
|
|
|
+// Confidence: High
|
|
|
+// Copyright: (C) 2014 Himangi Saraogi. GPLv2.
|
|
|
+// Comments:
|
|
|
+// Options: --no-includes, --include-headers
|
|
|
|
|
|
-virtual context
|
|
|
virtual patch
|
|
|
+virtual context
|
|
|
virtual org
|
|
|
virtual report
|
|
|
|
|
@@ -23,45 +20,43 @@ virtual report
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
@depends on context@
|
|
|
-type T;
|
|
|
+expression e;
|
|
|
@@
|
|
|
|
|
|
-* (T *)
|
|
|
- \(kmalloc\|kzalloc\|kcalloc\)(...)
|
|
|
+*if (e) BUG();
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
// For patch mode
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
@depends on patch@
|
|
|
-type T;
|
|
|
+expression e;
|
|
|
@@
|
|
|
|
|
|
-- (T *)
|
|
|
- \(kmalloc\|kzalloc\|kcalloc\)(...)
|
|
|
+-if (e) BUG();
|
|
|
++BUG_ON(e);
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
// For org and report mode
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
-@r depends on org || report@
|
|
|
-type T;
|
|
|
+@r@
|
|
|
+expression e;
|
|
|
position p;
|
|
|
@@
|
|
|
|
|
|
- (T@p *)\(kmalloc\|kzalloc\|kcalloc\)(...)
|
|
|
+ if (e) BUG@p ();
|
|
|
|
|
|
@script:python depends on org@
|
|
|
p << r.p;
|
|
|
-t << r.T;
|
|
|
@@
|
|
|
|
|
|
-coccilib.org.print_safe_todo(p[0], t)
|
|
|
+coccilib.org.print_todo(p[0], "WARNING use BUG_ON")
|
|
|
|
|
|
@script:python depends on report@
|
|
|
p << r.p;
|
|
|
-t << r.T;
|
|
|
@@
|
|
|
|
|
|
-msg="WARNING: casting value returned by k[cmz]alloc to (%s *) is useless." % (t)
|
|
|
+msg="WARNING: Use BUG_ON"
|
|
|
coccilib.report.print_report(p[0], msg)
|
|
|
+
|