Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Hangbin Liu
Fri, 13 Nov 2026 14:04
[PATCH net-next 6/6] bonding: factor out bond_enslave_validate
Author: Hangbin Liu
Date: Fri, 13 Nov 2026 14:04
Date: Fri, 13 Nov 2026 14:04
73 lines
10837 bytes
10837 bytes
From: Hangbin Liu <liuhangbin@kylinos.cn>
bond_enslave() is a long linear function whose flow is hard to see
behind the inline blocks. Factor out bond_enslave_validate to do
all read-only checks.
Failures return directly, no undo needed at that point.
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
drivers/net/bonding/bond_main.c | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 5e36612cfaec..8f97b0e2c0b3 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1935,17 +1935,16 @@ static void bond_publish_slave(struct bonding *bond, struct slave *slave)
bond_update_slave_arr(bond, NULL);
}
-/* enslave device <slave> to bond device <master> */
-int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
- struct netlink_ext_ack *extack)
+/* Fail-fast validation of the slave and the bond. Everything here
+ * reads state only, so a failure needs no undo. Must stay ahead of
+ * the first mutation in bond_enslave().
+ */
+static int bond_enslave_validate(struct net_device *bond_dev,
+ struct net_device *slave_dev,
+ struct netlink_ext_ack *extack)
{
struct bonding *bond = netdev_priv(bond_dev);
- const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
- int orig_fail_over_mac = bond->params.fail_over_mac;
- struct slave *new_slave = NULL, *prev_slave;
- bool alb_initialized = false;
- struct sockaddr_storage ss;
- int res = 0, i;
+ int res;
if (slave_dev->type == ARPHRD_CAN) {
BOND_NL_ERR(bond_dev, extack,
@@ -2010,6 +2009,25 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
return res;
}
+ return 0;
+}
+
+/* enslave device <slave> to bond device <master> */
+int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
+ struct netlink_ext_ack *extack)
+{
+ struct bonding *bond = netdev_priv(bond_dev);
+ const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
+ int orig_fail_over_mac = bond->params.fail_over_mac;
+ struct slave *new_slave = NULL, *prev_slave;
+ bool alb_initialized = false;
+ struct sockaddr_storage ss;
+ int res = 0, i;
+
+ res = bond_enslave_validate(bond_dev, slave_dev, extack);
+ if (res)
+ return res;
+
/* set bonding device ether type by slave - bonding netdevices are
* created with ether_setup, so when the slave type is not ARPHRD_ETHER
* there is a need to override some of the type dependent attribs/funcs.
--
2.56.0
Re: [PATCH net-next 6/6] bonding: factor out bond_enslave_validate
Author: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 14:40
Date: Tue, 17 Nov 2026 14:40
79 lines
10760 bytes
10760 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message says the new bond_enslave_validate() helper
(drivers/net/bonding/bond_main.c) does "all read-only checks".
--
bonding: factor out bond_enslave_validate
This commit moves the fail-fast checks at the top of bond_enslave() into
a new static helper, bond_enslave_validate(), in
drivers/net/bonding/bond_main.c. Behavior does not change. The moved
block runs from the ARPHRD_CAN check through the bond_slave_xdp_check()
call.
> bond_enslave() is a long linear function whose flow is hard to see
> behind the inline blocks. Factor out bond_enslave_validate to do
> all read-only checks.
[Severity: Low]
Is "all read-only checks" accurate here? The patch moves only the checks
that already ran before the first mutation. Several other checks that
only read state are still inline in bond_enslave().
Two of them run before any mutation:
drivers/net/bonding/bond_main.c:bond_enslave() {
...
if (!bond_has_slaves(bond)) {
if (bond_dev->type != slave_dev->type) {
if (slave_dev->type != ARPHRD_ETHER &&
BOND_MODE(bond) == BOND_MODE_8023AD) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"8023AD mode requires Ethernet devices");
return -EINVAL;
}
...
} else if (bond_dev->type != slave_dev->type) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Device type is different from other slaves");
return -EINVAL;
}
...
}
The infiniband mode check only reads slave_dev->type and BOND_MODE(bond).
It runs after the first-slave type change block, though, and exits
through err_undo_flags:
if (slave_dev->type == ARPHRD_INFINIBAND &&
BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Only active-backup mode is supported for infiniband slaves");
res = -EOPNOTSUPP;
goto err_undo_flags;
}
For a first slave, the bond has already gone through
NETDEV_PRE/POST_TYPE_CHANGE, dev_uc_flush()/dev_mc_flush() and
bond_setup_by_slave() at that point. err_undo_flags then calls
dev_close(bond_dev) and bond_ether_setup(bond_dev). This behaves the same
before and after the patch.
The fail_over_mac check after it also only reads state.
The helper's own code comment, and the "Failures return directly, no
undo needed at that point" sentence, are accurate for what the helper
contains.
Could the commit message say that the helper holds the checks that run
before the first mutation, rather than all read-only checks?
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-bond_enslave_restruct-v1-0-364c549e78db%40kylinos.cn
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads