Subject: Re: [PATCH 4/5] bonding: restructure and simplify bond_for_each_slave_next()

From: Ding Tianhong <[email-masked]>
Date: Fri, 30 Aug 2013 11:37:12 +0800

>>  			slave->link = BOND_LINK_BACK;
>>  			bond_set_slave_active_flags(slave);
>> diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
>> index ecb5d1d..7670584 100644
>> --- a/drivers/net/bonding/bonding.h
>> +++ b/drivers/net/bonding/bonding.h
>> @@ -119,14 +119,25 @@
>>   * bond_for_each_slave_from - iterate the slaves list from a starting point
>>   * @bond:	the bond holding this list.
>>   * @pos:	current slave.
>> - * @cnt:	counter for max number of moves
>>   * @start:	starting point.
>>   *
>>   * Caller must hold bond->lock
>>   */
>> -#define bond_for_each_slave_from(bond, pos, cnt, start) \
>> -	for (cnt = 0, pos = start; pos && cnt < (bond)->slave_cnt; \
>> -	     cnt++, pos = bond_next_slave(bond, pos))
>> +#define bond_for_each_slave_from(bond, pos, start) \
>> +	for (pos = bond_next_slave(bond, start); pos && pos != start; \
>> +			pos = bond_next_slave(bond, pos))
>> +
>> +/**
>> + * bond_for_each_slave_from_rcu - iterate the slaves list from a starting point
>> + * @bond:	the bond holding this list.
>> + * @pos:	current slave.
>> + * @start:	starting point.
>> + *
>> + * Caller must hold rcu_read_lock
>> + */
>> +#define bond_for_each_slave_from_rcu(bond, pos, start) \
>> +	for (pos = bond_next_slave_rcu(bond, start); pos && pos != start; \
>> +			pos = bond_next_slave_rcu(bond, pos))
>>  
> One question here: what if "start" gets deleted while we're traversing the list,
> could this lead to an infinite loop ?
> 

agree, so the start should not be delete while traversing the list, the func should not run
without protection. 

>>  /**
>>   * bond_for_each_slave - iterate over all slaves
>>
> 
> 
> .
>