From patchwork Tue May 10 11:07:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niels de Vos X-Patchwork-Id: 773982 X-Patchwork-Delegate: tomi.valkeinen@nokia.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4AB9o8A007648 for ; Tue, 10 May 2011 11:09:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752603Ab1EJLJs (ORCPT ); Tue, 10 May 2011 07:09:48 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:62269 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336Ab1EJLJr (ORCPT ); Tue, 10 May 2011 07:09:47 -0400 Received: by wya21 with SMTP id 21so4571915wya.19 for ; Tue, 10 May 2011 04:09:46 -0700 (PDT) Received: by 10.227.208.202 with SMTP id gd10mr3168650wbb.23.1305025785921; Tue, 10 May 2011 04:09:45 -0700 (PDT) Received: from localhost.localdomain (cpc3-glfd3-0-0-cust917.6-2.cable.virginmedia.com [86.17.251.150]) by mx.google.com with ESMTPS id ca12sm4323542wbb.36.2011.05.10.04.09.44 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 May 2011 04:09:45 -0700 (PDT) From: Niels de Vos To: linux-omap@vger.kernel.org Cc: linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , Sanjeev Premi , Niels de Vos Subject: [PATCH V2] omap2/omapfb: make DBG() more resistant in if-else constructions Date: Tue, 10 May 2011 12:07:33 +0100 Message-Id: <1305025653-17138-1-git-send-email-ndevos@redhat.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: References: Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 10 May 2011 11:09:50 +0000 (UTC) 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 --- V2: add the missing closing } 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..456c586 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