Re: [PATCH v2] nitro_enclaves: Fix implicit type conversion

From: Stefano Garzarella
Date: Wed Nov 03 2021 - 05:13:32 EST


On Fri, Oct 29, 2021 at 01:48:46AM +0000, Jiasheng Jiang wrote:
The variable 'cpu' and 'cpu_sibling' are defined as unsigned int.
However in the for_each_cpu, their values are assigned to -1.
That doesn't make sense and in the cpumask_next() they are implicitly
type conversed to int.
It is universally accepted that the implicit type conversion is
terrible.
Also, having the good programming custom will set an example for
others.
Thus, it might be better to change the definition of 'cpu' and
'cpu_sibling' from unsigned int to int.

Signed-off-by: Jiasheng Jiang <jiasheng@xxxxxxxxxxx>
---
drivers/virt/nitro_enclaves/ne_misc_dev.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)


The for_each_cpu documentation explicitly says that unsigned is supported and -1 is commonly used to refer to the value before 0 even for unsigned.

However I have nothing against changing them to int.

Reviewed-by: Stefano Garzarella <sgarzare@xxxxxxxxxx>

Thanks,
Stefano