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 E35288E6E for ; Fri, 11 Dec 2015 02:49:11 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 10 Dec 2015 17:49:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,410,1444719600"; d="scan'208";a="616166369" Received: from shilc102.sh.intel.com ([10.239.39.44]) by FMSMGA003.fm.intel.com with ESMTP; 10 Dec 2015 17:49:10 -0800 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shilc102.sh.intel.com with ESMTP id tBB1n8rk002418; Fri, 11 Dec 2015 09:49:08 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id tBB1n5xJ003257; Fri, 11 Dec 2015 09:49:07 +0800 Received: (from cliang18@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id tBB1mxmH003253; Fri, 11 Dec 2015 09:48:59 +0800 From: Cunming Liang To: dev@dpdk.org Date: Fri, 11 Dec 2015 09:48:57 +0800 Message-Id: <1449798537-3221-1-git-send-email-cunming.liang@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH v1] eal: fix negative value incorrectly being used defect 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, 11 Dec 2015 01:49:12 -0000 In eal_intr_proc_rxtx_intr, negative value may be used as argument to a function expecting a positive value. If 'read' returns EAGAIN as example, the bytes_read updates to a negative value which continue be passed as argument for the next 'read'. Coverity issue: 107115 927 do { 3. negative_return_fn: Function read(fd, &buf, bytes_read) returns a negative number. 4. var_assign: Assigning: signed variable bytes_read = read. CID 107115 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)9. negative_returns: bytes_read is passed to a parameter that cannot be negative. 928 bytes_read = read(fd, &buf, bytes_read); Fixes: c9f3ec1a0f3f ("eal/linux: add Rx interrupt control function") Signed-off-by: Cunming Liang --- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 470d6a1..06b26a9 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -901,6 +901,7 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle) { union rte_intr_read_buffer buf; int bytes_read = 1; + int nbytes; switch (intr_handle->type) { case RTE_INTR_HANDLE_UIO: @@ -925,15 +926,15 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle) * for epoll_wait. */ do { - bytes_read = read(fd, &buf, bytes_read); - if (bytes_read < 0) { + nbytes = read(fd, &buf, bytes_read); + if (nbytes < 0) { if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) continue; RTE_LOG(ERR, EAL, "Error reading from fd %d: %s\n", fd, strerror(errno)); - } else if (bytes_read == 0) + } else if (nbytes == 0) RTE_LOG(ERR, EAL, "Read nothing from fd %d\n", fd); return; } while (1); -- 2.4.3