From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id D0CEA569D for ; Tue, 4 Aug 2015 17:30:32 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 04 Aug 2015 08:26:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,609,1432623600"; d="scan'208";a="535863016" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by FMSMGA003.fm.intel.com with ESMTP; 04 Aug 2015 08:26:22 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t74FQLZ4002865; Tue, 4 Aug 2015 16:26:21 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t74FQKr1029283; Tue, 4 Aug 2015 16:26:20 +0100 Received: (from bairemon@localhost) by sivswdev01.ir.intel.com with id t74FQKVR029279; Tue, 4 Aug 2015 16:26:20 +0100 From: Bernard Iremonger To: dev@dpdk.org Date: Tue, 4 Aug 2015 16:26:18 +0100 Message-Id: <1438701978-29248-1-git-send-email-bernard.iremonger@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/1] bonding: fix error handling in rte_eth_bond_create() 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: Tue, 04 Aug 2015 15:30:33 -0000 if the name parameter to rte_eth_bond_create() was NULL, there was a segmentation fault. Signed-off-by: Bernard Iremonger --- drivers/net/bonding/rte_eth_bond_api.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index 4ca26dd..ffac3c9 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -194,19 +194,19 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) if (name == NULL) { RTE_BOND_LOG(ERR, "Invalid name specified"); - goto err; + goto err1; } if (socket_id >= number_of_sockets()) { RTE_BOND_LOG(ERR, "Invalid socket id specified to create bonded device on."); - goto err; + goto err1; } pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, socket_id); if (pci_dev == NULL) { RTE_BOND_LOG(ERR, "Unable to malloc pci dev on socket"); - goto err; + goto err1; } pci_drv = &rte_bond_pmd.pci_drv; @@ -214,14 +214,14 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) internals = rte_zmalloc_socket(name, sizeof(*internals), 0, socket_id); if (internals == NULL) { RTE_BOND_LOG(ERR, "Unable to malloc internals on socket"); - goto err; + goto err2; } /* reserve an ethdev entry */ eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); if (eth_dev == NULL) { RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev"); - goto err; + goto err3; } pci_dev->numa_node = socket_id; @@ -239,6 +239,10 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) eth_dev->data->mac_addrs = rte_zmalloc_socket(name, ETHER_ADDR_LEN, 0, socket_id); + if (eth_dev->data->mac_addrs == NULL) { + RTE_BOND_LOG(ERR, "Unable to malloc mac_addrs"); + goto err3; + } eth_dev->data->dev_started = 0; eth_dev->data->promiscuous = 0; @@ -277,16 +281,18 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) if (bond_ethdev_mode_set(eth_dev, mode)) { RTE_BOND_LOG(ERR, "Failed to set bonded device %d mode too %d", eth_dev->data->port_id, mode); - goto err; + goto err4; } return eth_dev->data->port_id; -err: - rte_free(pci_dev); - rte_free(internals); +err4: rte_free(eth_dev->data->mac_addrs); - +err3: + rte_free(internals); +err2: + rte_free(pci_dev); +err1: return -1; } -- 1.9.1