mlx5: vdpa: fix possible uninitialized var
Subsystems (2)
PATCH v2 1/1 mlx5: vdpa: fix possible uninitialized var
When compiling with -Werror=maybe-uninitialized, gcc may complains the possible uninitialized umem. Since the callers won't pass value other than 1 to 3, making 3 as default to fix the compiler warning.
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueuecase 2 : umem = &mvq->umem2;break ; -case 3 : +default : umem = &mvq->umem3;break ; }
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 1 line · Jason Wang
When compiling with -Werror=maybe-uninitialized, gcc may complains the
Maybe you want to fix to: gcc may complain about possible...
Other than that:
Quoted 24 lines
possible uninitialized umem. Since the callers won't pass value other than 1 to 3, making 3 as default to fix the compiler warning.
Signed-off-by Jason Wang <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-1@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueuecase 2 : umem = &mvq->umem2;break ; -case 3 : +default : umem = &mvq->umem3;break ; }Signature · 1 line
2.25.1
Michael S. Tsirkin
maintainerQuoted 5 lines · Jason Wang
When compiling with -Werror=maybe-uninitialized, gcc may complains the possible uninitialized umem. Since the callers won't pass value other than 1 to 3, making 3 as default to fix the compiler warning.
Signed-off-by Jason Wang <[email protected]>
Of course if it's actually something else this is not DTRT ... As long as we worry about this warning, let's have defence in depth:
case 3:
umem = &mvq->umem3;
break;
+ default:
+ umem = NULL;
+ BUG();
+ break;
Quoted 19 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-1@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueuecase 2 : umem = &mvq->umem2;break ; -case 3 : +default : umem = &mvq->umem3;break ; }Signature · 1 line
2.25.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
When compiling with -Werror=maybe-uninitialized, gcc may complains the possible uninitialized umem. Since the callers won't pass value other than 1 to 3, making 3 as default to fix the compiler warning.
Signed-off-by Jason Wang <[email protected]>Of course if it's actually something else this is not DTRT ...
It breaks some donw stream build (which mandates -Werror=maybe-uninitialized)
Quoted 8 lines
As long as we worry about this warning, let's have defence in depth:
case 3: umem = &mvq->umem3; break;+ default:
+ umem = NULL;
+BUG();
+ break;
Checkpatch doesn't like this:
WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON() #20: FILE: drivers/vdpa/mlx5/net/mlx5_vnet.c:695:
+ BUG();
But if you stick, I can go this way.
Thanks
Quoted 5 lines
Quoted 5 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 15 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-1@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueuecase 2 : umem = &mvq->umem2;break ; -case 3 : +default : umem = &mvq->umem3;break ; }Signature · 1 line
2.25.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization