net/virtio-user: fix return value not checked
authorJianfeng Tan <jianfeng.tan@intel.com>
Wed, 29 Jun 2016 09:05:33 +0000 (09:05 +0000)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Tue, 5 Jul 2016 11:30:00 +0000 (13:30 +0200)
When return values of function calls are not checked, Coverity will
report errors like:

    if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PATH) == 1)
    >>>     CID 127477:    (CHECKED_RETURN)
    >>>     Calling "rte_kvargs_process" without checking return value
            (as is done elsewhere 25 out of 30 times).
          rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PATH,
             &get_string_arg, &path);

Coverity issue: 127477, 127478
Fixes: ce2eabdd43ec ("net/virtio-user: add virtual device")
Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
drivers/net/virtio/virtio_user/vhost_user.c
drivers/net/virtio/virtio_user_ethdev.c

index a2b0687..a159ece 100644 (file)
@@ -392,7 +392,8 @@ vhost_user_setup(const char *path)
        }
 
        flag = fcntl(fd, F_GETFD);
-       fcntl(fd, F_SETFD, flag | FD_CLOEXEC);
+       if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
+               PMD_DRV_LOG(WARNING, "fcntl failed, %s", strerror(errno));
 
        memset(&un, 0, sizeof(un));
        un.sun_family = AF_UNIX;
index 27b6d60..dc6f0dd 100644 (file)
@@ -343,31 +343,60 @@ virtio_user_pmd_devinit(const char *name, const char *params)
        }
 
        if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PATH) == 1)
-               rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PATH,
-                                  &get_string_arg, &path);
+               ret = rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PATH,
+                                        &get_string_arg, &path);
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "error to parse %s",
+                                    VIRTIO_USER_ARG_PATH);
+                       goto end;
+               }
        else {
                PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio-user\n",
                          VIRTIO_USER_ARG_QUEUE_SIZE);
                goto end;
        }
 
-       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MAC) == 1)
-               rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MAC,
-                                  &get_string_arg, &mac_addr);
+       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MAC) == 1) {
+               ret = rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MAC,
+                                        &get_string_arg, &mac_addr);
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "error to parse %s",
+                                    VIRTIO_USER_ARG_MAC);
+                       goto end;
+               }
+       }
 
-       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE) == 1)
-               rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE,
-                                  &get_integer_arg, &queue_size);
+       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE) == 1) {
+               ret = rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE,
+                                        &get_integer_arg, &queue_size);
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "error to parse %s",
+                                    VIRTIO_USER_ARG_QUEUE_SIZE);
+                       goto end;
+               }
+       }
 
-       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUES_NUM) == 1)
-               rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUES_NUM,
-                                  &get_integer_arg, &queues);
+       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUES_NUM) == 1) {
+               ret = rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUES_NUM,
+                                        &get_integer_arg, &queues);
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "error to parse %s",
+                                    VIRTIO_USER_ARG_QUEUES_NUM);
+                       goto end;
+               }
+       }
 
-       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1)
-               rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM,
-                                  &get_integer_arg, &cq);
-       else if (queues > 1)
+       if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1) {
+               ret = rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM,
+                                        &get_integer_arg, &cq);
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "error to parse %s",
+                                    VIRTIO_USER_ARG_CQ_NUM);
+                       goto end;
+               }
+       } else if (queues > 1) {
                cq = 1;
+       }
 
        if (queues > 1 && cq == 0) {
                PMD_INIT_LOG(ERR, "multi-q requires ctrl-q");