From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id D1A4D4F91; Thu, 4 Apr 2019 08:52:21 +0200 (CEST) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 23:52:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="161266356" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.110.206]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 23:52:18 -0700 Date: Thu, 4 Apr 2019 14:47:24 +0800 From: Ye Xiaolong To: Tiwei Bie Cc: Mohammad Abdul Awal , dev@dpdk.org, maxime.coquelin@redhat.com, zhihong.wang@intel.com, stable@dpdk.org Message-ID: <20190404064724.GA33544@intel.com> References: <20190403160823.1337-1-mohammad.abdul.awal@intel.com> <20190404060354.GA5423@dpdk-tbie.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190404060354.GA5423@dpdk-tbie.sh.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH 3/3] vhost: fix null pointer checking X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Apr 2019 06:52:22 -0000 Hi, Tiwei, On 04/04, Tiwei Bie wrote: [snip] >> @@ -515,7 +515,7 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len) >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (dev == NULL) >> + if (dev == NULL || !buf) > >It would be better to do the check in this way: (!dev || !buf) >for consistency. > According to DPDK coding conventions 1.8.1 on NULL pointers [1], shouldn't it be if (dev == NULL || buf == NULL)? [1] https://doc.dpdk.org/guides/contributing/coding_style.html#null-pointers Thanks, Xiaolong >Thanks for the work! >Tiwei > > >> return -1; >> >> len = RTE_MIN(len, sizeof(dev->ifname)); >> @@ -532,7 +532,7 @@ rte_vhost_get_negotiated_features(int vid, uint64_t *features) >> struct virtio_net *dev; >> >> dev = get_device(vid); >> - if (!dev) >> + if (!dev || !features) >> return -1; >> >> *features = dev->features; >> @@ -547,7 +547,7 @@ rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem) >> size_t size; >> >> dev = get_device(vid); >> - if (!dev) >> + if (!dev || !mem) >> return -1; >> >> size = dev->mem->nregions * sizeof(struct rte_vhost_mem_region); >> @@ -570,7 +570,7 @@ rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, >> struct vhost_virtqueue *vq; >> >> dev = get_device(vid); >> - if (!dev) >> + if (!dev || !vring) >> return -1; >> >> if (vring_idx >= VHOST_MAX_VRING) >> @@ -763,7 +763,7 @@ int rte_vhost_get_log_base(int vid, uint64_t *log_base, >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (!dev) >> + if (!dev || !log_base || !log_size) >> return -1; >> >> *log_base = dev->log_base; >> @@ -777,7 +777,7 @@ int rte_vhost_get_vring_base(int vid, uint16_t queue_id, >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (!dev) >> + if (!dev || !last_avail_idx || !last_used_idx) >> return -1; >> >> *last_avail_idx = dev->virtqueue[queue_id]->last_avail_idx; >> @@ -805,7 +805,7 @@ int rte_vhost_extern_callback_register(int vid, >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (!dev) >> + if (!dev || !ops) >> return -1; >> >> dev->extern_ops = *ops; >> -- >> 2.17.1 >> From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id DE679A0679 for ; Thu, 4 Apr 2019 08:52:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2CBEB5323; Thu, 4 Apr 2019 08:52:24 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id D1A4D4F91; Thu, 4 Apr 2019 08:52:21 +0200 (CEST) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 23:52:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="161266356" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.110.206]) by fmsmga001.fm.intel.com with ESMTP; 03 Apr 2019 23:52:18 -0700 Date: Thu, 4 Apr 2019 14:47:24 +0800 From: Ye Xiaolong To: Tiwei Bie Cc: Mohammad Abdul Awal , dev@dpdk.org, maxime.coquelin@redhat.com, zhihong.wang@intel.com, stable@dpdk.org Message-ID: <20190404064724.GA33544@intel.com> References: <20190403160823.1337-1-mohammad.abdul.awal@intel.com> <20190404060354.GA5423@dpdk-tbie.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline In-Reply-To: <20190404060354.GA5423@dpdk-tbie.sh.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH 3/3] vhost: fix null pointer checking X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190404064724.lpPcTBX9N85tX80ANeShYeJesZGOYazo47uFZ8skvac@z> Hi, Tiwei, On 04/04, Tiwei Bie wrote: [snip] >> @@ -515,7 +515,7 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len) >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (dev == NULL) >> + if (dev == NULL || !buf) > >It would be better to do the check in this way: (!dev || !buf) >for consistency. > According to DPDK coding conventions 1.8.1 on NULL pointers [1], shouldn't it be if (dev == NULL || buf == NULL)? [1] https://doc.dpdk.org/guides/contributing/coding_style.html#null-pointers Thanks, Xiaolong >Thanks for the work! >Tiwei > > >> return -1; >> >> len = RTE_MIN(len, sizeof(dev->ifname)); >> @@ -532,7 +532,7 @@ rte_vhost_get_negotiated_features(int vid, uint64_t *features) >> struct virtio_net *dev; >> >> dev = get_device(vid); >> - if (!dev) >> + if (!dev || !features) >> return -1; >> >> *features = dev->features; >> @@ -547,7 +547,7 @@ rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem) >> size_t size; >> >> dev = get_device(vid); >> - if (!dev) >> + if (!dev || !mem) >> return -1; >> >> size = dev->mem->nregions * sizeof(struct rte_vhost_mem_region); >> @@ -570,7 +570,7 @@ rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, >> struct vhost_virtqueue *vq; >> >> dev = get_device(vid); >> - if (!dev) >> + if (!dev || !vring) >> return -1; >> >> if (vring_idx >= VHOST_MAX_VRING) >> @@ -763,7 +763,7 @@ int rte_vhost_get_log_base(int vid, uint64_t *log_base, >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (!dev) >> + if (!dev || !log_base || !log_size) >> return -1; >> >> *log_base = dev->log_base; >> @@ -777,7 +777,7 @@ int rte_vhost_get_vring_base(int vid, uint16_t queue_id, >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (!dev) >> + if (!dev || !last_avail_idx || !last_used_idx) >> return -1; >> >> *last_avail_idx = dev->virtqueue[queue_id]->last_avail_idx; >> @@ -805,7 +805,7 @@ int rte_vhost_extern_callback_register(int vid, >> { >> struct virtio_net *dev = get_device(vid); >> >> - if (!dev) >> + if (!dev || !ops) >> return -1; >> >> dev->extern_ops = *ops; >> -- >> 2.17.1 >>