From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Julia Lawall <Julia.Lawall@lip6.fr>,
Gilles Muller <Gilles.Muller@lip6.fr>,
Nicolas Palix <nicolas.palix@imag.fr>,
Michal Marek <mmarek@suse.cz>
Cc: linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH/RFC] coccinelle: replace 0/1 with false/true in functions returning bool
Date: Fri, 9 Aug 2013 16:15:46 +0000 [thread overview]
Message-ID: <1376064946-20232-1-git-send-email-linux@rasmusvillemoes.dk> (raw)
This semantic patch replaces "return {0,1};" with "return
{false,true};" in functions returning bool. There doesn't seem to be
any false positives, but some whitespace mangling is happening, for
example:
diff -u -p a/block/blk-throttle.c b/block/blk-throttle.c
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -734,9 +734,7 @@ static inline void throtl_extend_slice(s
static bool throtl_slice_used(struct throtl_grp *tg, bool rw)
{
if (time_in_range(jiffies, tg->slice_start[rw], tg->slice_end[rw]))
- return 0;
-
- return 1;
+ return false;return true;
}
Is there a way to prevent this, or is this the kind of thing which
must be handled in post-processing?
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
scripts/coccinelle/misc/boolreturn.cocci | 51 ++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 scripts/coccinelle/misc/boolreturn.cocci
diff --git a/scripts/coccinelle/misc/boolreturn.cocci b/scripts/coccinelle/misc/boolreturn.cocci
new file mode 100644
index 0000000..e6ece0d
--- /dev/null
+++ b/scripts/coccinelle/misc/boolreturn.cocci
@@ -0,0 +1,51 @@
+/// Return statements in functions returning bool should use
+/// true/false instead of 1/0.
+//
+
+virtual patch
+virtual report
+
+
+@r1 depends on patch@
+identifier fn;
+typedef bool;
+symbol false;
+symbol true;
+@@
+
+bool fn ( ... )
+{
+...
+(
+- return 0;
++ return false;
+|
+- return 1;
++ return true;
+)
+...
+}
+
+@r2 depends on !patch@
+identifier fn;
+position p;
+@@
+
+bool fn ( ... )
+{
+ ...
+(
+* return 0@p ;
+|
+* return 1@p ;
+)
+ ...
+}
+
+
+@script:python depends on report@
+p << r2.p;
+fn << r2.fn;
+@@
+
+coccilib.report.print_report(p[0], "WARNING: return of 0/1 in function '%s' with return type bool" % fn)
--
1.7.9.5
next reply other threads:[~2013-08-09 16:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-09 16:15 Rasmus Villemoes [this message]
2013-08-09 16:18 ` Julia Lawall
2013-08-09 17:59 ` [PATCH v2] " Rasmus Villemoes
2013-08-11 21:05 ` [PATCH v3] " Rasmus Villemoes
2013-08-11 21:16 ` Julia Lawall
2013-08-13 20:45 ` Michal Marek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1376064946-20232-1-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=Gilles.Muller@lip6.fr \
--cc=Julia.Lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.cz \
--cc=nicolas.palix@imag.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®