From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 21A5C80B9 for ; Fri, 12 Dec 2014 18:39:49 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 12 Dec 2014 09:39:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,565,1413270000"; d="scan'208";a="646750987" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 12 Dec 2014 09:39:47 -0800 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id sBCHdllS001318; Fri, 12 Dec 2014 17:39:47 GMT Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id sBCHdl9p021551; Fri, 12 Dec 2014 17:39:47 GMT Received: (from dwdohert@localhost) by sivswdev02.ir.intel.com with id sBCHdlYp021547; Fri, 12 Dec 2014 17:39:47 GMT From: Declan Doherty To: dev@dpdk.org Date: Fri, 12 Dec 2014 17:39:42 +0000 Message-Id: <1418405982-21407-1-git-send-email-declan.doherty@intel.com> X-Mailer: git-send-email 1.7.12.2 Subject: [dpdk-dev] [PATCH] bond: static analysis issues fix X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Dec 2014 17:39:50 -0000 Fixes for link bonding library identified by static analysis tool - Overflow check for active_slaves array in activate_slave function - Allocation check of pci_id_table in rte_eth_bond_create - Use of eth_dev pointer in mac_address_get/set before NULL check Signed-off-by: Declan Doherty --- lib/librte_pmd_bond/rte_eth_bond_api.c | 12 ++++++++---- lib/librte_pmd_bond/rte_eth_bond_pmd.c | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c b/lib/librte_pmd_bond/rte_eth_bond_api.c index ef5ddf4..9cb1c1f 100644 --- a/lib/librte_pmd_bond/rte_eth_bond_api.c +++ b/lib/librte_pmd_bond/rte_eth_bond_api.c @@ -115,8 +115,11 @@ activate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id) if (internals->mode == BONDING_MODE_8023AD) bond_mode_8023ad_activate_slave(eth_dev, port_id); - internals->active_slaves[internals->active_slave_count] = port_id; - internals->active_slave_count++; + if (internals->active_slave_count < + RTE_DIM(internals->active_slaves) - 1) { + internals->active_slaves[internals->active_slave_count] = port_id; + internals->active_slave_count++; + } } void @@ -144,7 +147,8 @@ deactivate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id) sizeof(internals->active_slaves[0])); } - internals->active_slave_count = active_count; + internals->active_slave_count = active_count < RTE_MAX_ETHPORTS ? + active_count : RTE_MAX_ETHPORTS - 1; if (eth_dev->data->dev_started && internals->mode == BONDING_MODE_8023AD) bond_mode_8023ad_start(eth_dev); @@ -210,7 +214,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) goto err; } pci_id_table = rte_zmalloc_socket(name, sizeof(*pci_id_table), 0, socket_id); - if (pci_drv == NULL) { + if (pci_id_table == NULL) { RTE_BOND_LOG(ERR, "Unable to malloc pci_id_table on socket"); goto err; } diff --git a/lib/librte_pmd_bond/rte_eth_bond_pmd.c b/lib/librte_pmd_bond/rte_eth_bond_pmd.c index 3db473b..bb4a537 100644 --- a/lib/librte_pmd_bond/rte_eth_bond_pmd.c +++ b/lib/librte_pmd_bond/rte_eth_bond_pmd.c @@ -764,8 +764,6 @@ mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr) { struct ether_addr *mac_addr; - mac_addr = eth_dev->data->mac_addrs; - if (eth_dev == NULL) { RTE_LOG(ERR, PMD, "%s: NULL pointer eth_dev specified\n", __func__); return -1; @@ -776,6 +774,8 @@ mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr) return -1; } + mac_addr = eth_dev->data->mac_addrs; + ether_addr_copy(mac_addr, dst_mac_addr); return 0; } @@ -785,8 +785,6 @@ mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr) { struct ether_addr *mac_addr; - mac_addr = eth_dev->data->mac_addrs; - if (eth_dev == NULL) { RTE_BOND_LOG(ERR, "NULL pointer eth_dev specified"); return -1; @@ -797,6 +795,8 @@ mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr) return -1; } + mac_addr = eth_dev->data->mac_addrs; + /* If new MAC is different to current MAC then update */ if (memcmp(mac_addr, new_mac_addr, sizeof(*mac_addr)) != 0) memcpy(mac_addr, new_mac_addr, sizeof(*mac_addr)); -- 1.7.12.2