[dpdk-dev,2/3] vhost: check that a device exists during reset_owner

Message ID 1444986530-20893-3-git-send-email-jerome.jutteau@outscale.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Jerome Jutteau Oct. 16, 2015, 9:08 a.m. UTC
  virtio-net search for it's device in reset_owner.
The function don't check the return result of get_config_ll_entry
which can be NULL.

Signed-off-by: Jerome Jutteau <jerome.jutteau@outscale.com>
---
 lib/librte_vhost/virtio-net.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Yuanhan Liu Oct. 19, 2015, 4:35 a.m. UTC | #1
On Fri, Oct 16, 2015 at 11:08:49AM +0200, Jerome Jutteau wrote:
> virtio-net search for it's device in reset_owner.
> The function don't check the return result of get_config_ll_entry
> which can be NULL.
> 
> Signed-off-by: Jerome Jutteau <jerome.jutteau@outscale.com>
> ---
>  lib/librte_vhost/virtio-net.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
> index 955a29d..ec6a575 100644
> --- a/lib/librte_vhost/virtio-net.c
> +++ b/lib/librte_vhost/virtio-net.c
> @@ -402,6 +402,8 @@ reset_owner(struct vhost_device_ctx ctx)
>  	uint64_t device_fh;
>  
>  	ll_dev = get_config_ll_entry(ctx);
> +	if (ll_dev == NULL)
> +		return -1;

I would call get_device() here, which dumps an error message when
it's NULL so that user will get noticed.

Besides that, the 3 patches look good to me, and,

Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

	--yliu

>  	device_fh = ll_dev->dev.device_fh;
>  
>  	cleanup_device(&ll_dev->dev);
> -- 
> jerome
  
Jerome Jutteau Oct. 19, 2015, 9:42 a.m. UTC | #2
Hi Yuanhan,

2015-10-19 6:35 GMT+02:00 Yuanhan Liu <yuanhan.liu@linux.intel.com>:
> I would call get_device() here, which dumps an error message when
> it's NULL so that user will get noticed.
>
> Besides that, the 3 patches look good to me, and,
>
> Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

Thanks for your review, a v2 is coming soon with get_device().
  

Patch

diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 955a29d..ec6a575 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -402,6 +402,8 @@  reset_owner(struct vhost_device_ctx ctx)
 	uint64_t device_fh;
 
 	ll_dev = get_config_ll_entry(ctx);
+	if (ll_dev == NULL)
+		return -1;
 	device_fh = ll_dev->dev.device_fh;
 
 	cleanup_device(&ll_dev->dev);