aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPavel Emelianov <xemul@openvz.org>2007-05-03 18:13:45 -0400
committerDavid S. Miller <davem@davemloft.net>2007-05-03 18:13:45 -0400
commit7562f876cd93800f2f8c89445f2a563590b24e09 (patch)
tree78a34c011af275efa0d55ba59c3bd49b771dd533 /net
parent03fba0479600114f32d29eee74ca3eaa364606bf (diff)
[NET]: Rework dev_base via list_head (v3)
Cleanup of dev_base list use, with the aim to simplify making device list per-namespace. In almost every occasion, use of dev_base variable and dev->next pointer could be easily replaced by for_each_netdev loop. A few most complicated places were converted to using first_netdev()/next_netdev(). Signed-off-by: Pavel Emelianov <xemul@openvz.org> Acked-by: Kirill Korotaev <dev@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/8021q/vlan.c3
-rw-r--r--net/8021q/vlanproc.c36
-rw-r--r--net/bridge/br_if.c4
-rw-r--r--net/bridge/br_ioctl.c4
-rw-r--r--net/bridge/br_netlink.c3
-rw-r--r--net/core/dev.c84
-rw-r--r--net/core/dev_mcast.c5
-rw-r--r--net/core/rtnetlink.c7
-rw-r--r--net/decnet/af_decnet.c11
-rw-r--r--net/decnet/dn_dev.c85
-rw-r--r--net/decnet/dn_fib.c2
-rw-r--r--net/decnet/dn_route.c14
-rw-r--r--net/ipv4/devinet.c17
-rw-r--r--net/ipv4/igmp.c15
-rw-r--r--net/ipv4/ipconfig.c2
-rw-r--r--net/ipv6/addrconf.c28
-rw-r--r--net/ipv6/anycast.c17
-rw-r--r--net/ipv6/mcast.c15
-rw-r--r--net/llc/llc_core.c10
-rw-r--r--net/netrom/nr_route.c5
-rw-r--r--net/rose/rose_route.c8
-rw-r--r--net/sched/sch_api.c7
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/tipc/eth_media.c12
24 files changed, 214 insertions, 182 deletions
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index c0c7bb8e9f07..bd93c45778d4 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -117,8 +117,7 @@ static void __exit vlan_cleanup_devices(void)
117 struct net_device *dev, *nxt; 117 struct net_device *dev, *nxt;
118 118
119 rtnl_lock(); 119 rtnl_lock();
120 for (dev = dev_base; dev; dev = nxt) { 120 for_each_netdev_safe(dev, nxt) {
121 nxt = dev->next;
122 if (dev->priv_flags & IFF_802_1Q_VLAN) { 121 if (dev->priv_flags & IFF_802_1Q_VLAN) {
123 unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev, 122 unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
124 VLAN_DEV_INFO(dev)->vlan_id); 123 VLAN_DEV_INFO(dev)->vlan_id);
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index 5e24f72602a1..d216a64421cd 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -237,13 +237,9 @@ int vlan_proc_rem_dev(struct net_device *vlandev)
237 * The following few functions build the content of /proc/net/vlan/config 237 * The following few functions build the content of /proc/net/vlan/config
238 */ 238 */
239 239
240/* starting at dev, find a VLAN device */ 240static inline int is_vlan_dev(struct net_device *dev)
241static struct net_device *vlan_skip(struct net_device *dev)
242{ 241{
243 while (dev && !(dev->priv_flags & IFF_802_1Q_VLAN)) 242 return dev->priv_flags & IFF_802_1Q_VLAN;
244 dev = dev->next;
245
246 return dev;
247} 243}
248 244
249/* start read of /proc/net/vlan/config */ 245/* start read of /proc/net/vlan/config */
@@ -257,19 +253,35 @@ static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
257 if (*pos == 0) 253 if (*pos == 0)
258 return SEQ_START_TOKEN; 254 return SEQ_START_TOKEN;
259 255
260 for (dev = vlan_skip(dev_base); dev && i < *pos; 256 for_each_netdev(dev) {
261 dev = vlan_skip(dev->next), ++i); 257 if (!is_vlan_dev(dev))
258 continue;
259
260 if (i++ == *pos)
261 return dev;
262 }
262 263
263 return (i == *pos) ? dev : NULL; 264 return NULL;
264} 265}
265 266
266static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos) 267static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
267{ 268{
269 struct net_device *dev;
270
268 ++*pos; 271 ++*pos;
269 272
270 return vlan_skip((v == SEQ_START_TOKEN) 273 dev = (struct net_device *)v;
271 ? dev_base 274 if (v == SEQ_START_TOKEN)
272 : ((struct net_device *)v)->next); 275 dev = net_device_entry(&dev_base_head);
276
277 for_each_netdev_continue(dev) {
278 if (!is_vlan_dev(dev))
279 continue;
280
281 return dev;
282 }
283
284 return NULL;
273} 285}
274 286
275static void vlan_seq_stop(struct seq_file *seq, void *v) 287static void vlan_seq_stop(struct seq_file *seq, void *v)
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 690573bbf012..849deaf14108 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -475,11 +475,9 @@ void __exit br_cleanup_bridges(void)
475 struct net_device *dev, *nxt; 475 struct net_device *dev, *nxt;
476 476
477 rtnl_lock(); 477 rtnl_lock();
478 for (dev = dev_base; dev; dev = nxt) { 478 for_each_netdev_safe(dev, nxt)
479 nxt = dev->next;
480 if (dev->priv_flags & IFF_EBRIDGE) 479 if (dev->priv_flags & IFF_EBRIDGE)
481 del_br(dev->priv); 480 del_br(dev->priv);
482 }
483 rtnl_unlock(); 481 rtnl_unlock();
484 482
485} 483}
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c
index eda0fbfc923a..bb15e9e259b1 100644
--- a/net/bridge/br_ioctl.c
+++ b/net/bridge/br_ioctl.c
@@ -27,7 +27,9 @@ static int get_bridge_ifindices(int *indices, int num)
27 struct net_device *dev; 27 struct net_device *dev;
28 int i = 0; 28 int i = 0;
29 29
30 for (dev = dev_base; dev && i < num; dev = dev->next) { 30 for_each_netdev(dev) {
31 if (i >= num)
32 break;
31 if (dev->priv_flags & IFF_EBRIDGE) 33 if (dev->priv_flags & IFF_EBRIDGE)
32 indices[i++] = dev->ifindex; 34 indices[i++] = dev->ifindex;
33 } 35 }
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 35facc0c11c2..0fcf6f073064 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -109,7 +109,8 @@ static int br_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
109 struct net_device *dev; 109 struct net_device *dev;
110 int idx; 110 int idx;
111 111
112 for (dev = dev_base, idx = 0; dev; dev = dev->next) { 112 idx = 0;
113 for_each_netdev(dev) {
113 /* not a bridge port */ 114 /* not a bridge port */
114 if (dev->br_port == NULL || idx < cb->args[0]) 115 if (dev->br_port == NULL || idx < cb->args[0])
115 goto skip; 116 goto skip;
diff --git a/net/core/dev.c b/net/core/dev.c
index c305819b7266..f27d4ab181e6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -156,13 +156,13 @@ static spinlock_t net_dma_event_lock;
156#endif 156#endif
157 157
158/* 158/*
159 * The @dev_base list is protected by @dev_base_lock and the rtnl 159 * The @dev_base_head list is protected by @dev_base_lock and the rtnl
160 * semaphore. 160 * semaphore.
161 * 161 *
162 * Pure readers hold dev_base_lock for reading. 162 * Pure readers hold dev_base_lock for reading.
163 * 163 *
164 * Writers must hold the rtnl semaphore while they loop through the 164 * Writers must hold the rtnl semaphore while they loop through the
165 * dev_base list, and hold dev_base_lock for writing when they do the 165 * dev_base_head list, and hold dev_base_lock for writing when they do the
166 * actual updates. This allows pure readers to access the list even 166 * actual updates. This allows pure readers to access the list even
167 * while a writer is preparing to update it. 167 * while a writer is preparing to update it.
168 * 168 *
@@ -174,11 +174,10 @@ static spinlock_t net_dma_event_lock;
174 * unregister_netdevice(), which must be called with the rtnl 174 * unregister_netdevice(), which must be called with the rtnl
175 * semaphore held. 175 * semaphore held.
176 */ 176 */
177struct net_device *dev_base; 177LIST_HEAD(dev_base_head);
178static struct net_device **dev_tail = &dev_base;
179DEFINE_RWLOCK(dev_base_lock); 178DEFINE_RWLOCK(dev_base_lock);
180 179
181EXPORT_SYMBOL(dev_base); 180EXPORT_SYMBOL(dev_base_head);
182EXPORT_SYMBOL(dev_base_lock); 181EXPORT_SYMBOL(dev_base_lock);
183 182
184#define NETDEV_HASHBITS 8 183#define NETDEV_HASHBITS 8
@@ -567,11 +566,12 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
567 566
568 ASSERT_RTNL(); 567 ASSERT_RTNL();
569 568
570 for (dev = dev_base; dev; dev = dev->next) 569 for_each_netdev(dev)
571 if (dev->type == type && 570 if (dev->type == type &&
572 !memcmp(dev->dev_addr, ha, dev->addr_len)) 571 !memcmp(dev->dev_addr, ha, dev->addr_len))
573 break; 572 return dev;
574 return dev; 573
574 return NULL;
575} 575}
576 576
577EXPORT_SYMBOL(dev_getbyhwaddr); 577EXPORT_SYMBOL(dev_getbyhwaddr);
@@ -581,11 +581,11 @@ struct net_device *__dev_getfirstbyhwtype(unsigned short type)
581 struct net_device *dev; 581 struct net_device *dev;
582 582
583 ASSERT_RTNL(); 583 ASSERT_RTNL();
584 for (dev = dev_base; dev; dev = dev->next) { 584 for_each_netdev(dev)
585 if (dev->type == type) 585 if (dev->type == type)
586 break; 586 return dev;
587 } 587
588 return dev; 588 return NULL;
589} 589}
590 590
591EXPORT_SYMBOL(__dev_getfirstbyhwtype); 591EXPORT_SYMBOL(__dev_getfirstbyhwtype);
@@ -617,17 +617,19 @@ EXPORT_SYMBOL(dev_getfirstbyhwtype);
617 617
618struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask) 618struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask)
619{ 619{
620 struct net_device *dev; 620 struct net_device *dev, *ret;
621 621
622 ret = NULL;
622 read_lock(&dev_base_lock); 623 read_lock(&dev_base_lock);
623 for (dev = dev_base; dev != NULL; dev = dev->next) { 624 for_each_netdev(dev) {
624 if (((dev->flags ^ if_flags) & mask) == 0) { 625 if (((dev->flags ^ if_flags) & mask) == 0) {
625 dev_hold(dev); 626 dev_hold(dev);
627 ret = dev;
626 break; 628 break;
627 } 629 }
628 } 630 }
629 read_unlock(&dev_base_lock); 631 read_unlock(&dev_base_lock);
630 return dev; 632 return ret;
631} 633}
632 634
633/** 635/**
@@ -693,7 +695,7 @@ int dev_alloc_name(struct net_device *dev, const char *name)
693 if (!inuse) 695 if (!inuse)
694 return -ENOMEM; 696 return -ENOMEM;
695 697
696 for (d = dev_base; d; d = d->next) { 698 for_each_netdev(d) {
697 if (!sscanf(d->name, name, &i)) 699 if (!sscanf(d->name, name, &i))
698 continue; 700 continue;
699 if (i < 0 || i >= max_netdevices) 701 if (i < 0 || i >= max_netdevices)
@@ -975,7 +977,7 @@ int register_netdevice_notifier(struct notifier_block *nb)
975 rtnl_lock(); 977 rtnl_lock();
976 err = raw_notifier_chain_register(&netdev_chain, nb); 978 err = raw_notifier_chain_register(&netdev_chain, nb);
977 if (!err) { 979 if (!err) {
978 for (dev = dev_base; dev; dev = dev->next) { 980 for_each_netdev(dev) {
979 nb->notifier_call(nb, NETDEV_REGISTER, dev); 981 nb->notifier_call(nb, NETDEV_REGISTER, dev);
980 982
981 if (dev->flags & IFF_UP) 983 if (dev->flags & IFF_UP)
@@ -2049,7 +2051,7 @@ static int dev_ifconf(char __user *arg)
2049 */ 2051 */
2050 2052
2051 total = 0; 2053 total = 0;
2052 for (dev = dev_base; dev; dev = dev->next) { 2054 for_each_netdev(dev) {
2053 for (i = 0; i < NPROTO; i++) { 2055 for (i = 0; i < NPROTO; i++) {
2054 if (gifconf_list[i]) { 2056 if (gifconf_list[i]) {
2055 int done; 2057 int done;
@@ -2081,26 +2083,28 @@ static int dev_ifconf(char __user *arg)
2081 * This is invoked by the /proc filesystem handler to display a device 2083 * This is invoked by the /proc filesystem handler to display a device
2082 * in detail. 2084 * in detail.
2083 */ 2085 */
2084static struct net_device *dev_get_idx(loff_t pos) 2086void *dev_seq_start(struct seq_file *seq, loff_t *pos)
2085{ 2087{
2088 loff_t off;
2086 struct net_device *dev; 2089 struct net_device *dev;
2087 loff_t i;
2088 2090
2089 for (i = 0, dev = dev_base; dev && i < pos; ++i, dev = dev->next); 2091 read_lock(&dev_base_lock);
2092 if (!*pos)
2093 return SEQ_START_TOKEN;
2090 2094
2091 return i == pos ? dev : NULL; 2095 off = 1;
2092} 2096 for_each_netdev(dev)
2097 if (off++ == *pos)
2098 return dev;
2093 2099
2094void *dev_seq_start(struct seq_file *seq, loff_t *pos) 2100 return NULL;
2095{
2096 read_lock(&dev_base_lock);
2097 return *pos ? dev_get_idx(*pos - 1) : SEQ_START_TOKEN;
2098} 2101}
2099 2102
2100void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2103void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2101{ 2104{
2102 ++*pos; 2105 ++*pos;
2103 return v == SEQ_START_TOKEN ? dev_base : ((struct net_device *)v)->next; 2106 return v == SEQ_START_TOKEN ?
2107 first_net_device() : next_net_device((struct net_device *)v);
2104} 2108}
2105 2109
2106void dev_seq_stop(struct seq_file *seq, void *v) 2110void dev_seq_stop(struct seq_file *seq, void *v)
@@ -3082,11 +3086,9 @@ int register_netdevice(struct net_device *dev)
3082 3086
3083 set_bit(__LINK_STATE_PRESENT, &dev->state); 3087 set_bit(__LINK_STATE_PRESENT, &dev->state);
3084 3088
3085 dev->next = NULL;
3086 dev_init_scheduler(dev); 3089 dev_init_scheduler(dev);
3087 write_lock_bh(&dev_base_lock); 3090 write_lock_bh(&dev_base_lock);
3088 *dev_tail = dev; 3091 list_add_tail(&dev->dev_list, &dev_base_head);
3089 dev_tail = &dev->next;
3090 hlist_add_head(&dev->name_hlist, head); 3092 hlist_add_head(&dev->name_hlist, head);
3091 hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex)); 3093 hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex));
3092 dev_hold(dev); 3094 dev_hold(dev);
@@ -3360,8 +3362,6 @@ void synchronize_net(void)
3360 3362
3361void unregister_netdevice(struct net_device *dev) 3363void unregister_netdevice(struct net_device *dev)
3362{ 3364{
3363 struct net_device *d, **dp;
3364
3365 BUG_ON(dev_boot_phase); 3365 BUG_ON(dev_boot_phase);
3366 ASSERT_RTNL(); 3366 ASSERT_RTNL();
3367 3367
@@ -3381,19 +3381,11 @@ void unregister_netdevice(struct net_device *dev)
3381 dev_close(dev); 3381 dev_close(dev);
3382 3382
3383 /* And unlink it from device chain. */ 3383 /* And unlink it from device chain. */
3384 for (dp = &dev_base; (d = *dp) != NULL; dp = &d->next) { 3384 write_lock_bh(&dev_base_lock);
3385 if (d == dev) { 3385 list_del(&dev->dev_list);
3386 write_lock_bh(&dev_base_lock); 3386 hlist_del(&dev->name_hlist);
3387 hlist_del(&dev->name_hlist); 3387 hlist_del(&dev->index_hlist);
3388 hlist_del(&dev->index_hlist); 3388 write_unlock_bh(&dev_base_lock);
3389 if (dev_tail == &dev->next)
3390 dev_tail = dp;
3391 *dp = d->next;
3392 write_unlock_bh(&dev_base_lock);
3393 break;
3394 }
3395 }
3396 BUG_ON(!d);
3397 3389
3398 dev->reg_state = NETREG_UNREGISTERING; 3390 dev->reg_state = NETREG_UNREGISTERING;
3399 3391
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index 7d57bf77f3a3..5a54053386c8 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -223,7 +223,7 @@ static void *dev_mc_seq_start(struct seq_file *seq, loff_t *pos)
223 loff_t off = 0; 223 loff_t off = 0;
224 224
225 read_lock(&dev_base_lock); 225 read_lock(&dev_base_lock);
226 for (dev = dev_base; dev; dev = dev->next) { 226 for_each_netdev(dev) {
227 if (off++ == *pos) 227 if (off++ == *pos)
228 return dev; 228 return dev;
229 } 229 }
@@ -232,9 +232,8 @@ static void *dev_mc_seq_start(struct seq_file *seq, loff_t *pos)
232 232
233static void *dev_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 233static void *dev_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
234{ 234{
235 struct net_device *dev = v;
236 ++*pos; 235 ++*pos;
237 return dev->next; 236 return next_net_device((struct net_device *)v);
238} 237}
239 238
240static void dev_mc_seq_stop(struct seq_file *seq, void *v) 239static void dev_mc_seq_stop(struct seq_file *seq, void *v)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index cec111109155..8c971a2efe2a 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -539,13 +539,16 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
539 int s_idx = cb->args[0]; 539 int s_idx = cb->args[0];
540 struct net_device *dev; 540 struct net_device *dev;
541 541
542 for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) { 542 idx = 0;
543 for_each_netdev(dev) {
543 if (idx < s_idx) 544 if (idx < s_idx)
544 continue; 545 goto cont;
545 if (rtnl_fill_ifinfo(skb, dev, NULL, 0, RTM_NEWLINK, 546 if (rtnl_fill_ifinfo(skb, dev, NULL, 0, RTM_NEWLINK,
546 NETLINK_CB(cb->skb).pid, 547 NETLINK_CB(cb->skb).pid,
547 cb->nlh->nlmsg_seq, 0, NLM_F_MULTI) <= 0) 548 cb->nlh->nlmsg_seq, 0, NLM_F_MULTI) <= 0)
548 break; 549 break;
550cont:
551 idx++;
549 } 552 }
550 cb->args[0] = idx; 553 cb->args[0] = idx;
551 554
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index a205eaa87f52..9fbe87c93802 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -721,7 +721,7 @@ static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
721 struct sock *sk = sock->sk; 721 struct sock *sk = sock->sk;
722 struct dn_scp *scp = DN_SK(sk); 722 struct dn_scp *scp = DN_SK(sk);
723 struct sockaddr_dn *saddr = (struct sockaddr_dn *)uaddr; 723 struct sockaddr_dn *saddr = (struct sockaddr_dn *)uaddr;
724 struct net_device *dev; 724 struct net_device *dev, *ldev;
725 int rv; 725 int rv;
726 726
727 if (addr_len != sizeof(struct sockaddr_dn)) 727 if (addr_len != sizeof(struct sockaddr_dn))
@@ -746,14 +746,17 @@ static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
746 if (!(saddr->sdn_flags & SDF_WILD)) { 746 if (!(saddr->sdn_flags & SDF_WILD)) {
747 if (dn_ntohs(saddr->sdn_nodeaddrl)) { 747 if (dn_ntohs(saddr->sdn_nodeaddrl)) {
748 read_lock(&dev_base_lock); 748 read_lock(&dev_base_lock);
749 for(dev = dev_base; dev; dev = dev->next) { 749 ldev = NULL;
750 for_each_netdev(dev) {
750 if (!dev->dn_ptr) 751 if (!dev->dn_ptr)
751 continue; 752 continue;
752 if (dn_dev_islocal(dev, dn_saddr2dn(saddr))) 753 if (dn_dev_islocal(dev, dn_saddr2dn(saddr))) {
754 ldev = dev;
753 break; 755 break;
756 }
754 } 757 }
755 read_unlock(&dev_base_lock); 758 read_unlock(&dev_base_lock);
756 if (dev == NULL) 759 if (ldev == NULL)
757 return -EADDRNOTAVAIL; 760 return -EADDRNOTAVAIL;
758 } 761 }
759 } 762 }
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 5c2a9951b638..764a56a13e38 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -799,9 +799,10 @@ static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
799 skip_ndevs = cb->args[0]; 799 skip_ndevs = cb->args[0];
800 skip_naddr = cb->args[1]; 800 skip_naddr = cb->args[1];
801 801
802 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) { 802 idx = 0;
803 for_each_netdev(dev) {
803 if (idx < skip_ndevs) 804 if (idx < skip_ndevs)
804 continue; 805 goto cont;
805 else if (idx > skip_ndevs) { 806 else if (idx > skip_ndevs) {
806 /* Only skip over addresses for first dev dumped 807 /* Only skip over addresses for first dev dumped
807 * in this iteration (idx == skip_ndevs) */ 808 * in this iteration (idx == skip_ndevs) */
@@ -809,18 +810,20 @@ static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
809 } 810 }
810 811
811 if ((dn_db = dev->dn_ptr) == NULL) 812 if ((dn_db = dev->dn_ptr) == NULL)
812 continue; 813 goto cont;
813 814
814 for (ifa = dn_db->ifa_list, dn_idx = 0; ifa; 815 for (ifa = dn_db->ifa_list, dn_idx = 0; ifa;
815 ifa = ifa->ifa_next, dn_idx++) { 816 ifa = ifa->ifa_next, dn_idx++) {
816 if (dn_idx < skip_naddr) 817 if (dn_idx < skip_naddr)
817 continue; 818 goto cont;
818 819
819 if (dn_nl_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid, 820 if (dn_nl_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
820 cb->nlh->nlmsg_seq, RTM_NEWADDR, 821 cb->nlh->nlmsg_seq, RTM_NEWADDR,
821 NLM_F_MULTI) < 0) 822 NLM_F_MULTI) < 0)
822 goto done; 823 goto done;
823 } 824 }
825cont:
826 idx++;
824 } 827 }
825done: 828done:
826 cb->args[0] = idx; 829 cb->args[0] = idx;
@@ -1296,7 +1299,7 @@ void dn_dev_devices_off(void)
1296 struct net_device *dev; 1299 struct net_device *dev;
1297 1300
1298 rtnl_lock(); 1301 rtnl_lock();
1299 for(dev = dev_base; dev; dev = dev->next) 1302 for_each_netdev(dev)
1300 dn_dev_down(dev); 1303 dn_dev_down(dev);
1301 rtnl_unlock(); 1304 rtnl_unlock();
1302 1305
@@ -1307,7 +1310,7 @@ void dn_dev_devices_on(void)
1307 struct net_device *dev; 1310 struct net_device *dev;
1308 1311
1309 rtnl_lock(); 1312 rtnl_lock();
1310 for(dev = dev_base; dev; dev = dev->next) { 1313 for_each_netdev(dev) {
1311 if (dev->flags & IFF_UP) 1314 if (dev->flags & IFF_UP)
1312 dn_dev_up(dev); 1315 dn_dev_up(dev);
1313 } 1316 }
@@ -1325,62 +1328,56 @@ int unregister_dnaddr_notifier(struct notifier_block *nb)
1325} 1328}
1326 1329
1327#ifdef CONFIG_PROC_FS 1330#ifdef CONFIG_PROC_FS
1328static inline struct net_device *dn_dev_get_next(struct seq_file *seq, struct net_device *dev) 1331static inline int is_dn_dev(struct net_device *dev)
1329{ 1332{
1330 do { 1333 return dev->dn_ptr != NULL;
1331 dev = dev->next;
1332 } while(dev && !dev->dn_ptr);
1333
1334 return dev;
1335} 1334}
1336 1335
1337static struct net_device *dn_dev_get_idx(struct seq_file *seq, loff_t pos) 1336static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
1338{ 1337{
1338 int i;
1339 struct net_device *dev; 1339 struct net_device *dev;
1340 1340
1341 dev = dev_base; 1341 read_lock(&dev_base_lock);
1342 if (dev && !dev->dn_ptr)
1343 dev = dn_dev_get_next(seq, dev);
1344 if (pos) {
1345 while(dev && (dev = dn_dev_get_next(seq, dev)))
1346 --pos;
1347 }
1348 return dev;
1349}
1350 1342
1351static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos) 1343 if (*pos == 0)
1352{ 1344 return SEQ_START_TOKEN;
1353 if (*pos) { 1345
1354 struct net_device *dev; 1346 i = 1;
1355 read_lock(&dev_base_lock); 1347 for_each_netdev(dev) {
1356 dev = dn_dev_get_idx(seq, *pos - 1); 1348 if (!is_dn_dev(dev))
1357 if (dev == NULL) 1349 continue;
1358 read_unlock(&dev_base_lock); 1350
1359 return dev; 1351 if (i++ == *pos)
1352 return dev;
1360 } 1353 }
1361 return SEQ_START_TOKEN; 1354
1355 return NULL;
1362} 1356}
1363 1357
1364static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1358static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1365{ 1359{
1366 struct net_device *dev = v; 1360 struct net_device *dev;
1367 loff_t one = 1;
1368 1361
1369 if (v == SEQ_START_TOKEN) {
1370 dev = dn_dev_seq_start(seq, &one);
1371 } else {
1372 dev = dn_dev_get_next(seq, dev);
1373 if (dev == NULL)
1374 read_unlock(&dev_base_lock);
1375 }
1376 ++*pos; 1362 ++*pos;
1377 return dev; 1363
1364 dev = (struct net_device *)v;
1365 if (v == SEQ_START_TOKEN)
1366 dev = net_device_entry(&dev_base_head);
1367
1368 for_each_netdev_continue(dev) {
1369 if (!is_dn_dev(dev))
1370 continue;
1371
1372 return dev;
1373 }
1374
1375 return NULL;
1378} 1376}
1379 1377
1380static void dn_dev_seq_stop(struct seq_file *seq, void *v) 1378static void dn_dev_seq_stop(struct seq_file *seq, void *v)
1381{ 1379{
1382 if (v && v != SEQ_START_TOKEN) 1380 read_unlock(&dev_base_lock);
1383 read_unlock(&dev_base_lock);
1384} 1381}
1385 1382
1386static char *dn_type2asc(char type) 1383static char *dn_type2asc(char type)
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index 310a86268d2b..d2bc19d47950 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -602,7 +602,7 @@ static void dn_fib_del_ifaddr(struct dn_ifaddr *ifa)
602 602
603 /* Scan device list */ 603 /* Scan device list */
604 read_lock(&dev_base_lock); 604 read_lock(&dev_base_lock);
605 for(dev = dev_base; dev; dev = dev->next) { 605 for_each_netdev(dev) {
606 dn_db = dev->dn_ptr; 606 dn_db = dev->dn_ptr;
607 if (dn_db == NULL) 607 if (dn_db == NULL)
608 continue; 608 continue;
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 5d7337bcf0fe..a8bf106b7a61 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -886,7 +886,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
886 .iif = loopback_dev.ifindex, 886 .iif = loopback_dev.ifindex,
887 .oif = oldflp->oif }; 887 .oif = oldflp->oif };
888 struct dn_route *rt = NULL; 888 struct dn_route *rt = NULL;
889 struct net_device *dev_out = NULL; 889 struct net_device *dev_out = NULL, *dev;
890 struct neighbour *neigh = NULL; 890 struct neighbour *neigh = NULL;
891 unsigned hash; 891 unsigned hash;
892 unsigned flags = 0; 892 unsigned flags = 0;
@@ -925,15 +925,17 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
925 goto out; 925 goto out;
926 } 926 }
927 read_lock(&dev_base_lock); 927 read_lock(&dev_base_lock);
928 for(dev_out = dev_base; dev_out; dev_out = dev_out->next) { 928 for_each_netdev(dev) {
929 if (!dev_out->dn_ptr) 929 if (!dev->dn_ptr)
930 continue; 930 continue;
931 if (!dn_dev_islocal(dev_out, oldflp->fld_src)) 931 if (!dn_dev_islocal(dev, oldflp->fld_src))
932 continue; 932 continue;
933 if ((dev_out->flags & IFF_LOOPBACK) && 933 if ((dev->flags & IFF_LOOPBACK) &&
934 oldflp->fld_dst && 934 oldflp->fld_dst &&
935 !dn_dev_islocal(dev_out, oldflp->fld_dst)) 935 !dn_dev_islocal(dev, oldflp->fld_dst))
936 continue; 936 continue;
937
938 dev_out = dev;
937 break; 939 break;
938 } 940 }
939 read_unlock(&dev_base_lock); 941 read_unlock(&dev_base_lock);
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 088888db8b3d..7f95e6e9beeb 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -910,7 +910,7 @@ no_in_dev:
910 */ 910 */
911 read_lock(&dev_base_lock); 911 read_lock(&dev_base_lock);
912 rcu_read_lock(); 912 rcu_read_lock();
913 for (dev = dev_base; dev; dev = dev->next) { 913 for_each_netdev(dev) {
914 if ((in_dev = __in_dev_get_rcu(dev)) == NULL) 914 if ((in_dev = __in_dev_get_rcu(dev)) == NULL)
915 continue; 915 continue;
916 916
@@ -989,7 +989,7 @@ __be32 inet_confirm_addr(const struct net_device *dev, __be32 dst, __be32 local,
989 989
990 read_lock(&dev_base_lock); 990 read_lock(&dev_base_lock);
991 rcu_read_lock(); 991 rcu_read_lock();
992 for (dev = dev_base; dev; dev = dev->next) { 992 for_each_netdev(dev) {
993 if ((in_dev = __in_dev_get_rcu(dev))) { 993 if ((in_dev = __in_dev_get_rcu(dev))) {
994 addr = confirm_addr_indev(in_dev, dst, local, scope); 994 addr = confirm_addr_indev(in_dev, dst, local, scope);
995 if (addr) 995 if (addr)
@@ -1182,23 +1182,26 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
1182 int s_ip_idx, s_idx = cb->args[0]; 1182 int s_ip_idx, s_idx = cb->args[0];
1183 1183
1184 s_ip_idx = ip_idx = cb->args[1]; 1184 s_ip_idx = ip_idx = cb->args[1];
1185 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) { 1185 idx = 0;
1186 for_each_netdev(dev) {
1186 if (idx < s_idx) 1187 if (idx < s_idx)
1187 continue; 1188 goto cont;
1188 if (idx > s_idx) 1189 if (idx > s_idx)
1189 s_ip_idx = 0; 1190 s_ip_idx = 0;
1190 if ((in_dev = __in_dev_get_rtnl(dev)) == NULL) 1191 if ((in_dev = __in_dev_get_rtnl(dev)) == NULL)
1191 continue; 1192 goto cont;
1192 1193
1193 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa; 1194 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
1194 ifa = ifa->ifa_next, ip_idx++) { 1195 ifa = ifa->ifa_next, ip_idx++) {
1195 if (ip_idx < s_ip_idx) 1196 if (ip_idx < s_ip_idx)
1196 continue; 1197 goto cont;
1197 if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid, 1198 if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
1198 cb->nlh->nlmsg_seq, 1199 cb->nlh->nlmsg_seq,
1199 RTM_NEWADDR, NLM_F_MULTI) <= 0) 1200 RTM_NEWADDR, NLM_F_MULTI) <= 0)
1200 goto done; 1201 goto done;
1201 } 1202 }
1203cont:
1204 idx++;
1202 } 1205 }
1203 1206
1204done: 1207done:
@@ -1243,7 +1246,7 @@ void inet_forward_change(void)
1243 ipv4_devconf_dflt.forwarding = on; 1246 ipv4_devconf_dflt.forwarding = on;
1244 1247
1245 read_lock(&dev_base_lock); 1248 read_lock(&dev_base_lock);
1246 for (dev = dev_base; dev; dev = dev->next) { 1249 for_each_netdev(dev) {
1247 struct in_device *in_dev; 1250 struct in_device *in_dev;
1248 rcu_read_lock(); 1251 rcu_read_lock();
1249 in_dev = __in_dev_get_rcu(dev); 1252 in_dev = __in_dev_get_rcu(dev);
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 2506021c2935..f4dd47453108 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -2288,9 +2288,8 @@ static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq)
2288 struct ip_mc_list *im = NULL; 2288 struct ip_mc_list *im = NULL;
2289 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); 2289 struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq);
2290 2290
2291 for (state->dev = dev_base, state->in_dev = NULL; 2291 state->in_dev = NULL;
2292 state->dev; 2292 for_each_netdev(state->dev) {
2293 state->dev = state->dev->next) {
2294 struct in_device *in_dev; 2293 struct in_device *in_dev;
2295 in_dev = in_dev_get(state->dev); 2294 in_dev = in_dev_get(state->dev);
2296 if (!in_dev) 2295 if (!in_dev)
@@ -2316,7 +2315,7 @@ static struct ip_mc_list *igmp_mc_get_next(struct seq_file *seq, struct ip_mc_li
2316 read_unlock(&state->in_dev->mc_list_lock); 2315 read_unlock(&state->in_dev->mc_list_lock);
2317 in_dev_put(state->in_dev); 2316 in_dev_put(state->in_dev);
2318 } 2317 }
2319 state->dev = state->dev->next; 2318 state->dev = next_net_device(state->dev);
2320 if (!state->dev) { 2319 if (!state->dev) {
2321 state->in_dev = NULL; 2320 state->in_dev = NULL;
2322 break; 2321 break;
@@ -2450,9 +2449,9 @@ static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq)
2450 struct ip_mc_list *im = NULL; 2449 struct ip_mc_list *im = NULL;
2451 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); 2450 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq);
2452 2451
2453 for (state->dev = dev_base, state->idev = NULL, state->im = NULL; 2452 state->idev = NULL;
2454 state->dev; 2453 state->im = NULL;
2455 state->dev = state->dev->next) { 2454 for_each_netdev(state->dev) {
2456 struct in_device *idev; 2455 struct in_device *idev;
2457 idev = in_dev_get(state->dev); 2456 idev = in_dev_get(state->dev);
2458 if (unlikely(idev == NULL)) 2457 if (unlikely(idev == NULL))
@@ -2488,7 +2487,7 @@ static struct ip_sf_list *igmp_mcf_get_next(struct seq_file *seq, struct ip_sf_l
2488 read_unlock(&state->idev->mc_list_lock); 2487 read_unlock(&state->idev->mc_list_lock);
2489 in_dev_put(state->idev); 2488 in_dev_put(state->idev);
2490 } 2489 }
2491 state->dev = state->dev->next; 2490 state->dev = next_net_device(state->dev);
2492 if (!state->dev) { 2491 if (!state->dev) {
2493 state->idev = NULL; 2492 state->idev = NULL;
2494 goto out; 2493 goto out;
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 597c800b2fdc..342ca8d89458 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -192,7 +192,7 @@ static int __init ic_open_devs(void)
192 if (dev_change_flags(&loopback_dev, loopback_dev.flags | IFF_UP) < 0) 192 if (dev_change_flags(&loopback_dev, loopback_dev.flags | IFF_UP) < 0)
193 printk(KERN_ERR "IP-Config: Failed to open %s\n", loopback_dev.name); 193 printk(KERN_ERR "IP-Config: Failed to open %s\n", loopback_dev.name);
194 194
195 for (dev = dev_base; dev; dev = dev->next) { 195 for_each_netdev(dev) {
196 if (dev == &loopback_dev) 196 if (dev == &loopback_dev)
197 continue; 197 continue;
198 if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : 198 if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) :
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 3452433cbc96..d02685c6bc69 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -449,7 +449,7 @@ static void addrconf_forward_change(void)
449 struct inet6_dev *idev; 449 struct inet6_dev *idev;
450 450
451 read_lock(&dev_base_lock); 451 read_lock(&dev_base_lock);
452 for (dev=dev_base; dev; dev=dev->next) { 452 for_each_netdev(dev) {
453 rcu_read_lock(); 453 rcu_read_lock();
454 idev = __in6_dev_get(dev); 454 idev = __in6_dev_get(dev);
455 if (idev) { 455 if (idev) {
@@ -911,7 +911,7 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
911 read_lock(&dev_base_lock); 911 read_lock(&dev_base_lock);
912 rcu_read_lock(); 912 rcu_read_lock();
913 913
914 for (dev = dev_base; dev; dev=dev->next) { 914 for_each_netdev(dev) {
915 struct inet6_dev *idev; 915 struct inet6_dev *idev;
916 struct inet6_ifaddr *ifa; 916 struct inet6_ifaddr *ifa;
917 917
@@ -2064,7 +2064,7 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
2064 return; 2064 return;
2065 } 2065 }
2066 2066
2067 for (dev = dev_base; dev != NULL; dev = dev->next) { 2067 for_each_netdev(dev) {
2068 struct in_device * in_dev = __in_dev_get_rtnl(dev); 2068 struct in_device * in_dev = __in_dev_get_rtnl(dev);
2069 if (in_dev && (dev->flags & IFF_UP)) { 2069 if (in_dev && (dev->flags & IFF_UP)) {
2070 struct in_ifaddr * ifa; 2070 struct in_ifaddr * ifa;
@@ -2225,7 +2225,7 @@ static void ip6_tnl_add_linklocal(struct inet6_dev *idev)
2225 return; 2225 return;
2226 } 2226 }
2227 /* then try to inherit it from any device */ 2227 /* then try to inherit it from any device */
2228 for (link_dev = dev_base; link_dev; link_dev = link_dev->next) { 2228 for_each_netdev(link_dev) {
2229 if (!ipv6_inherit_linklocal(idev, link_dev)) 2229 if (!ipv6_inherit_linklocal(idev, link_dev))
2230 return; 2230 return;
2231 } 2231 }
@@ -3257,14 +3257,15 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
3257 s_idx = cb->args[0]; 3257 s_idx = cb->args[0];
3258 s_ip_idx = ip_idx = cb->args[1]; 3258 s_ip_idx = ip_idx = cb->args[1];
3259 3259
3260 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) { 3260 idx = 0;
3261 for_each_netdev(dev) {
3261 if (idx < s_idx) 3262 if (idx < s_idx)
3262 continue; 3263 goto cont;
3263 if (idx > s_idx) 3264 if (idx > s_idx)
3264 s_ip_idx = 0; 3265 s_ip_idx = 0;
3265 ip_idx = 0; 3266 ip_idx = 0;
3266 if ((idev = in6_dev_get(dev)) == NULL) 3267 if ((idev = in6_dev_get(dev)) == NULL)
3267 continue; 3268 goto cont;
3268 read_lock_bh(&idev->lock); 3269 read_lock_bh(&idev->lock);
3269 switch (type) { 3270 switch (type) {
3270 case UNICAST_ADDR: 3271 case UNICAST_ADDR:
@@ -3311,6 +3312,8 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
3311 } 3312 }
3312 read_unlock_bh(&idev->lock); 3313 read_unlock_bh(&idev->lock);
3313 in6_dev_put(idev); 3314 in6_dev_put(idev);
3315cont:
3316 idx++;
3314 } 3317 }
3315done: 3318done:
3316 if (err <= 0) { 3319 if (err <= 0) {
@@ -3575,16 +3578,19 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3575 struct inet6_dev *idev; 3578 struct inet6_dev *idev;
3576 3579
3577 read_lock(&dev_base_lock); 3580 read_lock(&dev_base_lock);
3578 for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) { 3581 idx = 0;
3582 for_each_netdev(dev) {
3579 if (idx < s_idx) 3583 if (idx < s_idx)
3580 continue; 3584 goto cont;
3581 if ((idev = in6_dev_get(dev)) == NULL) 3585 if ((idev = in6_dev_get(dev)) == NULL)
3582 continue; 3586 goto cont;
3583 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid, 3587 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
3584 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI); 3588 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
3585 in6_dev_put(idev); 3589 in6_dev_put(idev);
3586 if (err <= 0) 3590 if (err <= 0)
3587 break; 3591 break;
3592cont:
3593 idx++;
3588 } 3594 }
3589 read_unlock(&dev_base_lock); 3595 read_unlock(&dev_base_lock);
3590 cb->args[0] = idx; 3596 cb->args[0] = idx;
@@ -4247,7 +4253,7 @@ void __exit addrconf_cleanup(void)
4247 * clean dev list. 4253 * clean dev list.
4248 */ 4254 */
4249 4255
4250 for (dev=dev_base; dev; dev=dev->next) { 4256 for_each_netdev(dev) {
4251 if ((idev = __in6_dev_get(dev)) == NULL) 4257 if ((idev = __in6_dev_get(dev)) == NULL)
4252 continue; 4258 continue;
4253 addrconf_ifdown(dev, 1); 4259 addrconf_ifdown(dev, 1);
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 09117d63256f..9b81264eb78f 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -423,14 +423,18 @@ static int ipv6_chk_acast_dev(struct net_device *dev, struct in6_addr *addr)
423 */ 423 */
424int ipv6_chk_acast_addr(struct net_device *dev, struct in6_addr *addr) 424int ipv6_chk_acast_addr(struct net_device *dev, struct in6_addr *addr)
425{ 425{
426 int found = 0;
427
426 if (dev) 428 if (dev)
427 return ipv6_chk_acast_dev(dev, addr); 429 return ipv6_chk_acast_dev(dev, addr);
428 read_lock(&dev_base_lock); 430 read_lock(&dev_base_lock);
429 for (dev=dev_base; dev; dev=dev->next) 431 for_each_netdev(dev)
430 if (ipv6_chk_acast_dev(dev, addr)) 432 if (ipv6_chk_acast_dev(dev, addr)) {
433 found = 1;
431 break; 434 break;
435 }
432 read_unlock(&dev_base_lock); 436 read_unlock(&dev_base_lock);
433 return dev != 0; 437 return found;
434} 438}
435 439
436 440
@@ -447,9 +451,8 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)
447 struct ifacaddr6 *im = NULL; 451 struct ifacaddr6 *im = NULL;
448 struct ac6_iter_state *state = ac6_seq_private(seq); 452 struct ac6_iter_state *state = ac6_seq_private(seq);
449 453
450 for (state->dev = dev_base, state->idev = NULL; 454 state->idev = NULL;
451 state->dev; 455 for_each_netdev(state->dev) {
452 state->dev = state->dev->next) {
453 struct inet6_dev *idev; 456 struct inet6_dev *idev;
454 idev = in6_dev_get(state->dev); 457 idev = in6_dev_get(state->dev);
455 if (!idev) 458 if (!idev)
@@ -476,7 +479,7 @@ static struct ifacaddr6 *ac6_get_next(struct seq_file *seq, struct ifacaddr6 *im
476 read_unlock_bh(&state->idev->lock); 479 read_unlock_bh(&state->idev->lock);
477 in6_dev_put(state->idev); 480 in6_dev_put(state->idev);
478 } 481 }
479 state->dev = state->dev->next; 482 state->dev = next_net_device(state->dev);
480 if (!state->dev) { 483 if (!state->dev) {
481 state->idev = NULL; 484 state->idev = NULL;
482 break; 485 break;
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 6c2758951d60..3e308fb41b49 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -2331,9 +2331,8 @@ static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq)
2331 struct ifmcaddr6 *im = NULL; 2331 struct ifmcaddr6 *im = NULL;
2332 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); 2332 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2333 2333
2334 for (state->dev = dev_base, state->idev = NULL; 2334 state->idev = NULL;
2335 state->dev; 2335 for_each_netdev(state->dev) {
2336 state->dev = state->dev->next) {
2337 struct inet6_dev *idev; 2336 struct inet6_dev *idev;
2338 idev = in6_dev_get(state->dev); 2337 idev = in6_dev_get(state->dev);
2339 if (!idev) 2338 if (!idev)
@@ -2360,7 +2359,7 @@ static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr
2360 read_unlock_bh(&state->idev->lock); 2359 read_unlock_bh(&state->idev->lock);
2361 in6_dev_put(state->idev); 2360 in6_dev_put(state->idev);
2362 } 2361 }
2363 state->dev = state->dev->next; 2362 state->dev = next_net_device(state->dev);
2364 if (!state->dev) { 2363 if (!state->dev) {
2365 state->idev = NULL; 2364 state->idev = NULL;
2366 break; 2365 break;
@@ -2475,9 +2474,9 @@ static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq)
2475 struct ifmcaddr6 *im = NULL; 2474 struct ifmcaddr6 *im = NULL;
2476 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); 2475 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2477 2476
2478 for (state->dev = dev_base, state->idev = NULL, state->im = NULL; 2477 state->idev = NULL;
2479 state->dev; 2478 state->im = NULL;
2480 state->dev = state->dev->next) { 2479 for_each_netdev(state->dev) {
2481 struct inet6_dev *idev; 2480 struct inet6_dev *idev;
2482 idev = in6_dev_get(state->dev); 2481 idev = in6_dev_get(state->dev);
2483 if (unlikely(idev == NULL)) 2482 if (unlikely(idev == NULL))
@@ -2513,7 +2512,7 @@ static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_s
2513 read_unlock_bh(&state->idev->lock); 2512 read_unlock_bh(&state->idev->lock);
2514 in6_dev_put(state->idev); 2513 in6_dev_put(state->idev);
2515 } 2514 }
2516 state->dev = state->dev->next; 2515 state->dev = next_net_device(state->dev);
2517 if (!state->dev) { 2516 if (!state->dev) {
2518 state->idev = NULL; 2517 state->idev = NULL;
2519 goto out; 2518 goto out;
diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c
index d12413cff5bd..d4b13a031fd5 100644
--- a/net/llc/llc_core.c
+++ b/net/llc/llc_core.c
@@ -160,8 +160,14 @@ static struct packet_type llc_tr_packet_type = {
160 160
161static int __init llc_init(void) 161static int __init llc_init(void)
162{ 162{
163 if (dev_base->next) 163 struct net_device *dev;
164 memcpy(llc_station_mac_sa, dev_base->next->dev_addr, ETH_ALEN); 164
165 dev = first_net_device();
166 if (dev != NULL)
167 dev = next_net_device(dev);
168
169 if (dev != NULL)
170 memcpy(llc_station_mac_sa, dev->dev_addr, ETH_ALEN);
165 else 171 else
166 memset(llc_station_mac_sa, 0, ETH_ALEN); 172 memset(llc_station_mac_sa, 0, ETH_ALEN);
167 dev_add_pack(&llc_packet_type); 173 dev_add_pack(&llc_packet_type);
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 8e6bd4e9d82c..2f76e062609d 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -598,7 +598,7 @@ struct net_device *nr_dev_first(void)
598 struct net_device *dev, *first = NULL; 598 struct net_device *dev, *first = NULL;
599 599
600 read_lock(&dev_base_lock); 600 read_lock(&dev_base_lock);
601 for (dev = dev_base; dev != NULL; dev = dev->next) { 601 for_each_netdev(dev) {
602 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM) 602 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM)
603 if (first == NULL || strncmp(dev->name, first->name, 3) < 0) 603 if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
604 first = dev; 604 first = dev;
@@ -618,12 +618,13 @@ struct net_device *nr_dev_get(ax25_address *addr)
618 struct net_device *dev; 618 struct net_device *dev;
619 619
620 read_lock(&dev_base_lock); 620 read_lock(&dev_base_lock);
621 for (dev = dev_base; dev != NULL; dev = dev->next) { 621 for_each_netdev(dev) {
622 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM && ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0) { 622 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM && ax25cmp(addr, (ax25_address *)dev->dev_addr) == 0) {
623 dev_hold(dev); 623 dev_hold(dev);
624 goto out; 624 goto out;
625 } 625 }
626 } 626 }
627 dev = NULL;
627out: 628out:
628 read_unlock(&dev_base_lock); 629 read_unlock(&dev_base_lock);
629 return dev; 630 return dev;
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
index 1f9aefd95a99..929a784a86d7 100644
--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -596,7 +596,7 @@ struct net_device *rose_dev_first(void)
596 struct net_device *dev, *first = NULL; 596 struct net_device *dev, *first = NULL;
597 597
598 read_lock(&dev_base_lock); 598 read_lock(&dev_base_lock);
599 for (dev = dev_base; dev != NULL; dev = dev->next) { 599 for_each_netdev(dev) {
600 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE) 600 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE)
601 if (first == NULL || strncmp(dev->name, first->name, 3) < 0) 601 if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
602 first = dev; 602 first = dev;
@@ -614,12 +614,13 @@ struct net_device *rose_dev_get(rose_address *addr)
614 struct net_device *dev; 614 struct net_device *dev;
615 615
616 read_lock(&dev_base_lock); 616 read_lock(&dev_base_lock);
617 for (dev = dev_base; dev != NULL; dev = dev->next) { 617 for_each_netdev(dev) {
618 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) { 618 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) {
619 dev_hold(dev); 619 dev_hold(dev);
620 goto out; 620 goto out;
621 } 621 }
622 } 622 }
623 dev = NULL;
623out: 624out:
624 read_unlock(&dev_base_lock); 625 read_unlock(&dev_base_lock);
625 return dev; 626 return dev;
@@ -630,10 +631,11 @@ static int rose_dev_exists(rose_address *addr)
630 struct net_device *dev; 631 struct net_device *dev;
631 632
632 read_lock(&dev_base_lock); 633 read_lock(&dev_base_lock);
633 for (dev = dev_base; dev != NULL; dev = dev->next) { 634 for_each_netdev(dev) {
634 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0) 635 if ((dev->flags & IFF_UP) && dev->type == ARPHRD_ROSE && rosecmp(addr, (rose_address *)dev->dev_addr) == 0)
635 goto out; 636 goto out;
636 } 637 }
638 dev = NULL;
637out: 639out:
638 read_unlock(&dev_base_lock); 640 read_unlock(&dev_base_lock);
639 return dev != NULL; 641 return dev != NULL;
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 8699e7006d80..bec600af03ca 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -894,9 +894,10 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
894 s_idx = cb->args[0]; 894 s_idx = cb->args[0];
895 s_q_idx = q_idx = cb->args[1]; 895 s_q_idx = q_idx = cb->args[1];
896 read_lock(&dev_base_lock); 896 read_lock(&dev_base_lock);
897 for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) { 897 idx = 0;
898 for_each_netdev(dev) {
898 if (idx < s_idx) 899 if (idx < s_idx)
899 continue; 900 goto cont;
900 if (idx > s_idx) 901 if (idx > s_idx)
901 s_q_idx = 0; 902 s_q_idx = 0;
902 q_idx = 0; 903 q_idx = 0;
@@ -910,6 +911,8 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
910 goto done; 911 goto done;
911 q_idx++; 912 q_idx++;
912 } 913 }
914cont:
915 idx++;
913 } 916 }
914 917
915done: 918done:
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index c361deb6cea9..d4afafc39138 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -170,7 +170,7 @@ static void sctp_get_local_addr_list(void)
170 struct sctp_af *af; 170 struct sctp_af *af;
171 171
172 read_lock(&dev_base_lock); 172 read_lock(&dev_base_lock);
173 for (dev = dev_base; dev; dev = dev->next) { 173 for_each_netdev(dev) {
174 __list_for_each(pos, &sctp_address_families) { 174 __list_for_each(pos, &sctp_address_families) {
175 af = list_entry(pos, struct sctp_af, list); 175 af = list_entry(pos, struct sctp_af, list);
176 af->copy_addrlist(&sctp_local_addr_list, dev); 176 af->copy_addrlist(&sctp_local_addr_list, dev);
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 67bb29b44d1b..0ee6ded18f3a 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -120,16 +120,18 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,
120 120
121static int enable_bearer(struct tipc_bearer *tb_ptr) 121static int enable_bearer(struct tipc_bearer *tb_ptr)
122{ 122{
123 struct net_device *dev = dev_base; 123 struct net_device *dev, *pdev;
124 struct eth_bearer *eb_ptr = &eth_bearers[0]; 124 struct eth_bearer *eb_ptr = &eth_bearers[0];
125 struct eth_bearer *stop = &eth_bearers[MAX_ETH_BEARERS]; 125 struct eth_bearer *stop = &eth_bearers[MAX_ETH_BEARERS];
126 char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1; 126 char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1;
127 127
128 /* Find device with specified name */ 128 /* Find device with specified name */
129 129 dev = NULL;
130 while (dev && dev->name && strncmp(dev->name, driver_name, IFNAMSIZ)) { 130 for_each_netdev(pdev)
131 dev = dev->next; 131 if (!strncmp(dev->name, driver_name, IFNAMSIZ)) {
132 } 132 dev = pdev;
133 break;
134 }
133 if (!dev) 135 if (!dev)
134 return -ENODEV; 136 return -ENODEV;
135 137