[v2] net/virtio-user: fix run close(0) and close callfd

Message ID 1607706688-9839-1-git-send-email-17826875952@163.com (mailing list archive)
State Rejected, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] net/virtio-user: fix run close(0) and close callfd |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK

Commit Message

Jiawei Zhu Dec. 11, 2020, 5:11 p.m. UTC
  From: Jiawei Zhu <zhujiawei12@huawei.com>

When i < VIRTIO_MAX_VIRTQUEUES and j == i,
dev->callfds[i] and dev->kickfds[i] are default 0.
So it will close(0), close the standard input (stdin).
And when the code fails in kickfd creation,
it will leaves one callfd not closed.

Fixes: e6e7ad8b3024 ("net/virtio-user: move eventfd open/close into init/uninit")
Cc: stable@dpdk.org:

Signed-off-by: Jiawei Zhu <zhujiawei12@huawei.com>
---
v2:
* Add close callfd when fail in kickfd creation before break.
---
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Maxime Coquelin Jan. 7, 2021, 10:36 a.m. UTC | #1
Cc'ing stable@dpdk.org.

On 12/11/20 6:11 PM, Jiawei Zhu wrote:
> From: Jiawei Zhu <zhujiawei12@huawei.com>
> 
> When i < VIRTIO_MAX_VIRTQUEUES and j == i,
> dev->callfds[i] and dev->kickfds[i] are default 0.
> So it will close(0), close the standard input (stdin).
> And when the code fails in kickfd creation,
> it will leaves one callfd not closed.
> 
> Fixes: e6e7ad8b3024 ("net/virtio-user: move eventfd open/close into init/uninit")
> Cc: stable@dpdk.org:
> 
> Signed-off-by: Jiawei Zhu <zhujiawei12@huawei.com>
> ---
> v2:
> * Add close callfd when fail in kickfd creation before break.
> ---
> ---
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 053f026..e1cbad0 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -276,6 +276,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
>  		}
>  		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
>  		if (kickfd < 0) {
> +			close(callfd);
>  			PMD_DRV_LOG(ERR, "kickfd error, %s", strerror(errno));
>  			break;
>  		}
> @@ -284,7 +285,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
>  	}
>  
>  	if (i < VIRTIO_MAX_VIRTQUEUES) {
> -		for (j = 0; j <= i; ++j) {
> +		for (j = 0; j < i; ++j) {
>  			close(dev->callfds[j]);
>  			close(dev->kickfds[j]);
>  		}
> 


Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks!
Maxime
  
Maxime Coquelin Jan. 8, 2021, 9:14 a.m. UTC | #2
On 12/11/20 6:11 PM, Jiawei Zhu wrote:
> From: Jiawei Zhu <zhujiawei12@huawei.com>
> 
> When i < VIRTIO_MAX_VIRTQUEUES and j == i,
> dev->callfds[i] and dev->kickfds[i] are default 0.
> So it will close(0), close the standard input (stdin).
> And when the code fails in kickfd creation,
> it will leaves one callfd not closed.
> 
> Fixes: e6e7ad8b3024 ("net/virtio-user: move eventfd open/close into init/uninit")
> Cc: stable@dpdk.org:
> 
> Signed-off-by: Jiawei Zhu <zhujiawei12@huawei.com>
> ---
> v2:
> * Add close callfd when fail in kickfd creation before break.
> ---
> ---
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)


Series applied to dpdk-next-virtio/main.

Thanks,
Maxime
  

Patch

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 053f026..e1cbad0 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -276,6 +276,7 @@  int virtio_user_stop_device(struct virtio_user_dev *dev)
 		}
 		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (kickfd < 0) {
+			close(callfd);
 			PMD_DRV_LOG(ERR, "kickfd error, %s", strerror(errno));
 			break;
 		}
@@ -284,7 +285,7 @@  int virtio_user_stop_device(struct virtio_user_dev *dev)
 	}
 
 	if (i < VIRTIO_MAX_VIRTQUEUES) {
-		for (j = 0; j <= i; ++j) {
+		for (j = 0; j < i; ++j) {
 			close(dev->callfds[j]);
 			close(dev->kickfds[j]);
 		}