From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id DEBA058CB; Thu, 4 Apr 2019 09:01:55 +0200 (CEST) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Apr 2019 00:01:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="140011006" Received: from dpdk-tbie.sh.intel.com ([10.67.104.173]) by fmsmga007.fm.intel.com with ESMTP; 04 Apr 2019 00:01:53 -0700 Date: Thu, 4 Apr 2019 15:01:27 +0800 From: Tiwei Bie To: Ye Xiaolong Cc: Mohammad Abdul Awal , dev@dpdk.org, maxime.coquelin@redhat.com, zhihong.wang@intel.com, stable@dpdk.org Message-ID: <20190404070127.GA12175@dpdk-tbie.sh.intel.com> References: <20190403160823.1337-1-mohammad.abdul.awal@intel.com> <20190404060354.GA5423@dpdk-tbie.sh.intel.com> <20190404064724.GA33544@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190404064724.GA33544@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 07:01:56 -0000 On Thu, Apr 04, 2019 at 02:47:24PM +0800, Ye Xiaolong wrote: > 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)? Agree, this is more preferred. Thanks, Tiwei > > [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 40470A0679 for ; Thu, 4 Apr 2019 09:01:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C63645911; Thu, 4 Apr 2019 09:01:57 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id DEBA058CB; Thu, 4 Apr 2019 09:01:55 +0200 (CEST) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Apr 2019 00:01:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="140011006" Received: from dpdk-tbie.sh.intel.com ([10.67.104.173]) by fmsmga007.fm.intel.com with ESMTP; 04 Apr 2019 00:01:53 -0700 Date: Thu, 4 Apr 2019 15:01:27 +0800 From: Tiwei Bie To: Ye Xiaolong Cc: Mohammad Abdul Awal , dev@dpdk.org, maxime.coquelin@redhat.com, zhihong.wang@intel.com, stable@dpdk.org Message-ID: <20190404070127.GA12175@dpdk-tbie.sh.intel.com> References: <20190403160823.1337-1-mohammad.abdul.awal@intel.com> <20190404060354.GA5423@dpdk-tbie.sh.intel.com> <20190404064724.GA33544@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline In-Reply-To: <20190404064724.GA33544@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: <20190404070127.jPMEpSslxwx0z19JaGZiFGWjq0huInGhvvIcMxMxn24@z> On Thu, Apr 04, 2019 at 02:47:24PM +0800, Ye Xiaolong wrote: > 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)? Agree, this is more preferred. Thanks, Tiwei > > [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 > >>