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 00B34C45A for ; Wed, 15 Jun 2016 18:27:48 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 15 Jun 2016 09:27:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,476,1459839600"; d="scan'208";a="976340400" Received: from dpdk15.sh.intel.com ([10.239.129.25]) by orsmga001.jf.intel.com with ESMTP; 15 Jun 2016 09:27:47 -0700 From: Huawei Xie To: dev@dpdk.org Cc: yuanhan.liu@intel.com, michalx.k.jastrzebski@intel.com, Huawei Xie Date: Wed, 15 Jun 2016 08:32:45 +0800 Message-Id: <1465950765-53868-1-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.8.1.4 Subject: [dpdk-dev] [PATCH] vhost: fix dereference null return value 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: Wed, 15 Jun 2016 16:27:49 -0000 fixes the following coverity issues: CID 107118 (#1 of 1): Dereference null return value (NULL_RETURNS) CID 119262 (#1 of 1): Dereference null return value (NULL_RETURNS) Fixes: 8f972312b8f4 ("vhost: support vhost-user") Fixes: 77d20126b4c2 ("vhost-user: handle message to enable vring") Signed-off-by: Huawei Xie --- lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index 5803182..5844a42 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -283,6 +283,9 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) struct vhost_vring_file file; struct virtio_net *dev = get_device(ctx); + if (!dev) + return; + file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) file.fd = VIRTIO_INVALID_EVENTFD; @@ -306,8 +309,9 @@ user_get_vring_base(struct vhost_device_ctx ctx, { struct virtio_net *dev = get_device(ctx); - if (dev == NULL) + if (!dev) return -1; + /* We have to stop the queue (virtio) if it is running. */ if (dev->flags & VIRTIO_DEV_RUNNING) notify_ops->destroy_device(dev); @@ -341,6 +345,9 @@ user_set_vring_enable(struct vhost_device_ctx ctx, struct virtio_net *dev = get_device(ctx); int enable = (int)state->num; + if (!dev) + return -1; + RTE_LOG(INFO, VHOST_CONFIG, "set queue enable: %d to qp idx: %d\n", enable, state->index); @@ -361,7 +368,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx, struct virtio_net *dev; dev = get_device(ctx); - if (dev == NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) + if (!dev || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) return; dev->protocol_features = protocol_features; -- 1.8.1.4