Re: [PATCH net v2 1/2] bonding: fix null-ptr-deref in bond_rr_gen_slave_id()

From: Jiayuan Chen

Date: Fri Feb 27 2026 - 05:19:09 EST


2026/2/27 17:45, "Sebastian Andrzej Siewior" <bigeasy@xxxxxxxxxxxxx mailto:bigeasy@xxxxxxxxxxxxx?to=%22Sebastian%20Andrzej%20Siewior%22%20%3Cbigeasy%40linutronix.de%3E > wrote:


>
> On 2026-02-27 17:22:49 [+0800], Jiayuan Chen wrote:
>
> >
> > --- a/drivers/net/bonding/bond_main.c
> > +++ b/drivers/net/bonding/bond_main.c
> > @@ -6458,6 +6458,12 @@ int bond_create(struct net *net, const char *name)
> > dev_net_set(bond_dev, net);
> > bond_dev->rtnl_link_ops = &bond_link_ops;
> >
> > + res = bond_create_init(bond);
> >
> Wouldn't it be better to put into bond_init()?
>
> I haven't look into it but when can the bond_mode be changed?
>
> Sebastian
>

Thanks! bond_init() (ndo_init) is indeed a better fit, it is called by register_netdevice()
and naturally covers both bond_create() and bond_newlink() without a separate helper.

bond_mode can be changed after device creation via sysfs or netlink, a bond created
in active-backup mode can later be switched to round-robin, which means the allocation
must not be conditional on the mode at creation time.