Reply: [net] bonding: use return instead of goto

2016-02-06 Thread 张胜举
> On Fri, Feb 05, 2016 at 09:42:24AM +0800, 张胜举 wrote:
> > > On Wed, Feb 03, 2016 at 06:15:22AM +, Zhang Shengju wrote:
> > > > Replace 'goto' with 'return' to remove unnecessary check at label:
> > > > err_undo_flags.
> > >
> > > I think you're going to have to explain how you came to the
> > > conclusion that the check isn't necessary.
> ...
> > The reason is that 'err_undo_flags' do two things for the first slave
> > device:
> > 1. revert bond mac address if it is set by the slave device.
> > 2. revert bond device type if it's not ARPHRD_ETHER.
> >
> > I think it's not necessary for the three places, they changed neither
> > bond mac address nor type.
> > it's straightforward to return directly.
> 
> I see what you're saying, and that does look to be true if you're only adding 
> a
> singular first device right now. But looking at the enslave and release 
> paths, I
> don't see anything preventing concurrent slave adds and removes, which
> could mean there are situations where those checks really are necessary. I
> don't actually know.
> 
> --
> Jarod Wilson
> ja...@redhat.com

All of three places don't change any attributes of bond device, 
just for sanity check before enslaving.  
If it's necessary for these three places to goto 'err_undo_flags',  
it will mean that all sanity checks before these three places need to do so, 
which is not right clearly. 

Even there is concurrent situation which make the check necessary, which I 
haven't figure out yet,
it's not right place to do this.  

Thanks,
Shengju





Re: Reply: [net] bonding: use return instead of goto

2016-02-05 Thread Jarod Wilson
On Fri, Feb 05, 2016 at 09:42:24AM +0800, 张胜举 wrote:
> > On Wed, Feb 03, 2016 at 06:15:22AM +, Zhang Shengju wrote:
> > > Replace 'goto' with 'return' to remove unnecessary check at label:
> > > err_undo_flags.
> > 
> > I think you're going to have to explain how you came to the conclusion
> > that the check isn't necessary.
...
> The reason is that 'err_undo_flags' do two things for the first slave
> device:
> 1. revert bond mac address if it is set by the slave device.
> 2. revert bond device type if it's not ARPHRD_ETHER.
> 
> I think it's not necessary for the three places, they changed neither  bond
> mac address nor type. 
> it's straightforward to return directly.

I see what you're saying, and that does look to be true if you're only
adding a singular first device right now. But looking at the enslave and
release paths, I don't see anything preventing concurrent slave adds and
removes, which could mean there are situations where those checks really
are necessary. I don't actually know.

-- 
Jarod Wilson
ja...@redhat.com



Reply: [net] bonding: use return instead of goto

2016-02-04 Thread 张胜举
> On Wed, Feb 03, 2016 at 06:15:22AM +, Zhang Shengju wrote:
> > Replace 'goto' with 'return' to remove unnecessary check at label:
> > err_undo_flags.
> 
> I think you're going to have to explain how you came to the conclusion
that
> the check isn't necessary.
> 
> --
> Jarod Wilson
> ja...@redhat.com
Hi Jarod,

The reason is that 'err_undo_flags' do two things for the first slave
device:
1. revert bond mac address if it is set by the slave device.
2. revert bond device type if it's not ARPHRD_ETHER.

I think it's not necessary for the three places, they changed neither  bond
mac address nor type. 
it's straightforward to return directly.

Thanks,
Shengju





Re: [net] bonding: use return instead of goto

2016-02-04 Thread Jarod Wilson
On Wed, Feb 03, 2016 at 06:15:22AM +, Zhang Shengju wrote:
> Replace 'goto' with 'return' to remove unnecessary check at label:
> err_undo_flags.

I think you're going to have to explain how you came to the conclusion
that the check isn't necessary.

-- 
Jarod Wilson
ja...@redhat.com



[net] bonding: use return instead of goto

2016-02-02 Thread Zhang Shengju
Replace 'goto' with 'return' to remove unnecessary check at label:
err_undo_flags.

Signed-off-by: Zhang Shengju 
---
 drivers/net/bonding/bond_main.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index bcc7b19..abe014f 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1379,8 +1379,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev)
if (slave_dev->flags & IFF_UP) {
netdev_err(bond_dev, "%s is up - this may be due to an out of 
date ifenslave\n",
   slave_dev->name);
-   res = -EPERM;
-   goto err_undo_flags;
+   return -EPERM;
}
 
/* set bonding device ether type by slave - bonding netdevices are
@@ -1400,8 +1399,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev)
res = notifier_to_errno(res);
if (res) {
netdev_err(bond_dev, "refused to change device 
type\n");
-   res = -EBUSY;
-   goto err_undo_flags;
+   return -EBUSY;
}
 
/* Flush unicast and multicast addresses */
@@ -1421,8 +1419,7 @@ int bond_enslave(struct net_device *bond_dev, struct 
net_device *slave_dev)
} else if (bond_dev->type != slave_dev->type) {
netdev_err(bond_dev, "%s ether type (%d) is different from 
other slaves (%d), can not enslave it\n",
   slave_dev->name, slave_dev->type, bond_dev->type);
-   res = -EINVAL;
-   goto err_undo_flags;
+   return -EINVAL;
}
 
if (slave_ops->ndo_set_mac_address == NULL) {
-- 
1.8.3.1