Patchwork [XTF,4/4] build: Avoid using initialisers for anonymous unions

login
register
mail settings
Submitter Andrew Cooper
Date Sept. 28, 2017, 10:59 a.m.
Message ID <1506596372-24393-4-git-send-email-andrew.cooper3@citrix.com>
Download mbox | patch
Permalink /patch/348623/
State New
Headers show

Comments

Andrew Cooper - Sept. 28, 2017, 10:59 a.m.
GCC 4.4 of CentOS 6 vintage can't cope.

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tests/livepatch-priv-check/main.c | 75 ++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 49 deletions(-)
Jan Beulich - Sept. 28, 2017, 12:37 p.m.
>>> On 28.09.17 at 12:59, <andrew.cooper3@citrix.com> wrote:
> --- a/tests/livepatch-priv-check/main.c
> +++ b/tests/livepatch-priv-check/main.c
> @@ -38,23 +38,17 @@ static void check_ret(const char *test, int rc)
>  static void test_upload(void)
>  {
>      static uint8_t payload[PAGE_SIZE];
> -    xen_sysctl_t op =
> -    {
> +    xen_sysctl_t op = {
>          .cmd = XEN_SYSCTL_livepatch_op,
>          .interface_version = sysctl_interface_version,
> -        .u.livepatch = {
> -            .cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD,
> -            .u.upload = {
> -                .name = {
> -                    .name.p = TEST_NAME,
> -                    .size = sizeof(TEST_NAME),
> -                },
> -                .size = PAGE_SIZE,
> -                .payload.p = payload,
> -            },
> -        },
>      };
>  
> +    op.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD;
> +    op.u.livepatch.u.upload.name.name.p = TEST_NAME;
> +    op.u.livepatch.u.upload.name.size = sizeof(TEST_NAME);
> +    op.u.livepatch.u.upload.size = PAGE_SIZE;
> +    op.u.livepatch.u.upload.payload.p = payload;

So where's the anonymous field here? Same for the other changes
further down.

Jan
Andrew Cooper - Sept. 28, 2017, 4:56 p.m.
On 28/09/17 13:37, Jan Beulich wrote:
>>>> On 28.09.17 at 12:59, <andrew.cooper3@citrix.com> wrote:
>> --- a/tests/livepatch-priv-check/main.c
>> +++ b/tests/livepatch-priv-check/main.c
>> @@ -38,23 +38,17 @@ static void check_ret(const char *test, int rc)
>>  static void test_upload(void)
>>  {
>>      static uint8_t payload[PAGE_SIZE];
>> -    xen_sysctl_t op =
>> -    {
>> +    xen_sysctl_t op = {
>>          .cmd = XEN_SYSCTL_livepatch_op,
>>          .interface_version = sysctl_interface_version,
>> -        .u.livepatch = {
>> -            .cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD,
>> -            .u.upload = {
>> -                .name = {
>> -                    .name.p = TEST_NAME,
>> -                    .size = sizeof(TEST_NAME),
>> -                },
>> -                .size = PAGE_SIZE,
>> -                .payload.p = payload,
>> -            },
>> -        },
>>      };
>>  
>> +    op.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD;
>> +    op.u.livepatch.u.upload.name.name.p = TEST_NAME;
>> +    op.u.livepatch.u.upload.name.size = sizeof(TEST_NAME);
>> +    op.u.livepatch.u.upload.size = PAGE_SIZE;
>> +    op.u.livepatch.u.upload.payload.p = payload;
> So where's the anonymous field here? Same for the other changes
> further down.

main.c: In function ‘test_upload’:
main.c:49: error: unknown field ‘p’ specified in initializer
cc1: warnings being treated as errors
main.c:49: error: missing braces around initializer
main.c:49: error: (near initialization for
‘op.u.livepatch.u.upload.name.name.<anonymous>’)
main.c:53: error: unknown field ‘p’ specified in initializer
main.c: In function ‘test_upload’:
main.c:49: error: unknown field ‘p’ specified in initializer
cc1: warnings being treated as errors

although this does give me an idea to simplify the patch...

~Andrew

Patch

diff --git a/tests/livepatch-priv-check/main.c b/tests/livepatch-priv-check/main.c
index e51ba64..9f9e778 100644
--- a/tests/livepatch-priv-check/main.c
+++ b/tests/livepatch-priv-check/main.c
@@ -38,23 +38,17 @@  static void check_ret(const char *test, int rc)
 static void test_upload(void)
 {
     static uint8_t payload[PAGE_SIZE];
-    xen_sysctl_t op =
-    {
+    xen_sysctl_t op = {
         .cmd = XEN_SYSCTL_livepatch_op,
         .interface_version = sysctl_interface_version,
-        .u.livepatch = {
-            .cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD,
-            .u.upload = {
-                .name = {
-                    .name.p = TEST_NAME,
-                    .size = sizeof(TEST_NAME),
-                },
-                .size = PAGE_SIZE,
-                .payload.p = payload,
-            },
-        },
     };
 
+    op.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD;
+    op.u.livepatch.u.upload.name.name.p = TEST_NAME;
+    op.u.livepatch.u.upload.name.size = sizeof(TEST_NAME);
+    op.u.livepatch.u.upload.size = PAGE_SIZE;
+    op.u.livepatch.u.upload.payload.p = payload;
+
     check_ret(__func__, hypercall_sysctl(&op));
 }
 
@@ -64,64 +58,47 @@  static void test_list(void)
 {
     char names[NR_PAYLOADS * XEN_LIVEPATCH_NAME_SIZE];
     uint32_t lengths[NR_PAYLOADS];
-
-    xen_sysctl_t op =
-    {
+    xen_sysctl_t op = {
         .cmd = XEN_SYSCTL_livepatch_op,
         .interface_version = sysctl_interface_version,
-        .u.livepatch = {
-            .cmd = XEN_SYSCTL_LIVEPATCH_LIST,
-            .u.list = {
-                .idx = 0,
-                .nr = NR_PAYLOADS,
-                .name.p = names,
-                .len.p = lengths,
-            },
-        },
     };
 
+    op.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_LIST;
+    op.u.livepatch.u.list.idx = 0;
+    op.u.livepatch.u.list.nr = NR_PAYLOADS;
+    op.u.livepatch.u.list.name.p = names;
+    op.u.livepatch.u.list.len.p = lengths;
+
     check_ret(__func__, hypercall_sysctl(&op));
 }
 
 static void test_get(void)
 {
-    xen_sysctl_t op =
-    {
+    xen_sysctl_t op = {
         .cmd = XEN_SYSCTL_livepatch_op,
         .interface_version = sysctl_interface_version,
-        .u.livepatch = {
-            .cmd = XEN_SYSCTL_LIVEPATCH_GET,
-            .u.get = {
-                .name = {
-                    .name.p = TEST_NAME,
-                    .size = sizeof(TEST_NAME),
-                },
-            },
-        },
     };
 
+    op.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_GET;
+    op.u.livepatch.u.get.name.name.p = TEST_NAME;
+    op.u.livepatch.u.get.name.size = sizeof(TEST_NAME);
+
     check_ret(__func__, hypercall_sysctl(&op));
 }
 
 static void test_action(uint32_t action)
 {
-    xen_sysctl_t op =
-    {
+    xen_sysctl_t op = {
         .cmd = XEN_SYSCTL_livepatch_op,
         .interface_version = sysctl_interface_version,
-        .u.livepatch = {
-            .cmd = XEN_SYSCTL_LIVEPATCH_ACTION,
-            .u.action = {
-                .name = {
-                    .name.p = TEST_NAME,
-                    .size = sizeof(TEST_NAME),
-                },
-                .cmd = action,
-                .timeout = 0,
-            },
-        },
     };
 
+    op.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_ACTION;
+    op.u.livepatch.u.action.name.name.p = TEST_NAME;
+    op.u.livepatch.u.action.name.size = sizeof(TEST_NAME);
+    op.u.livepatch.u.action.cmd = action;
+    op.u.livepatch.u.action.timeout = 0;
+
     check_ret(__func__, hypercall_sysctl(&op));
 }