From: Niels de Vos <ndevos@redhat.com>
To: linux-omap@vger.kernel.org
Cc: linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Niels de Vos <ndevos@redhat.com>
Subject: [PATCH] omap2/omapfb: make DBG() more resistant in if-else constructions
Date: Tue, 10 May 2011 09:20:49 +0000 [thread overview]
Message-ID: <1305019249-9898-1-git-send-email-ndevos@redhat.com> (raw)
When DBG() is used in a simple if-else, the resulting code path
currently depends on the definition of DBG(). Inserting the statement in
a "do { ... } while (0)" prevents this possible misuse.
Signed-off-by: Niels de Vos <ndevos@redhat.com>
---
Note, I have not found any offenders, but a mistake can easily be made.
The following example shows what can go wrong if little intention is
paid to the definition of the DBG() macro.
Example:
if something_went_wrong()
DBG("oh no, something went wrong!\n");
else
printk("all went fine\n");
Old result where the else is placed inside the first if-statment:
if something_went_wrong() {
if (omapfb_debug) {
printk(KERN_DEBUG "oh no, something went wrong!\n");
} else {
printk("all went fine\n");
}
}
New result where the else is an alternative to the first if-statement:
if something_went_wrong() {
do {
if (omapfb_debug)
printk(KERN_DEBUG "oh no, something went wrong!\n");
} while (0);
} else {
printk("all went fine\n");
}
---
drivers/video/omap2/omapfb/omapfb.h | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/video/omap2/omapfb/omapfb.h b/drivers/video/omap2/omapfb/omapfb.h
index 1305fc9..a01b0bb 100644
--- a/drivers/video/omap2/omapfb/omapfb.h
+++ b/drivers/video/omap2/omapfb/omapfb.h
@@ -34,8 +34,10 @@
#ifdef DEBUG
extern unsigned int omapfb_debug;
#define DBG(format, ...) \
- if (omapfb_debug) \
- printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__)
+ do { \
+ if (omapfb_debug) \
+ printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
+ while (0)
#else
#define DBG(format, ...)
#endif
--
1.7.4.4
next reply other threads:[~2011-05-10 9:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-10 9:20 Niels de Vos [this message]
2011-05-10 9:42 ` [PATCH] omap2/omapfb: make DBG() more resistant in if-else constructions Geert Uytterhoeven
2011-05-10 10:57 ` Niels de Vos
2011-05-10 11:07 ` [PATCH V2] " Niels de Vos
2011-05-10 12:16 ` [PATCH V2] omap2/omapfb: make DBG() more resistant in if-else Tomi Valkeinen
2011-05-10 12:08 ` [PATCH] " Tomi Valkeinen
2011-05-10 12:14 ` [PATCH] omap2/omapfb: make DBG() more resistant in if-else constructions Geert Uytterhoeven
2011-05-10 9:49 ` [PATCH] omap2/omapfb: make DBG() more resistant in if-else Premi, Sanjeev
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=1305019249-9898-1-git-send-email-ndevos@redhat.com \
--to=ndevos@redhat.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).