Commit 0883beca authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Jeff Garzik

bonding: Relax unneeded _safe lists iterations.

Many places either do not modify the list under the list_for_each_xxx,
or break out of the loop as soon as the first element is removed.

Thus, this _safe iteration just occupies some unneeded .text space
and requires an additional variable.
Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Acked-by: default avatarJay Vosburgh <fubar@us.ibm.com>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent 0dd646fe
...@@ -261,14 +261,14 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id) ...@@ -261,14 +261,14 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
*/ */
static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id) static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
{ {
struct vlan_entry *vlan, *next; struct vlan_entry *vlan;
int res = -ENODEV; int res = -ENODEV;
dprintk("bond: %s, vlan id %d\n", bond->dev->name, vlan_id); dprintk("bond: %s, vlan id %d\n", bond->dev->name, vlan_id);
write_lock_bh(&bond->lock); write_lock_bh(&bond->lock);
list_for_each_entry_safe(vlan, next, &bond->vlan_list, vlan_list) { list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
if (vlan->vlan_id == vlan_id) { if (vlan->vlan_id == vlan_id) {
list_del(&vlan->vlan_list); list_del(&vlan->vlan_list);
...@@ -2428,7 +2428,7 @@ static __be32 bond_glean_dev_ip(struct net_device *dev) ...@@ -2428,7 +2428,7 @@ static __be32 bond_glean_dev_ip(struct net_device *dev)
static int bond_has_this_ip(struct bonding *bond, __be32 ip) static int bond_has_this_ip(struct bonding *bond, __be32 ip)
{ {
struct vlan_entry *vlan, *vlan_next; struct vlan_entry *vlan;
if (ip == bond->master_ip) if (ip == bond->master_ip)
return 1; return 1;
...@@ -2436,8 +2436,7 @@ static int bond_has_this_ip(struct bonding *bond, __be32 ip) ...@@ -2436,8 +2436,7 @@ static int bond_has_this_ip(struct bonding *bond, __be32 ip)
if (list_empty(&bond->vlan_list)) if (list_empty(&bond->vlan_list))
return 0; return 0;
list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list, list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
vlan_list) {
if (ip == vlan->vlan_ip) if (ip == vlan->vlan_ip)
return 1; return 1;
} }
...@@ -2479,7 +2478,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave) ...@@ -2479,7 +2478,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
{ {
int i, vlan_id, rv; int i, vlan_id, rv;
__be32 *targets = bond->params.arp_targets; __be32 *targets = bond->params.arp_targets;
struct vlan_entry *vlan, *vlan_next; struct vlan_entry *vlan;
struct net_device *vlan_dev; struct net_device *vlan_dev;
struct flowi fl; struct flowi fl;
struct rtable *rt; struct rtable *rt;
...@@ -2526,8 +2525,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave) ...@@ -2526,8 +2525,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
} }
vlan_id = 0; vlan_id = 0;
list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list, list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
vlan_list) {
vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
if (vlan_dev == rt->u.dst.dev) { if (vlan_dev == rt->u.dst.dev) {
vlan_id = vlan->vlan_id; vlan_id = vlan->vlan_id;
...@@ -3477,13 +3475,13 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, ...@@ -3477,13 +3475,13 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
{ {
struct in_ifaddr *ifa = ptr; struct in_ifaddr *ifa = ptr;
struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev; struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
struct bonding *bond, *bond_next; struct bonding *bond;
struct vlan_entry *vlan, *vlan_next; struct vlan_entry *vlan;
if (dev_net(ifa->ifa_dev->dev) != &init_net) if (dev_net(ifa->ifa_dev->dev) != &init_net)
return NOTIFY_DONE; return NOTIFY_DONE;
list_for_each_entry_safe(bond, bond_next, &bond_dev_list, bond_list) { list_for_each_entry(bond, &bond_dev_list, bond_list) {
if (bond->dev == event_dev) { if (bond->dev == event_dev) {
switch (event) { switch (event) {
case NETDEV_UP: case NETDEV_UP:
...@@ -3500,8 +3498,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, ...@@ -3500,8 +3498,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
if (list_empty(&bond->vlan_list)) if (list_empty(&bond->vlan_list))
continue; continue;
list_for_each_entry_safe(vlan, vlan_next, &bond->vlan_list, list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
vlan_list) {
vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
if (vlan_dev == event_dev) { if (vlan_dev == event_dev) {
switch (event) { switch (event) {
...@@ -4851,7 +4848,7 @@ static struct lock_class_key bonding_netdev_xmit_lock_key; ...@@ -4851,7 +4848,7 @@ static struct lock_class_key bonding_netdev_xmit_lock_key;
int bond_create(char *name, struct bond_params *params) int bond_create(char *name, struct bond_params *params)
{ {
struct net_device *bond_dev; struct net_device *bond_dev;
struct bonding *bond, *nxt; struct bonding *bond;
int res; int res;
rtnl_lock(); rtnl_lock();
...@@ -4859,7 +4856,7 @@ int bond_create(char *name, struct bond_params *params) ...@@ -4859,7 +4856,7 @@ int bond_create(char *name, struct bond_params *params)
/* Check to see if the bond already exists. */ /* Check to see if the bond already exists. */
if (name) { if (name) {
list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) list_for_each_entry(bond, &bond_dev_list, bond_list)
if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) { if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) {
printk(KERN_ERR DRV_NAME printk(KERN_ERR DRV_NAME
": cannot add bond %s; it already exists\n", ": cannot add bond %s; it already exists\n",
...@@ -4931,7 +4928,7 @@ static int __init bonding_init(void) ...@@ -4931,7 +4928,7 @@ static int __init bonding_init(void)
{ {
int i; int i;
int res; int res;
struct bonding *bond, *nxt; struct bonding *bond;
printk(KERN_INFO "%s", version); printk(KERN_INFO "%s", version);
...@@ -4961,7 +4958,7 @@ static int __init bonding_init(void) ...@@ -4961,7 +4958,7 @@ static int __init bonding_init(void)
goto out; goto out;
err: err:
list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) { list_for_each_entry(bond, &bond_dev_list, bond_list) {
bond_work_cancel_all(bond); bond_work_cancel_all(bond);
destroy_workqueue(bond->wq); destroy_workqueue(bond->wq);
} }
......
...@@ -111,7 +111,6 @@ static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t ...@@ -111,7 +111,6 @@ static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t
char *ifname; char *ifname;
int rv, res = count; int rv, res = count;
struct bonding *bond; struct bonding *bond;
struct bonding *nxt;
sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
ifname = command + 1; ifname = command + 1;
...@@ -134,7 +133,7 @@ static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t ...@@ -134,7 +133,7 @@ static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t
rtnl_lock(); rtnl_lock();
down_write(&bonding_rwsem); down_write(&bonding_rwsem);
list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) list_for_each_entry(bond, &bond_dev_list, bond_list)
if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) { if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
/* check the ref count on the bond's kobject. /* check the ref count on the bond's kobject.
* If it's > expected, then there's a file open, * If it's > expected, then there's a file open,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment