Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1294966 > unrolled thread

[PATCH 04/14] x25: use list_for_each_entry*

Started byGeliang Tang <geliangtang@163.com>
First post2015-12-18 16:40 +0100
Last post2015-12-18 16:40 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 04/14] x25: use list_for_each_entry* Geliang Tang <geliangtang@163.com> - 2015-12-18 16:40 +0100

#1294966 — [PATCH 04/14] x25: use list_for_each_entry*

FromGeliang Tang <geliangtang@163.com>
Date2015-12-18 16:40 +0100
Subject[PATCH 04/14] x25: use list_for_each_entry*
Message-ID<qH5ip-7rE-17@gated-at.bofh.it>
Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 net/x25/x25_forward.c | 20 ++++++--------------
 net/x25/x25_link.c    | 23 ++++++-----------------
 net/x25/x25_route.c   | 29 +++++++----------------------
 3 files changed, 19 insertions(+), 53 deletions(-)

diff --git a/net/x25/x25_forward.c b/net/x25/x25_forward.c
index cf561f1..4394eb6 100644
--- a/net/x25/x25_forward.c
+++ b/net/x25/x25_forward.c
@@ -24,7 +24,6 @@ int x25_forward_call(struct x25_address *dest_addr, struct x25_neigh *from,
 {
 	struct x25_route *rt;
 	struct x25_neigh *neigh_new = NULL;
-	struct list_head *entry;
 	struct x25_forward *x25_frwd, *new_frwd;
 	struct sk_buff *skbn;
 	short same_lci = 0;
@@ -51,8 +50,7 @@ int x25_forward_call(struct x25_address *dest_addr, struct x25_neigh *from,
 	 * established LCI? It shouldn't happen, just in case..
 	 */
 	read_lock_bh(&x25_forward_list_lock);
-	list_for_each(entry, &x25_forward_list) {
-		x25_frwd = list_entry(entry, struct x25_forward, node);
+	list_for_each_entry(x25_frwd, &x25_forward_list, node) {
 		if (x25_frwd->lci == lci) {
 			pr_warn("call request for lci which is already registered!, transmitting but not registering new pair\n");
 			same_lci = 1;
@@ -97,15 +95,13 @@ out_no_route:
 int x25_forward_data(int lci, struct x25_neigh *from, struct sk_buff *skb) {
 
 	struct x25_forward *frwd;
-	struct list_head *entry;
 	struct net_device *peer = NULL;
 	struct x25_neigh *nb;
 	struct sk_buff *skbn;
 	int rc = 0;
 
 	read_lock_bh(&x25_forward_list_lock);
-	list_for_each(entry, &x25_forward_list) {
-		frwd = list_entry(entry, struct x25_forward, node);
+	list_for_each_entry(frwd, &x25_forward_list, node) {
 		if (frwd->lci == lci) {
 			/* The call is established, either side can send */
 			if (from->dev == frwd->dev1) {
@@ -136,13 +132,11 @@ out:
 
 void x25_clear_forward_by_lci(unsigned int lci)
 {
-	struct x25_forward *fwd;
-	struct list_head *entry, *tmp;
+	struct x25_forward *fwd, *tmp;
 
 	write_lock_bh(&x25_forward_list_lock);
 
-	list_for_each_safe(entry, tmp, &x25_forward_list) {
-		fwd = list_entry(entry, struct x25_forward, node);
+	list_for_each_entry_safe(fwd, tmp, &x25_forward_list, node) {
 		if (fwd->lci == lci) {
 			list_del(&fwd->node);
 			kfree(fwd);
@@ -154,13 +148,11 @@ void x25_clear_forward_by_lci(unsigned int lci)
 
 void x25_clear_forward_by_dev(struct net_device *dev)
 {
-	struct x25_forward *fwd;
-	struct list_head *entry, *tmp;
+	struct x25_forward *fwd, *tmp;
 
 	write_lock_bh(&x25_forward_list_lock);
 
-	list_for_each_safe(entry, tmp, &x25_forward_list) {
-		fwd = list_entry(entry, struct x25_forward, node);
+	list_for_each_entry_safe(fwd, tmp, &x25_forward_list, node) {
 		if ((fwd->dev1 == dev) || (fwd->dev2 == dev)){
 			list_del(&fwd->node);
 			kfree(fwd);
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
index fd5ffb2..61cc8a2 100644
--- a/net/x25/x25_link.c
+++ b/net/x25/x25_link.c
@@ -296,14 +296,11 @@ static void __x25_remove_neigh(struct x25_neigh *nb)
  */
 void x25_link_device_down(struct net_device *dev)
 {
-	struct x25_neigh *nb;
-	struct list_head *entry, *tmp;
+	struct x25_neigh *nb, *tmp;
 
 	write_lock_bh(&x25_neigh_list_lock);
 
-	list_for_each_safe(entry, tmp, &x25_neigh_list) {
-		nb = list_entry(entry, struct x25_neigh, node);
-
+	list_for_each_entry_safe(nb, tmp, &x25_neigh_list, node) {
 		if (nb->dev == dev) {
 			__x25_remove_neigh(nb);
 			dev_put(dev);
@@ -319,12 +316,9 @@ void x25_link_device_down(struct net_device *dev)
 struct x25_neigh *x25_get_neigh(struct net_device *dev)
 {
 	struct x25_neigh *nb, *use = NULL;
-	struct list_head *entry;
 
 	read_lock_bh(&x25_neigh_list_lock);
-	list_for_each(entry, &x25_neigh_list) {
-		nb = list_entry(entry, struct x25_neigh, node);
-
+	list_for_each_entry(nb, &x25_neigh_list, node) {
 		if (nb->dev == dev) {
 			use = nb;
 			break;
@@ -394,18 +388,13 @@ out_dev_put:
  */
 void __exit x25_link_free(void)
 {
-	struct x25_neigh *nb;
-	struct list_head *entry, *tmp;
+	struct x25_neigh *nb, *tmp;
 
 	write_lock_bh(&x25_neigh_list_lock);
 
-	list_for_each_safe(entry, tmp, &x25_neigh_list) {
-		struct net_device *dev;
-
-		nb = list_entry(entry, struct x25_neigh, node);
-		dev = nb->dev;
+	list_for_each_entry_safe(nb, tmp, &x25_neigh_list, node) {
 		__x25_remove_neigh(nb);
-		dev_put(dev);
+		dev_put(nb->dev);
 	}
 	write_unlock_bh(&x25_neigh_list_lock);
 }
diff --git a/net/x25/x25_route.c b/net/x25/x25_route.c
index 277c8d2..50562d7 100644
--- a/net/x25/x25_route.c
+++ b/net/x25/x25_route.c
@@ -32,14 +32,11 @@ static int x25_add_route(struct x25_address *address, unsigned int sigdigits,
 			 struct net_device *dev)
 {
 	struct x25_route *rt;
-	struct list_head *entry;
 	int rc = -EINVAL;
 
 	write_lock_bh(&x25_route_list_lock);
 
-	list_for_each(entry, &x25_route_list) {
-		rt = list_entry(entry, struct x25_route, node);
-
+	list_for_each_entry(rt, &x25_route_list, node) {
 		if (!memcmp(&rt->address, address, sigdigits) &&
 		    rt->sigdigits == sigdigits)
 			goto out;
@@ -83,14 +80,11 @@ static int x25_del_route(struct x25_address *address, unsigned int sigdigits,
 			 struct net_device *dev)
 {
 	struct x25_route *rt;
-	struct list_head *entry;
 	int rc = -EINVAL;
 
 	write_lock_bh(&x25_route_list_lock);
 
-	list_for_each(entry, &x25_route_list) {
-		rt = list_entry(entry, struct x25_route, node);
-
+	list_for_each_entry(rt, &x25_route_list, node) {
 		if (!memcmp(&rt->address, address, sigdigits) &&
 		    rt->sigdigits == sigdigits && rt->dev == dev) {
 			__x25_remove_route(rt);
@@ -108,14 +102,11 @@ static int x25_del_route(struct x25_address *address, unsigned int sigdigits,
  */
 void x25_route_device_down(struct net_device *dev)
 {
-	struct x25_route *rt;
-	struct list_head *entry, *tmp;
+	struct x25_route *rt, *tmp;
 
 	write_lock_bh(&x25_route_list_lock);
 
-	list_for_each_safe(entry, tmp, &x25_route_list) {
-		rt = list_entry(entry, struct x25_route, node);
-
+	list_for_each_entry_safe(rt, tmp, &x25_route_list, node) {
 		if (rt->dev == dev)
 			__x25_remove_route(rt);
 	}
@@ -154,13 +145,10 @@ struct net_device *x25_dev_get(char *devname)
 struct x25_route *x25_get_route(struct x25_address *addr)
 {
 	struct x25_route *rt, *use = NULL;
-	struct list_head *entry;
 
 	read_lock_bh(&x25_route_list_lock);
 
-	list_for_each(entry, &x25_route_list) {
-		rt = list_entry(entry, struct x25_route, node);
-
+	list_for_each_entry(rt, &x25_route_list, node) {
 		if (!memcmp(&rt->address, addr, rt->sigdigits)) {
 			if (!use)
 				use = rt;
@@ -214,13 +202,10 @@ out:
  */
 void __exit x25_route_free(void)
 {
-	struct x25_route *rt;
-	struct list_head *entry, *tmp;
+	struct x25_route *rt, *tmp;
 
 	write_lock_bh(&x25_route_list_lock);
-	list_for_each_safe(entry, tmp, &x25_route_list) {
-		rt = list_entry(entry, struct x25_route, node);
+	list_for_each_entry_safe(rt, tmp, &x25_route_list, node)
 		__x25_remove_route(rt);
-	}
 	write_unlock_bh(&x25_route_list_lock);
 }
-- 
2.5.0


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web