net/vhost: fix return value of vhost creates not checked

Message ID 1576458359-13848-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series net/vhost: fix return value of vhost creates not checked |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation fail apply issues

Commit Message

Yunjian Wang Dec. 16, 2019, 1:05 a.m. UTC
  The function eth_dev_vhost_create() could return errors,
the return value need to be checked.

Fixes: ee584e9710b9 ("vhost: add driver on top of the library")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Tiwei Bie Dec. 16, 2019, 5:33 a.m. UTC | #1
On Mon, Dec 16, 2019 at 09:05:59AM +0800, Yunjian Wang wrote:
> The function eth_dev_vhost_create() could return errors,
> the return value need to be checked.
> 
> Fixes: ee584e9710b9 ("vhost: add driver on top of the library")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/vhost/rte_eth_vhost.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
> index 46f01a7..7e4faf2 100644
> --- a/drivers/net/vhost/rte_eth_vhost.c
> +++ b/drivers/net/vhost/rte_eth_vhost.c
> @@ -1455,8 +1455,10 @@ struct vhost_xstats_name_off {
>  	if (dev->device.numa_node == SOCKET_ID_ANY)
>  		dev->device.numa_node = rte_socket_id();
>  
> -	eth_dev_vhost_create(dev, iface_name, queues, dev->device.numa_node,
> -		flags, disable_flags);
> +	ret = eth_dev_vhost_create(dev, iface_name, queues,
> +			dev->device.numa_node, flags, disable_flags);
> +	if (ret == -1)
> +		VHOST_LOG(ERR, "Failed to create %s", name);

This will set "ret" to port id on success,
but we shouldn't return port id in probe.

>  
>  out_free:
>  	rte_kvargs_free(kvlist);
> -- 
> 1.8.3.1
> 
>
  
Yunjian Wang Dec. 16, 2019, 6:38 a.m. UTC | #2
> -----Original Message-----
> From: Tiwei Bie [mailto:tiwei.bie@intel.com]
> Sent: Monday, December 16, 2019 1:33 PM
> To: wangyunjian <wangyunjian@huawei.com>
> Cc: dev@dpdk.org; maxime.coquelin@redhat.com; zhihong.wang@intel.com;
> xudingke <xudingke@huawei.com>; stable@dpdk.org
> Subject: Re: [PATCH] net/vhost: fix return value of vhost creates not checked
> 
> On Mon, Dec 16, 2019 at 09:05:59AM +0800, Yunjian Wang wrote:
> > The function eth_dev_vhost_create() could return errors, the return
> > value need to be checked.
> >
> > Fixes: ee584e9710b9 ("vhost: add driver on top of the library")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  drivers/net/vhost/rte_eth_vhost.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/vhost/rte_eth_vhost.c
> > b/drivers/net/vhost/rte_eth_vhost.c
> > index 46f01a7..7e4faf2 100644
> > --- a/drivers/net/vhost/rte_eth_vhost.c
> > +++ b/drivers/net/vhost/rte_eth_vhost.c
> > @@ -1455,8 +1455,10 @@ struct vhost_xstats_name_off {
> >  	if (dev->device.numa_node == SOCKET_ID_ANY)
> >  		dev->device.numa_node = rte_socket_id();
> >
> > -	eth_dev_vhost_create(dev, iface_name, queues, dev->device.numa_node,
> > -		flags, disable_flags);
> > +	ret = eth_dev_vhost_create(dev, iface_name, queues,
> > +			dev->device.numa_node, flags, disable_flags);
> > +	if (ret == -1)
> > +		VHOST_LOG(ERR, "Failed to create %s", name);
> 
> This will set "ret" to port id on success, but we shouldn't return port id in
> probe.

OK, I agree. How about function eth_dev_vhost_create can return 0 on success?

Thanks
Yunjian

> 
> >
> >  out_free:
> >  	rte_kvargs_free(kvlist);
> > --
> > 1.8.3.1
> >
> >
  
Tiwei Bie Dec. 17, 2019, 1:21 a.m. UTC | #3
On Mon, Dec 16, 2019 at 06:38:28AM +0000, wangyunjian wrote:
> > -----Original Message-----
> > From: Tiwei Bie [mailto:tiwei.bie@intel.com]
> > Sent: Monday, December 16, 2019 1:33 PM
> > To: wangyunjian <wangyunjian@huawei.com>
> > Cc: dev@dpdk.org; maxime.coquelin@redhat.com; zhihong.wang@intel.com;
> > xudingke <xudingke@huawei.com>; stable@dpdk.org
> > Subject: Re: [PATCH] net/vhost: fix return value of vhost creates not checked
> > 
> > On Mon, Dec 16, 2019 at 09:05:59AM +0800, Yunjian Wang wrote:
> > > The function eth_dev_vhost_create() could return errors, the return
> > > value need to be checked.
> > >
> > > Fixes: ee584e9710b9 ("vhost: add driver on top of the library")
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > > ---
> > >  drivers/net/vhost/rte_eth_vhost.c | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/net/vhost/rte_eth_vhost.c
> > > b/drivers/net/vhost/rte_eth_vhost.c
> > > index 46f01a7..7e4faf2 100644
> > > --- a/drivers/net/vhost/rte_eth_vhost.c
> > > +++ b/drivers/net/vhost/rte_eth_vhost.c
> > > @@ -1455,8 +1455,10 @@ struct vhost_xstats_name_off {
> > >  	if (dev->device.numa_node == SOCKET_ID_ANY)
> > >  		dev->device.numa_node = rte_socket_id();
> > >
> > > -	eth_dev_vhost_create(dev, iface_name, queues, dev->device.numa_node,
> > > -		flags, disable_flags);
> > > +	ret = eth_dev_vhost_create(dev, iface_name, queues,
> > > +			dev->device.numa_node, flags, disable_flags);
> > > +	if (ret == -1)
> > > +		VHOST_LOG(ERR, "Failed to create %s", name);
> > 
> > This will set "ret" to port id on success, but we shouldn't return port id in
> > probe.
> 
> OK, I agree. How about function eth_dev_vhost_create can return 0 on success?

Sounds good to me.

> 
> Thanks
> Yunjian
> 
> > 
> > >
> > >  out_free:
> > >  	rte_kvargs_free(kvlist);
> > > --
> > > 1.8.3.1
> > >
> > >
  

Patch

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 46f01a7..7e4faf2 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1455,8 +1455,10 @@  struct vhost_xstats_name_off {
 	if (dev->device.numa_node == SOCKET_ID_ANY)
 		dev->device.numa_node = rte_socket_id();
 
-	eth_dev_vhost_create(dev, iface_name, queues, dev->device.numa_node,
-		flags, disable_flags);
+	ret = eth_dev_vhost_create(dev, iface_name, queues,
+			dev->device.numa_node, flags, disable_flags);
+	if (ret == -1)
+		VHOST_LOG(ERR, "Failed to create %s", name);
 
 out_free:
 	rte_kvargs_free(kvlist);