Message ID | 1354634875-5182-6-git-send-email-benjamin.tissoires@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Delegated to: | Jiri Kosina |
Headers | show |
On Tue, 4 Dec 2012 16:27:46 +0100, Benjamin Tissoires wrote: > This avoids the problematic case: > > if (condition) > i2c_hid_dbg(ihid, "Blah blah %d\n", i); > else > do_something_very_important(); > > Which looks correct, however with the previous macro definition, > this expands to the unexpected: > > if (condition) { > if (debug) \ > dev_printk(KERN_DEBUG, &ihid->client->dev, > "Blah blah %d\n", i); > else > do_something_very_important(); > } > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> > --- > drivers/hid/i2c-hid/i2c-hid.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c > index 9ee6555..54950be 100644 > --- a/drivers/hid/i2c-hid/i2c-hid.c > +++ b/drivers/hid/i2c-hid/i2c-hid.c > @@ -50,9 +50,11 @@ static bool debug; > module_param(debug, bool, 0444); > MODULE_PARM_DESC(debug, "print a lot of debug information"); > > -#define i2c_hid_dbg(ihid, fmt, arg...) \ > - if (debug) \ > - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg) > +#define i2c_hid_dbg(ihid, fmt, arg...) \ > +do { \ > + if (debug) \ > + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ > +} while (0) > > struct i2c_hid_desc { > __le16 wHIDDescLength; Reviewed-by: Jean Delvare <khali@linux-fr.org>
On Tue, 4 Dec 2012, Jean Delvare wrote: > > This avoids the problematic case: > > > > if (condition) > > i2c_hid_dbg(ihid, "Blah blah %d\n", i); > > else > > do_something_very_important(); > > > > Which looks correct, however with the previous macro definition, > > this expands to the unexpected: > > > > if (condition) { > > if (debug) \ > > dev_printk(KERN_DEBUG, &ihid->client->dev, > > "Blah blah %d\n", i); > > else > > do_something_very_important(); > > } > > > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> > > --- > > drivers/hid/i2c-hid/i2c-hid.c | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c > > index 9ee6555..54950be 100644 > > --- a/drivers/hid/i2c-hid/i2c-hid.c > > +++ b/drivers/hid/i2c-hid/i2c-hid.c > > @@ -50,9 +50,11 @@ static bool debug; > > module_param(debug, bool, 0444); > > MODULE_PARM_DESC(debug, "print a lot of debug information"); > > > > -#define i2c_hid_dbg(ihid, fmt, arg...) \ > > - if (debug) \ > > - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg) > > +#define i2c_hid_dbg(ihid, fmt, arg...) \ > > +do { \ > > + if (debug) \ > > + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ > > +} while (0) > > > > struct i2c_hid_desc { > > __le16 wHIDDescLength; > > Reviewed-by: Jean Delvare <khali@linux-fr.org> Applied.
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 9ee6555..54950be 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -50,9 +50,11 @@ static bool debug; module_param(debug, bool, 0444); MODULE_PARM_DESC(debug, "print a lot of debug information"); -#define i2c_hid_dbg(ihid, fmt, arg...) \ - if (debug) \ - dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg) +#define i2c_hid_dbg(ihid, fmt, arg...) \ +do { \ + if (debug) \ + dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \ +} while (0) struct i2c_hid_desc { __le16 wHIDDescLength;
This avoids the problematic case: if (condition) i2c_hid_dbg(ihid, "Blah blah %d\n", i); else do_something_very_important(); Which looks correct, however with the previous macro definition, this expands to the unexpected: if (condition) { if (debug) \ dev_printk(KERN_DEBUG, &ihid->client->dev, "Blah blah %d\n", i); else do_something_very_important(); } Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> --- drivers/hid/i2c-hid/i2c-hid.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)