From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id BB56B5927 for ; Thu, 27 Aug 2015 19:30:14 +0200 (CEST) Received: from uucp by smtp.tuxdriver.com with local-rmail (Exim 4.63) (envelope-from ) id 1ZV108-00073H-Cq; Thu, 27 Aug 2015 13:30:12 -0400 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.15.1/8.14.6) with ESMTP id t7RHHF8v028835; Thu, 27 Aug 2015 13:17:15 -0400 Received: (from linville@localhost) by localhost.localdomain (8.15.1/8.15.1/Submit) id t7RHHFAD028832; Thu, 27 Aug 2015 13:17:15 -0400 X-Authentication-Warning: localhost.localdomain: linville set sender to linville@tuxdriver.com using -f From: "John W. Linville" To: dev@dpdk.org Date: Thu, 27 Aug 2015 13:17:13 -0400 Message-Id: <1440695833-28778-1-git-send-email-linville@tuxdriver.com> X-Mailer: git-send-email 2.4.3 Subject: [dpdk-dev] [PATCH] rte_eth_af_packet: refactor error handling to avoid NULL pointer dereference 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: Thu, 27 Aug 2015 17:30:15 -0000 Coverity CID # 13321 Checking *internals != NULL before accessing req is not good enough, because **internals is a function argument and the function doesn't really know what is passed-in. We can close our eyes and ignore the warning on the basis of controlling all the calling code, or we can refactor the error exit to avoid the issue entirely... Signed-off-by: John W. Linville --- drivers/net/af_packet/rte_eth_af_packet.c | 44 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index bdd9628674cb..cac26e533813 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -454,7 +454,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: no interface specified for AF_PACKET ethdev\n", name); - goto error; + goto error_early; } RTE_LOG(INFO, PMD, @@ -467,16 +467,16 @@ rte_pmd_init_internals(const char *name, */ data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node); if (data == NULL) - goto error; + goto error_early; pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, numa_node); if (pci_dev == NULL) - goto error; + goto error_early; *internals = rte_zmalloc_socket(name, sizeof(**internals), 0, numa_node); if (*internals == NULL) - goto error; + goto error_early; for (q = 0; q < nb_queues; q++) { (*internals)->rx_queue[q].map = MAP_FAILED; @@ -498,13 +498,13 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: I/F name too long (%s)\n", name, pair->value); - goto error; + goto error_early; } if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) { RTE_LOG(ERR, PMD, "%s: ioctl failed (SIOCGIFINDEX)\n", name); - goto error; + goto error_early; } (*internals)->if_index = ifr.ifr_ifindex; @@ -512,7 +512,7 @@ rte_pmd_init_internals(const char *name, RTE_LOG(ERR, PMD, "%s: ioctl failed (SIOCGIFHWADDR)\n", name); - goto error; + goto error_early; } memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); @@ -678,24 +678,22 @@ rte_pmd_init_internals(const char *name, return 0; error: - rte_free(data); - rte_free(pci_dev); - - if (*internals) { - for (q = 0; q < nb_queues; q++) { - munmap((*internals)->rx_queue[q].map, - 2 * req->tp_block_size * req->tp_block_nr); - - rte_free((*internals)->rx_queue[q].rd); - rte_free((*internals)->tx_queue[q].rd); - if (((*internals)->rx_queue[q].sockfd != 0) && - ((*internals)->rx_queue[q].sockfd != qsockfd)) - close((*internals)->rx_queue[q].sockfd); - } - rte_free(*internals); - } if (qsockfd != -1) close(qsockfd); + for (q = 0; q < nb_queues; q++) { + munmap((*internals)->rx_queue[q].map, + 2 * req->tp_block_size * req->tp_block_nr); + + rte_free((*internals)->rx_queue[q].rd); + rte_free((*internals)->tx_queue[q].rd); + if (((*internals)->rx_queue[q].sockfd != 0) && + ((*internals)->rx_queue[q].sockfd != qsockfd)) + close((*internals)->rx_queue[q].sockfd); + } + rte_free(*internals); +error_early: + rte_free(pci_dev); + rte_free(data); return -1; } -- 2.4.3