diff mbox

openvswitch: using nla_for_each_X to simplify the code

Message ID CAPgLHd8hY-nZWaG-meEk1MtY5Rj_26Lj1bxH=jtn20jxni+U8g@mail.gmail.com
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

Wei Yongjun Oct. 7, 2012, 1:42 p.m. UTC
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Using nla_for_each_nested() or nla_for_each_attr()
to simplify the code.

dpatch engine is used to auto generate this patch.
(https://github.com/weiyj/dpatch)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 net/openvswitch/actions.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)



--
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

Comments

Jesse Gross Oct. 7, 2012, 6:30 p.m. UTC | #1
On Sun, Oct 7, 2012 at 6:42 AM, Wei Yongjun <weiyj.lk@gmail.com> wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>
> Using nla_for_each_nested() or nla_for_each_attr()
> to simplify the code.
>
> dpatch engine is used to auto generate this patch.
> (https://github.com/weiyj/dpatch)
>
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

It is done this way intentionally to avoid checks on the fast path for
conditions that have already been validated.
--
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 Oct. 7, 2012, 6:33 p.m. UTC | #2
From: Jesse Gross <jesse@nicira.com>
Date: Sun, 7 Oct 2012 11:30:51 -0700

> On Sun, Oct 7, 2012 at 6:42 AM, Wei Yongjun <weiyj.lk@gmail.com> wrote:
>> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>>
>> Using nla_for_each_nested() or nla_for_each_attr()
>> to simplify the code.
>>
>> dpatch engine is used to auto generate this patch.
>> (https://github.com/weiyj/dpatch)
>>
>> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> It is done this way intentionally to avoid checks on the fast path for
> conditions that have already been validated.

Agreed, I'm not applying this patch.
--
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/openvswitch/actions.c b/net/openvswitch/actions.c
index 0811447..b67594f 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -288,8 +288,7 @@  static int output_userspace(struct datapath *dp, struct sk_buff *skb,
 	upcall.userdata = NULL;
 	upcall.portid = 0;
 
-	for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
-		 a = nla_next(a, &rem)) {
+	nla_for_each_nested(a, attr, rem) {
 		switch (nla_type(a)) {
 		case OVS_USERSPACE_ATTR_USERDATA:
 			upcall.userdata = a;
@@ -311,8 +310,7 @@  static int sample(struct datapath *dp, struct sk_buff *skb,
 	const struct nlattr *a;
 	int rem;
 
-	for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
-		 a = nla_next(a, &rem)) {
+	nla_for_each_nested(a, attr, rem) {
 		switch (nla_type(a)) {
 		case OVS_SAMPLE_ATTR_PROBABILITY:
 			if (net_random() >= nla_get_u32(a))
@@ -371,8 +369,7 @@  static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
 	const struct nlattr *a;
 	int rem;
 
-	for (a = attr, rem = len; rem > 0;
-	     a = nla_next(a, &rem)) {
+	nla_for_each_attr(a, attr, len, rem) {
 		int err = 0;
 
 		if (prev_port != -1) {