virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] mlx5: vdpa: fix possible uninitialized var
@ 2021-01-14  7:09 Jason Wang
  2021-01-17 10:30 ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2021-01-14  7:09 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel; +Cc: elic

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 <jasowang@redhat.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index f1d54814db97..07ccc61cd6f6 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -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;
 	}
-- 
2.25.1

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

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

* Re: [PATCH V2] mlx5: vdpa: fix possible uninitialized var
  2021-01-14  7:09 [PATCH V2] mlx5: vdpa: fix possible uninitialized var Jason Wang
@ 2021-01-17 10:30 ` Michael S. Tsirkin
  2021-01-18  5:32   ` Jason Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2021-01-17 10:30 UTC (permalink / raw)
  To: Jason Wang; +Cc: elic, linux-kernel, virtualization

On Thu, Jan 14, 2021 at 03:09:04PM +0800, Jason Wang wrote:
> 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 <jasowang@redhat.com>

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;


> ---
>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index f1d54814db97..07ccc61cd6f6 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -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;
>  	}
> -- 
> 2.25.1

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

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

* Re: [PATCH V2] mlx5: vdpa: fix possible uninitialized var
  2021-01-17 10:30 ` Michael S. Tsirkin
@ 2021-01-18  5:32   ` Jason Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Wang @ 2021-01-18  5:32 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: elic, linux-kernel, virtualization


On 2021/1/17 下午6:30, Michael S. Tsirkin wrote:
> On Thu, Jan 14, 2021 at 03:09:04PM +0800, Jason Wang wrote:
>> 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 <jasowang@redhat.com>
> Of course if it's actually something else this is not DTRT ...


It breaks some donw stream build (which mandates 
-Werror=maybe-uninitialized)


> 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


>
>> ---
>>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index f1d54814db97..07ccc61cd6f6 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -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;
>>   	}
>> -- 
>> 2.25.1

_______________________________________________
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:[~2021-01-18  5:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14  7:09 [PATCH V2] mlx5: vdpa: fix possible uninitialized var Jason Wang
2021-01-17 10:30 ` Michael S. Tsirkin
2021-01-18  5:32   ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).