[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZsMFspiLZojq3EIO@Laptop-X1>
Date: Mon, 19 Aug 2024 16:43:30 +0800
From: Hangbin Liu <liuhangbin@...il.com>
To: Nikolay Aleksandrov <razor@...ckwall.org>
Cc: netdev@...r.kernel.org, Jay Vosburgh <j.vosburgh@...il.com>,
"David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Eric Dumazet <edumazet@...gle.com>,
Tariq Toukan <tariqt@...dia.com>, Jianbo Liu <jianbol@...dia.com>,
Sabrina Dubroca <sd@...asysnail.net>
Subject: Re: [PATCHv2 net-next 1/3] bonding: add common function to check
ipsec device
On Mon, Aug 19, 2024 at 11:02:14AM +0300, Nikolay Aleksandrov wrote:
> > +static struct net_device bond_ipsec_dev(struct xfrm_state *xs)
> > +{
> > + struct net_device *bond_dev = xs->xso.dev;
> > + struct net_device *real_dev;
> > + struct bonding *bond;
> > + struct slave *slave;
> > +
> > + if (!bond_dev)
> > + return NULL;
> > +
> > + bond = netdev_priv(bond_dev);
> > + slave = rcu_dereference(bond->curr_active_slave);
> > + real_dev = slave ? slave->dev : NULL;
> > +
> > + if ((BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) ||
> > + !slave || !real_dev || !xs->xso.real_dev)
> > + return NULL;
>
> No need to check !slave again here. !real_dev implies !slave and
> vice-versa, if it is set then we must have had a slave.
Ah yes, I missed this.
> I prefer the more obvious way - check slave after deref and
> bail out, similar to my fix, I think it is easier to follow the
> code and more obvious. Although I don't feel strong about that
> it's just a preference. :)
I don't have a inclination, I just want to check all the error and fail out.
If we check each one separately, do you think if I should do like
if (!bond_dev)
return NULL;
bond = netdev_priv(bond_dev);
if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
return NULL;
slave = rcu_dereference(bond->curr_active_slave);
if (!slave)
return NULL;
> > + WARN_ON(xs->xso.real_dev != slave->dev);
Here as you said, the WARN_ON would be triggered easily, do you think if I
should change to pr_warn or salve_warn?
Thanks
Hangbin
Powered by blists - more mailing lists