Coccinelle: Script to replace if and BUG with BUG_ON
PATCH 1/1 Coccinelle: Script to replace if and BUG with BUG_ON
This script detects 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.
--- scripts/coccinelle/misc/bugon.cocci | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 scripts/coccinelle/misc/bugon.cocci
scripts/coccinelle/misc/bugon.cocci new file +62 -0
@@ -0,0 +1,62 @@ +/// Use BUG_ON instead of a if condition followed by BUG. +/// +//# 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 patch +virtual context +virtual org +virtual report + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + + at depends on context@ +expression e; +@@ + +*if (e) BUG(); + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + + at depends on patch@ +expression e; +@@ + +-if (e) BUG(); ++BUG_ON(e); + +//---------------------------------------------------------- +// For org and report mode +//---------------------------------------------------------- + + at r@ +expression e; +position p; +@@ + + if (e) BUG at p (); + + at script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING use BUG_ON") + +@script:python depends on report@ +p << r.p; +@@ + +msg="WARNING: Use BUG_ON" +coccilib.report.print_report(p[0], msg) +
Signature · 1 line
1.9.1
Quoted 6 lines · Himangi Saraogi
This script detects cases where
BUG()follows an if condition on an expression and replaces the if condition andBUG()with aBUG_ONhaving the conditional expression of the if statement as argument.Signed-off-by Himangi Saraogi <[email protected]>Acked-by Julia Lawall <[email protected]>
Is this a result of some internal review, or where does Julia's Acked-by come from? I'm just wondering, because I haven't seen any previous version of this patch.
Thanks,
Michal
Quoted 11 lines · Michal Marek
Quoted 6 lines · Himangi Saraogi
This script detects cases where
BUG()follows an if condition on an expression and replaces the if condition andBUG()with aBUG_ONhaving the conditional expression of the if statement as argument.Signed-off-by Himangi Saraogi <[email protected]>Acked-by Julia Lawall <[email protected]>Is this a result of some internal review, or where does Julia's Acked-by come from? I'm just wondering, because I haven't seen any previous version of this patch.
She sent it to me first. It's OK with me.
julia
Quoted 9 lines · Julia Lawall
Quoted 5 lines · Michal Marek
Quoted 4 lines · Himangi Saraogi
This script detects cases where
BUG()follows an if condition on an expression and replaces the if condition andBUG()with aBUG_ONhaving the conditional expression of the if statement as argument.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Signed-off-by Himangi Saraogi <[email protected]>Acked-by Julia Lawall <[email protected]>Is this a result of some internal review, or where does Julia's Acked-by come from? I'm just wondering, because I haven't seen any previous version of this patch.
She sent it to me first. It's OK with me.
OK, thanks for confirming. I'm going to merge this and the previous patches by Himangi.
Michal