From 466b0ace2df9cab7f45ae2c3102d5a979c7b604d Mon Sep 17 00:00:00 2001 From: Tomasz Kulasek Date: Wed, 26 Jul 2017 17:50:48 +0200 Subject: [PATCH] net/bonding: fix crash when primary slave set rte_eth_bond_primary_set segfaults for invalid port. This patch moves devices check before use of internal data. Fixes: 4c42498d916d ("net/bonding: allow slaves to also be bonded devices") Signed-off-by: Tomasz Kulasek Acked-by: Declan Doherty --- drivers/net/bonding/rte_eth_bond_api.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index 824ab4f6c6..de1d9e0dbb 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -514,15 +514,14 @@ rte_eth_bond_primary_set(uint8_t bonded_port_id, uint8_t slave_port_id) { struct bond_dev_private *internals; - internals = rte_eth_devices[bonded_port_id].data->dev_private; - if (valid_bonded_port_id(bonded_port_id) != 0) return -1; + internals = rte_eth_devices[bonded_port_id].data->dev_private; + if (valid_slave_port_id(slave_port_id, internals->mode) != 0) return -1; - internals->user_defined_primary_port = 1; internals->primary_port = slave_port_id; -- 2.20.1