DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1] eal: fix negative value incorrectly being used defect
@ 2015-12-11  1:48 Cunming Liang
  2015-12-11 14:40 ` Mcnamara, John
  2015-12-11 14:54 ` David Marchand
  0 siblings, 2 replies; 4+ messages in thread
From: Cunming Liang @ 2015-12-11  1:48 UTC (permalink / raw)
  To: dev

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 <cunming.liang@intel.com>
---
 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-12 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-11  1:48 [dpdk-dev] [PATCH v1] eal: fix negative value incorrectly being used defect Cunming Liang
2015-12-11 14:40 ` Mcnamara, John
2015-12-11 14:54 ` David Marchand
2015-12-12 21:03   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).