diff mbox

[net-next,6/6] net_sched: make macro be enclosed in parenthesis

Message ID 1386680134-85452-7-git-send-email-yangyingliang@huawei.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Yang Yingliang Dec. 10, 2013, 12:55 p.m. UTC
Macros with complex values should be enclosed in parenthesis

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 net/sched/em_meta.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

David Laight Dec. 10, 2013, 1:01 p.m. UTC | #1
>  #define SKIP_NONLOCAL(skb)			\
> +({						\
>  	if (unlikely(skb->sk == NULL)) {	\
>  		*err = -1;			\
>  		return;				\
> -	}
> +	}					\
> +})

That one should be lined up against the fence and shot :-)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yang Yingliang Dec. 11, 2013, 2:16 a.m. UTC | #2
On 2013/12/10 21:01, David Laight wrote:
>>  #define SKIP_NONLOCAL(skb)			\
>> +({						\
>>  	if (unlikely(skb->sk == NULL)) {	\
>>  		*err = -1;			\
>>  		return;				\
>> -	}
>> +	}					\
>> +})
> 
> That one should be lined up against the fence and shot :-)
> 
> 

Hmm, not fully understand, did you mean that:

#define SKIP_NONLOCAL(skb) ({			\
 	if (unlikely(skb->sk == NULL)) {	\
 		*err = -1;			\
		return;				\
	}					\
})

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Dec. 11, 2013, 3:49 a.m. UTC | #3
From: Yang Yingliang <yangyingliang@huawei.com>
Date: Tue, 10 Dec 2013 20:55:34 +0800

> Macros with complex values should be enclosed in parenthesis
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  net/sched/em_meta.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
> index e5cef956..852cd62 100644
> --- a/net/sched/em_meta.c
> +++ b/net/sched/em_meta.c
> @@ -272,10 +272,12 @@ META_COLLECTOR(int_rtiif)
>   **************************************************************************/
>  
>  #define SKIP_NONLOCAL(skb)			\
> +({						\
>  	if (unlikely(skb->sk == NULL)) {	\
>  		*err = -1;			\
>  		return;				\
> -	}
> +	}					\
> +})

I can't apply this.

First of all, "({ })" is for statements that evaluate to an lvalue,
this macro does not.

Second of all, and more importantly, this macro needs to be eliminated
entirely.  It completely hides control flow, and in the past we've
killed macros which do this such as the old netlink attribute
builders.

The control flow should be inlined and expanded explicitly in the
code so that someone who reads it can tell the control flow can
be changed by the statement.  Compare:

	SKIP_NONLOCAL(skb)

to:

	if (skip_nonlocal(skb)) {
		*err = -1;
		return;
	}
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Laight Dec. 11, 2013, 10:20 a.m. UTC | #4
> From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org] On Behalf Of David Miller
> From: Yang Yingliang <yangyingliang@huawei.com>
> Date: Tue, 10 Dec 2013 20:55:34 +0800
> 
> > Macros with complex values should be enclosed in parenthesis
> >
> > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > ---
> >  net/sched/em_meta.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
> > index e5cef956..852cd62 100644
> > --- a/net/sched/em_meta.c
> > +++ b/net/sched/em_meta.c
> > @@ -272,10 +272,12 @@ META_COLLECTOR(int_rtiif)
> >   **************************************************************************/
> >
> >  #define SKIP_NONLOCAL(skb)			\
> > +({						\
> >  	if (unlikely(skb->sk == NULL)) {	\
> >  		*err = -1;			\
> >  		return;				\
> > -	}
> > +	}					\
> > +})
> 
> I can't apply this.
> 
> First of all, "({ })" is for statements that evaluate to an lvalue,
> this macro does not.
> 
> Second of all, and more importantly, this macro needs to be eliminated
> entirely.  It completely hides control flow, and in the past we've
> killed macros which do this such as the old netlink attribute
> builders.
> 
> The control flow should be inlined and expanded explicitly in the
> code so that someone who reads it can tell the control flow can
> be changed by the statement.  Compare:
> 
> 	SKIP_NONLOCAL(skb)
> 
> to:
> 
> 	if (skip_nonlocal(skb)) {
> 		*err = -1;
> 		return;
> 	}

Or:
	if (!skb->sk)
		goto no_sk;
	...
	return;

no_sk:
	*err = -1;
	return;

Actually WTF is a void function doing having an 'int *err' argument?
These should just be:
	if (!skb->sk)
		return -1;

	David



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index e5cef956..852cd62 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -272,10 +272,12 @@  META_COLLECTOR(int_rtiif)
  **************************************************************************/
 
 #define SKIP_NONLOCAL(skb)			\
+({						\
 	if (unlikely(skb->sk == NULL)) {	\
 		*err = -1;			\
 		return;				\
-	}
+	}					\
+})
 
 META_COLLECTOR(int_sk_family)
 {