[ovs-dev] [PATCH 04/16] datapath: Don't read net namespace on kernels that don't use them.

Ben Pfaff blp at nicira.com
Tue Apr 13 17:04:29 UTC 2010


On Tue, Apr 13, 2010 at 10:41:06AM -0400, Jesse Gross wrote:
> Use macros to eliminate the network namespace argument before it
> gets to the compiler.  This allows us to specify a namespace on
> kernels that know about them and prevent the compiler from complaining
> on kernels that don't.

I'm surprised that this is necessary.  I didn't think that the kernel
compiler flags were set up to complain about unused arguments.  But the
change seems OK.

One nit: The cast to (void) below should be unnecessary since
rtnl_notify() as we define it already has a "void" return type.

>  /* No 'net' parameter in these versions. */
>  #define rtnl_notify(skb, net, pid, group, nlh, flags) \
> -	((void) (net), (void) rtnl_notify(skb, pid, group, nlh, flags))
> +		    ((void) rtnl_notify((skb), (pid), (group), (nlh), (flags)))

Another nit: I know that paranoid parenthesization is customary for C
macros, but it really isn't necessary for function arguments, because
macro arguments cannot contain commas (outside parentheses)[1] and the
extra parentheses make everything harder to read:

>  /* Make the return type effectively 'void' to match Linux 2.6.30+. */
>  #define rtnl_notify(skb, net, pid, group, nlh, flags) \
> -	((void) rtnl_notify(skb, net, pid, group, nlh, flags))
> +	((void) rtnl_notify((skb), (net), (pid), (group), (nlh), (flags)))
>  #endif
>  
>  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)

[1] Well, you can do something like
       #define COMMA ,
       #define f(a,b) a
       f(1 COMMA 2, 3)
    which will expand to
       1 , 2
    but anyone who does that deserves what he gets in my opinion.




More information about the dev mailing list