From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ye Xiaolong Subject: Re: [PATCH 3/3] vhost: fix null pointer checking Date: Thu, 4 Apr 2019 14:47:24 +0800 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 Cc: Mohammad Abdul Awal , dev@dpdk.org, maxime.coquelin@redhat.com, zhihong.wang@intel.com, stable@dpdk.org To: Tiwei Bie Return-path: Content-Disposition: inline In-Reply-To: <20190404060354.GA5423@dpdk-tbie.sh.intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 >>