All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vdpa/mlx5: fix error handling in mlx5_vdpa_dev_add()
@ 2022-01-07 21:13 trix
  2022-01-08  1:49   ` Si-Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: trix @ 2022-01-07 21:13 UTC (permalink / raw)
  To: mst, jasowang, nathan, ndesaulniers, elic, parav, si-wei.liu, xieyongji
  Cc: virtualization, linux-kernel, llvm, Tom Rix

From: Tom Rix <trix@redhat.com>

Clang build fails with
mlx5_vnet.c:2574:6: error: variable 'mvdev' is used uninitialized whenever
  'if' condition is true
        if (!ndev->vqs || !ndev->event_cbs) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mlx5_vnet.c:2660:14: note: uninitialized use occurs here
        put_device(&mvdev->vdev.dev);
                    ^~~~~
This because mvdev is set after trying to allocate ndev->vqs,event_cbs.
So move the allocation to after mvdev is set but before the arrays
are used in init_mvqs()

Fixes: 7620d51af29a ("vdpa/mlx5: Support configuring max data virtqueue")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index b564c70475815..37220f6db7ad7 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2569,16 +2569,18 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	if (IS_ERR(ndev))
 		return PTR_ERR(ndev);
 
+	ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
+	ndev->mvdev.max_vqs = max_vqs;
+	mvdev = &ndev->mvdev;
+	mvdev->mdev = mdev;
+
 	ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL);
 	ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL);
 	if (!ndev->vqs || !ndev->event_cbs) {
 		err = -ENOMEM;
 		goto err_alloc;
 	}
-	ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
-	ndev->mvdev.max_vqs = max_vqs;
-	mvdev = &ndev->mvdev;
-	mvdev->mdev = mdev;
+
 	init_mvqs(ndev);
 	mutex_init(&ndev->reslock);
 	config = &ndev->config;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] vdpa/mlx5: fix error handling in mlx5_vdpa_dev_add()
  2022-01-07 21:13 [PATCH] vdpa/mlx5: fix error handling in mlx5_vdpa_dev_add() trix
@ 2022-01-08  1:49   ` Si-Wei Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Si-Wei Liu @ 2022-01-08  1:49 UTC (permalink / raw)
  To: trix, mst, jasowang, nathan, ndesaulniers, elic, parav, xieyongji
  Cc: virtualization, linux-kernel, llvm


The proposed fix looks fine, but I still hope this to revert this series 
if at all possible. The review hadn't been done yet.

On 1/7/2022 1:13 PM, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> Clang build fails with
> mlx5_vnet.c:2574:6: error: variable 'mvdev' is used uninitialized whenever
>    'if' condition is true
>          if (!ndev->vqs || !ndev->event_cbs) {
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mlx5_vnet.c:2660:14: note: uninitialized use occurs here
>          put_device(&mvdev->vdev.dev);
>                      ^~~~~
> This because mvdev is set after trying to allocate ndev->vqs,event_cbs.
> So move the allocation to after mvdev is set but before the arrays
> are used in init_mvqs()
>
> Fixes: 7620d51af29a ("vdpa/mlx5: Support configuring max data virtqueue")
> Signed-off-by: Tom Rix <trix@redhat.com>

Reviewed-by: Si-Wei Liu<si-wei.liu@oracle.com>
> ---
>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index b564c70475815..37220f6db7ad7 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -2569,16 +2569,18 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>   	if (IS_ERR(ndev))
>   		return PTR_ERR(ndev);
>   
> +	ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
> +	ndev->mvdev.max_vqs = max_vqs;
> +	mvdev = &ndev->mvdev;
> +	mvdev->mdev = mdev;
> +
>   	ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL);
>   	ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL);
>   	if (!ndev->vqs || !ndev->event_cbs) {
>   		err = -ENOMEM;
>   		goto err_alloc;
>   	}
> -	ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
> -	ndev->mvdev.max_vqs = max_vqs;
> -	mvdev = &ndev->mvdev;
> -	mvdev->mdev = mdev;
> +
>   	init_mvqs(ndev);
>   	mutex_init(&ndev->reslock);
>   	config = &ndev->config;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vdpa/mlx5: fix error handling in mlx5_vdpa_dev_add()
@ 2022-01-08  1:49   ` Si-Wei Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Si-Wei Liu @ 2022-01-08  1:49 UTC (permalink / raw)
  To: trix, mst, jasowang, nathan, ndesaulniers, elic, parav, xieyongji
  Cc: llvm, linux-kernel, virtualization


The proposed fix looks fine, but I still hope this to revert this series 
if at all possible. The review hadn't been done yet.

On 1/7/2022 1:13 PM, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> Clang build fails with
> mlx5_vnet.c:2574:6: error: variable 'mvdev' is used uninitialized whenever
>    'if' condition is true
>          if (!ndev->vqs || !ndev->event_cbs) {
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mlx5_vnet.c:2660:14: note: uninitialized use occurs here
>          put_device(&mvdev->vdev.dev);
>                      ^~~~~
> This because mvdev is set after trying to allocate ndev->vqs,event_cbs.
> So move the allocation to after mvdev is set but before the arrays
> are used in init_mvqs()
>
> Fixes: 7620d51af29a ("vdpa/mlx5: Support configuring max data virtqueue")
> Signed-off-by: Tom Rix <trix@redhat.com>

Reviewed-by: Si-Wei Liu<si-wei.liu@oracle.com>
> ---
>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index b564c70475815..37220f6db7ad7 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -2569,16 +2569,18 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>   	if (IS_ERR(ndev))
>   		return PTR_ERR(ndev);
>   
> +	ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
> +	ndev->mvdev.max_vqs = max_vqs;
> +	mvdev = &ndev->mvdev;
> +	mvdev->mdev = mdev;
> +
>   	ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL);
>   	ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL);
>   	if (!ndev->vqs || !ndev->event_cbs) {
>   		err = -ENOMEM;
>   		goto err_alloc;
>   	}
> -	ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
> -	ndev->mvdev.max_vqs = max_vqs;
> -	mvdev = &ndev->mvdev;
> -	mvdev->mdev = mdev;
> +
>   	init_mvqs(ndev);
>   	mutex_init(&ndev->reslock);
>   	config = &ndev->config;

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-08  1:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 21:13 [PATCH] vdpa/mlx5: fix error handling in mlx5_vdpa_dev_add() trix
2022-01-08  1:49 ` Si-Wei Liu
2022-01-08  1:49   ` Si-Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.