net/bonding: fix crash when primary slave set
authorTomasz Kulasek <tomaszx.kulasek@intel.com>
Wed, 26 Jul 2017 15:50:48 +0000 (17:50 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 31 Jul 2017 17:58:41 +0000 (19:58 +0200)
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 <tomaszx.kulasek@intel.com>
Acked-by: Declan Doherty <declan.doherty@intel.com>
drivers/net/bonding/rte_eth_bond_api.c

index 824ab4f..de1d9e0 100644 (file)
@@ -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;