mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Satyam Sharma" <satyam.sharma@gmail.com>
To: "Lars Ellenberg" <lars.ellenberg@linbit.com>
Cc: "Jens Axboe" <jens.axboe@oracle.com>,
	"Andi Kleen" <andi@firstfloor.org>,
	"Andrew Morton" <akpm@osdl.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [DRIVER SUBMISSION] DRBD wants to go mainline
Date: Sun, 22 Jul 2007 21:20:06 +0530	[thread overview]
Message-ID: <a781481a0707220850q4d1a176ds350819637b46e54d@mail.gmail.com> (raw)
In-Reply-To: <a781481a0707220831y67bcd64k34d52c3150c27dc1@mail.gmail.com>

On 7/22/07, Satyam Sharma <satyam.sharma@gmail.com> wrote:
> On 7/22/07, Lars Ellenberg <lars.ellenberg@linbit.com> wrote:
> [...]
> >  8 ERROR: Macros with multiple statements should be enclosed in a do - while loop
>
> You don't want to break if-else constructs.
>
> >  1 ERROR: Macros with complex values should be enclosed in parenthesis
>
> I'm not sure know when / why checkpatch.pl reports this. I don't want to
> pull your tree so can't check for myself, but note some obvious rules:
>
> 1. Macro definition must always include parenthesis around the entire
> definition (unless it's a do { somehting; } while (0) kind of macro).
> 2. Use parenthesis around wherever it uses the passed argument(s).
>
> >     these are "netlink packet definition language" in drbd_nl.h,
> >     which is sort of clean, and preprocessor magic in drbd_nl.c.
> >     suggestions how to handle this cleanly,
> >     without making it more ugly?
> >     autogenerate code by other means?
> >     write it out by hand, and lose the nice and clean drbd_nl.h?
>
> 1. Open-code it if it is trivial enough and there's no point
> obfuscating anything.
> 2. Consider making the macro a function. Probably inline, most probably not.
> 3. Macros must NOT evaluate the passed argument twice -- consider the
> possible damages of someone who doesn't know it's a macro and therefore
> passing in an expression that has side-effects (*boom, crash*).


Some more macro tips for you:

If the macro contains multiple statements but must also return a value
to the caller (i.e. say it can appear on RHS of an assignment), use the:

#define foo ({ something; lastthing; })

kind of idiom. So the return value of the last statement ("lastthing;"
above) in there (obviously) becomes the return value of the whole
macro. So if you need to define an internal variable inside the macro,
and the return value of the macro should be that internal variable itself,
use the:
#define bar ({ int __mvar; __mvar = something; otherstuff; __mvar; })
kind of idiom.

Of course, if you really try to pull off the above stunts, we'll probably
ask you to go back and make that a proper function in the first place :-)

  reply	other threads:[~2007-07-22 15:50 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-21 20:38 Lars Ellenberg
2007-07-21 21:17 ` Jan Engelhardt
2007-07-21 22:43   ` Lars Ellenberg
2007-07-22  9:06     ` Jan Engelhardt
2007-07-22 14:03       ` Lars Ellenberg
2007-07-27 18:46     ` Pavel Machek
2007-07-30 19:35       ` Lars Ellenberg
2007-07-30 19:41         ` Jan Engelhardt
2007-07-21 21:34 ` Jesper Juhl
2007-07-21 23:50 ` Andi Kleen
2007-07-22  5:52   ` Jens Axboe
2007-07-22 13:58     ` Lars Ellenberg
2007-07-22 14:49       ` Sam Ravnborg
2007-07-22 14:56       ` Andi Kleen
2007-07-22 15:31       ` Satyam Sharma
2007-07-22 15:50         ` Satyam Sharma [this message]
2007-07-22 16:13         ` Stefan Richter
2007-07-22  6:09   ` Lars Ellenberg
2007-07-22  8:52     ` Sam Ravnborg
2007-07-22  9:05       ` Pekka Enberg
2007-07-22  9:00     ` Pekka Enberg
2007-07-23  1:32 ` Kyle Moffett
2007-07-23  8:49   ` Christoph Hellwig
2007-07-23  9:00     ` Sam Ravnborg
2007-07-23  9:01       ` Christoph Hellwig
2007-07-23  9:19         ` Sam Ravnborg
2007-07-23 11:08           ` Lars Ellenberg
2007-07-23 13:32   ` Lars Ellenberg
2007-07-23 13:37     ` Jens Axboe
2007-07-23 21:13       ` Lars Ellenberg
2007-07-23 13:40     ` Satyam Sharma
2007-07-23 21:19       ` Lars Ellenberg
2007-07-24  7:36         ` Jens Axboe
2007-07-24 23:11         ` Satyam Sharma
2007-07-25  9:46           ` Lars Ellenberg
2007-07-25 12:12             ` Satyam Sharma
2007-07-26  2:03               ` david
2007-07-26  3:43                 ` Kyle Moffett
2007-07-26  9:17                   ` Evgeniy Polyakov
2007-07-24  0:48     ` Kyle Moffett
2007-07-23 20:59 ` Jesper Juhl
2007-07-22  9:54 Tomasz Chmielewski

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=a781481a0707220850q4d1a176ds350819637b46e54d@mail.gmail.com \
    --to=satyam.sharma@gmail.com \
    --cc=akpm@osdl.org \
    --cc=andi@firstfloor.org \
    --cc=jens.axboe@oracle.com \
    --cc=lars.ellenberg@linbit.com \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®