Skip to contentSkip to conversation

mlx5: vdpa: fix possible uninitialized var

PATCH In review Jason Wang 3 participants 4 messages Jan 14, 2021 – Jan 18, 2021

Subsystems (2)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

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
index f1d54814db97..07ccc61cd6f6 100644
@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue
 	case 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
Acked-by on v2 1/1
#1 lore raw
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.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
index f1d54814db97..07ccc61cd6f6 100644
@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue
 	case 2:
 		umem = &mvq->umem2;
 		break;
-	case 3:
+	default:
 		umem = &mvq->umem3;
 		break;
 	}
Signature · 1 line
2.25.1
#2 lore raw
In reply to Jason Wang
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.

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
index f1d54814db97..07ccc61cd6f6 100644
@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue
 	case 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

author
#3 lore raw
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.

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
index f1d54814db97..07ccc61cd6f6 100644
@@ -703,7 +703,7 @@ static void umem_destroy(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue
  	case 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