From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932708AbbLRPej (ORCPT ); Fri, 18 Dec 2015 10:34:39 -0500 Received: from m50-135.163.com ([123.125.50.135]:53482 "EHLO m50-135.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754390AbbLRPee (ORCPT ); Fri, 18 Dec 2015 10:34:34 -0500 From: Geliang Tang To: "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy Cc: Geliang Tang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/14] ipv4, ipv6: use list_for_each_entry* Date: Fri, 18 Dec 2015 23:33:27 +0800 Message-Id: <0167bba2ecf8c4fcb6b0b3135a4e957309986498.1450451516.git.geliangtang@163.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: X-CM-TRANSID: D9GowACnVuRcJ3RWCUKjAw--.24765S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxWF1ftFy8ZF48tw43Cr13twb_yoWrXr47pF 1Yy3W3Jw4xW348uw4xJF40kr1agw47tay293yfuw1SkF1DJr4Yqayxtr15XFyYyrWIkw4f WFWjgr43Cw48ArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UweOXUUUUU= X-Originating-IP: [116.77.150.30] X-CM-SenderInfo: 5jhoxtpqjwt0rj6rljoofrz/1tbiNR7UmVSIK4K9qwAAsF Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use list_for_each_entry*() instead of list_for_each*() to simplify the code. Signed-off-by: Geliang Tang --- net/ipv4/af_inet.c | 6 ++---- net/ipv4/tcp_output.c | 6 ++---- net/ipv6/addrconf.c | 8 +++----- net/ipv6/af_inet6.c | 7 ++----- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 11c4ca1..bb11ec1 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1028,7 +1028,6 @@ static struct inet_protosw inetsw_array[] = void inet_register_protosw(struct inet_protosw *p) { - struct list_head *lh; struct inet_protosw *answer; int protocol = p->protocol; struct list_head *last_perm; @@ -1040,14 +1039,13 @@ void inet_register_protosw(struct inet_protosw *p) /* If we are trying to override a permanent protocol, bail. */ last_perm = &inetsw[p->type]; - list_for_each(lh, &inetsw[p->type]) { - answer = list_entry(lh, struct inet_protosw, list); + list_for_each_entry(answer, &inetsw[p->type], list) { /* Check only the non-wild match. */ if ((INET_PROTOSW_PERMANENT & answer->flags) == 0) break; if (protocol == answer->protocol) goto out_permanent; - last_perm = lh; + last_perm = &answer->list; } /* Add the new entry after the last permanent entry if any, so that diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index a800cee..8810694 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -751,16 +751,14 @@ static void tcp_tasklet_func(unsigned long data) struct tsq_tasklet *tsq = (struct tsq_tasklet *)data; LIST_HEAD(list); unsigned long flags; - struct list_head *q, *n; - struct tcp_sock *tp; + struct tcp_sock *tp, *n; struct sock *sk; local_irq_save(flags); list_splice_init(&tsq->head, &list); local_irq_restore(flags); - list_for_each_safe(q, n, &list) { - tp = list_entry(q, struct tcp_sock, tsq_node); + list_for_each_entry_safe(tp, n, &list, tsq_node) { list_del(&tp->tsq_node); sk = (struct sock *)tp; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 7082fb7..e293647 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -865,21 +865,19 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) static void ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) { - struct list_head *p; + struct inet6_ifaddr *ifa; int ifp_scope = ipv6_addr_src_scope(&ifp->addr); /* * Each device address list is sorted in order of scope - * global before linklocal. */ - list_for_each(p, &idev->addr_list) { - struct inet6_ifaddr *ifa - = list_entry(p, struct inet6_ifaddr, if_list); + list_for_each_entry(ifa, &idev->addr_list, if_list) { if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) break; } - list_add_tail(&ifp->if_list, p); + list_add_tail(&ifp->if_list, &ifa->if_list); } static u32 inet6_addr_hash(const struct in6_addr *addr) diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 8ec0df7..a4fb172 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -568,7 +568,6 @@ static const struct net_proto_family inet6_family_ops = { int inet6_register_protosw(struct inet_protosw *p) { - struct list_head *lh; struct inet_protosw *answer; struct list_head *last_perm; int protocol = p->protocol; @@ -584,14 +583,12 @@ int inet6_register_protosw(struct inet_protosw *p) answer = NULL; ret = -EPERM; last_perm = &inetsw6[p->type]; - list_for_each(lh, &inetsw6[p->type]) { - answer = list_entry(lh, struct inet_protosw, list); - + list_for_each_entry(answer, &inetsw6[p->type], list) { /* Check only the non-wild match. */ if (INET_PROTOSW_PERMANENT & answer->flags) { if (protocol == answer->protocol) break; - last_perm = lh; + last_perm = &answer->list; } answer = NULL; -- 2.5.0