diff mbox series

[v2,2/2] tests/unit/test-smp-parse: Fix a check-patch complain

Message ID 20211111024429.10568-3-wangyanan55@huawei.com
State New
Headers show
Series tests/unit/test-smp-parse: Two fixes for test-smp-parse | expand

Commit Message

wangyanan (Y) Nov. 11, 2021, 2:44 a.m. UTC
Checkpatch.pl reports errors like below for commit 9e8e393bb7.
Let's fix it with a simpler format.
ERROR: space required after that close brace '}'
+    SMPTestData *data = &(SMPTestData){{ }};

Fixes: 9e8e393bb7 ("tests/unit: Add an unit test for smp parsing")
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
---
 tests/unit/test-smp-parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Jones Nov. 11, 2021, 8:43 a.m. UTC | #1
On Thu, Nov 11, 2021 at 10:44:29AM +0800, Yanan Wang wrote:
> Checkpatch.pl reports errors like below for commit 9e8e393bb7.
> Let's fix it with a simpler format.
> ERROR: space required after that close brace '}'
> +    SMPTestData *data = &(SMPTestData){{ }};
> 
> Fixes: 9e8e393bb7 ("tests/unit: Add an unit test for smp parsing")
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
> ---
>  tests/unit/test-smp-parse.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c
> index 872512aa37..7805a34b29 100644
> --- a/tests/unit/test-smp-parse.c
> +++ b/tests/unit/test-smp-parse.c
> @@ -514,7 +514,7 @@ static void test_generic(void)
>      Object *obj = smp_test_machine_init();
>      MachineState *ms = MACHINE(obj);
>      MachineClass *mc = MACHINE_GET_CLASS(obj);
> -    SMPTestData *data = &(SMPTestData){{ }};
> +    SMPTestData *data = &(SMPTestData){};
>      int i;
>  
>      for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
> @@ -548,7 +548,7 @@ static void test_with_dies(void)
>      Object *obj = smp_test_machine_init();
>      MachineState *ms = MACHINE(obj);
>      MachineClass *mc = MACHINE_GET_CLASS(obj);
> -    SMPTestData *data = &(SMPTestData){{ }};
> +    SMPTestData *data = &(SMPTestData){};
>      unsigned int num_dies = 2;
>      int i;
>  
> -- 
> 2.19.1
>

I just did some googling to refresh my memory on this, because I recall
{0} being recommended at some point. From what I can tell, {} is ok for
gcc, maybe also clang, but {0} is ANSI. The reasoning was that {} should
not be empty, and since element names are not required, '0' is enough to
assign the first element to zero. Also, as it's not required to list
each element, then that's enough for the whole struct. That said, {}
seems to be more popular, so we can probably assume the tools we support
also support it.

Reviewed-by: Andrew Jones <drjones@redhat.com>

Thanks,
drew
Thomas Huth Nov. 11, 2021, 8:53 a.m. UTC | #2
On 11/11/2021 09.43, Andrew Jones wrote:
> On Thu, Nov 11, 2021 at 10:44:29AM +0800, Yanan Wang wrote:
>> Checkpatch.pl reports errors like below for commit 9e8e393bb7.
>> Let's fix it with a simpler format.
>> ERROR: space required after that close brace '}'
>> +    SMPTestData *data = &(SMPTestData){{ }};
>>
>> Fixes: 9e8e393bb7 ("tests/unit: Add an unit test for smp parsing")
>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>> ---
>>   tests/unit/test-smp-parse.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c
>> index 872512aa37..7805a34b29 100644
>> --- a/tests/unit/test-smp-parse.c
>> +++ b/tests/unit/test-smp-parse.c
>> @@ -514,7 +514,7 @@ static void test_generic(void)
>>       Object *obj = smp_test_machine_init();
>>       MachineState *ms = MACHINE(obj);
>>       MachineClass *mc = MACHINE_GET_CLASS(obj);
>> -    SMPTestData *data = &(SMPTestData){{ }};
>> +    SMPTestData *data = &(SMPTestData){};
>>       int i;
>>   
>>       for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
>> @@ -548,7 +548,7 @@ static void test_with_dies(void)
>>       Object *obj = smp_test_machine_init();
>>       MachineState *ms = MACHINE(obj);
>>       MachineClass *mc = MACHINE_GET_CLASS(obj);
>> -    SMPTestData *data = &(SMPTestData){{ }};
>> +    SMPTestData *data = &(SMPTestData){};
>>       unsigned int num_dies = 2;
>>       int i;
>>   
>> -- 
>> 2.19.1
>>
> 
> I just did some googling to refresh my memory on this, because I recall
> {0} being recommended at some point. From what I can tell, {} is ok for
> gcc, maybe also clang, but {0} is ANSI. The reasoning was that {} should
> not be empty, and since element names are not required, '0' is enough to
> assign the first element to zero. Also, as it's not required to list
> each element, then that's enough for the whole struct. That said, {}
> seems to be more popular, so we can probably assume the tools we support
> also support it.

Some older compilers did not like {0} (see e.g. commit 555b3d67bc64), that's 
why we use {} in the QEMU code IIRC.

  Thomas
diff mbox series

Patch

diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c
index 872512aa37..7805a34b29 100644
--- a/tests/unit/test-smp-parse.c
+++ b/tests/unit/test-smp-parse.c
@@ -514,7 +514,7 @@  static void test_generic(void)
     Object *obj = smp_test_machine_init();
     MachineState *ms = MACHINE(obj);
     MachineClass *mc = MACHINE_GET_CLASS(obj);
-    SMPTestData *data = &(SMPTestData){{ }};
+    SMPTestData *data = &(SMPTestData){};
     int i;
 
     for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
@@ -548,7 +548,7 @@  static void test_with_dies(void)
     Object *obj = smp_test_machine_init();
     MachineState *ms = MACHINE(obj);
     MachineClass *mc = MACHINE_GET_CLASS(obj);
-    SMPTestData *data = &(SMPTestData){{ }};
+    SMPTestData *data = &(SMPTestData){};
     unsigned int num_dies = 2;
     int i;