Skip to content

Commit d6b83f1

Browse files
zhengchaoshaoPaolo Abeni
authored andcommitted
bonding: return -ENOMEM instead of BUG in alb_upper_dev_walk
If failed to allocate "tags" or could not find the final upper device from start_dev's upper list in bond_verify_device_path(), only the loopback detection of the current upper device should be affected, and the system is no need to be panic. So return -ENOMEM in alb_upper_dev_walk to stop walking, print some warn information when failed to allocate memory for vlan tags in bond_verify_device_path. I also think that the following function calls netdev_walk_all_upper_dev_rcu ---->>>alb_upper_dev_walk ---------->>>bond_verify_device_path From this way, "end device" can eventually be obtained from "start device" in bond_verify_device_path, IS_ERR(tags) could be instead of IS_ERR_OR_NULL(tags) in alb_upper_dev_walk. Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com> Link: https://lore.kernel.org/r/20231118081653.1481260-1-shaozhengchao@huawei.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 0807dc7 commit d6b83f1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

drivers/net/bonding/bond_alb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,8 @@ static int alb_upper_dev_walk(struct net_device *upper,
985985
if (netif_is_macvlan(upper) && !strict_match) {
986986
tags = bond_verify_device_path(bond->dev, upper, 0);
987987
if (IS_ERR_OR_NULL(tags))
988-
BUG();
988+
return -ENOMEM;
989+
989990
alb_send_lp_vid(slave, upper->dev_addr,
990991
tags[0].vlan_proto, tags[0].vlan_id);
991992
kfree(tags);

drivers/net/bonding/bond_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2973,8 +2973,11 @@ struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
29732973

29742974
if (start_dev == end_dev) {
29752975
tags = kcalloc(level + 1, sizeof(*tags), GFP_ATOMIC);
2976-
if (!tags)
2976+
if (!tags) {
2977+
net_err_ratelimited("%s: %s: Failed to allocate tags\n",
2978+
__func__, start_dev->name);
29772979
return ERR_PTR(-ENOMEM);
2980+
}
29782981
tags[level].vlan_proto = BOND_VLAN_PROTO_NONE;
29792982
return tags;
29802983
}

0 commit comments

Comments
 (0)