All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] kdd: remove zero-length arrays
@ 2020-06-08 20:38 Olaf Hering
  2020-06-09  8:55 ` Paul Durrant
  0 siblings, 1 reply; 18+ messages in thread
From: Olaf Hering @ 2020-06-08 20:38 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Olaf Hering, Tim Deegan, Wei Liu

Struct 'kdd_hdr' already has a member named 'payload[]' to easily
refer to the data after the header.  Remove the payload member from
'kdd_pkt' and always use 'kdd_hdr' to fix the following compile error:

kdd.c: In function 'kdd_tx':
kdd.c:746:30: error: array subscript 65534 is outside the bounds of an interior zero-length array 'uint8_t[0]' {aka 'unsigned char[]'} [-Werror=zero-length-bounds]
  746 |         sum += s->txp.payload[i];
      |                ~~~~~~~~~~~~~~^~~
In file included from kdd.c:53:
kdd.h:326:17: note: while referencing 'payload'
  326 |         uint8_t payload[0];
      |                 ^~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/debugger/kdd/kdd.c | 10 +++++-----
 tools/debugger/kdd/kdd.h |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/debugger/kdd/kdd.c b/tools/debugger/kdd/kdd.c
index 3ebda9b12c..4c6b39c22b 100644
--- a/tools/debugger/kdd/kdd.c
+++ b/tools/debugger/kdd/kdd.c
@@ -249,7 +249,7 @@ static void kdd_log_pkt(kdd_state *s, char *name, kdd_pkt *p)
 
     /* Re-check the checksum */
     for (i = 0; i < p->h.len; i++)
-        sum += p->payload[i];
+        sum += p->h.payload[i];
 
     fprintf(f, "\n"
             "%s: %s type 0x%4.4"PRIx16" len 0x%4.4"PRIx16
@@ -267,8 +267,8 @@ static void kdd_log_pkt(kdd_state *s, char *name, kdd_pkt *p)
             fprintf(f, "%8.8x ", i);
         } else if (i % 8 == 0)
             fprintf(f, " ");
-        fprintf(f, " %2.2x", p->payload[i]);
-        ascii[i % 16] = (isprint(((int)p->payload[i])) ? p->payload[i] : 0x2e);
+        fprintf(f, " %2.2x", p->h.payload[i]);
+        ascii[i % 16] = (isprint(((int)p->h.payload[i])) ? p->h.payload[i] : 0x2e);
         if (i % 16 == 15)
             fprintf(f, "  |%s|\n", ascii);
     }
@@ -743,7 +743,7 @@ static void kdd_tx(kdd_state *s)
 
     /* Fix up the checksum before we send */
     for (i = 0; i < s->txp.h.len; i++)
-        sum += s->txp.payload[i];
+        sum += s->txp.h.payload[i];
     s->txp.h.sum = sum;
 
     kdd_log_pkt(s, "TX", &s->txp);
@@ -1127,7 +1127,7 @@ static void kdd_handle_pkt(kdd_state *s, kdd_pkt *p)
 
     /* Simple checksum: add all the bytes */
     for (i = 0; i < p->h.len; i++)
-        sum += p->payload[i];
+        sum += p->h.payload[i];
     if (p->h.sum != sum) {
         kdd_send_ack(s, p->h.id, KDD_ACK_BAD);
         return;
diff --git a/tools/debugger/kdd/kdd.h b/tools/debugger/kdd/kdd.h
index bfb00ba5c5..57525d36c6 100644
--- a/tools/debugger/kdd/kdd.h
+++ b/tools/debugger/kdd/kdd.h
@@ -68,7 +68,7 @@ typedef struct {
     uint16_t len;     /* Payload length, excl. header and trailing byte */
     uint32_t id;      /* Echoed in responses */
     uint32_t sum;     /* Unsigned sum of all payload bytes */
-    uint8_t payload[0];
+    uint8_t payload[];
 } PACKED kdd_hdr;
 
 #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
@@ -323,7 +323,6 @@ typedef struct {
         kdd_msg msg;
         kdd_reg reg;
         kdd_stc stc;
-        uint8_t payload[0];
     };
 } PACKED kdd_pkt;
 


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

* RE: [PATCH v1] kdd: remove zero-length arrays
  2020-06-08 20:38 [PATCH v1] kdd: remove zero-length arrays Olaf Hering
@ 2020-06-09  8:55 ` Paul Durrant
  2020-06-09  9:00   ` Olaf Hering
  2020-06-09 12:15   ` Tim Deegan
  0 siblings, 2 replies; 18+ messages in thread
From: Paul Durrant @ 2020-06-09  8:55 UTC (permalink / raw)
  To: 'Olaf Hering', xen-devel
  Cc: 'Tim Deegan', 'Ian Jackson', 'Wei Liu'

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Olaf Hering
> Sent: 08 June 2020 21:39
> To: xen-devel@lists.xenproject.org
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>; Olaf Hering <olaf@aepfle.de>; Tim Deegan <tim@xen.org>;
> Wei Liu <wl@xen.org>
> Subject: [PATCH v1] kdd: remove zero-length arrays
> 
> Struct 'kdd_hdr' already has a member named 'payload[]' to easily
> refer to the data after the header.  Remove the payload member from
> 'kdd_pkt' and always use 'kdd_hdr' to fix the following compile error:

Is it not sufficient to just change the declaration of payload in kdd_pkt from [0] to []? In fact I can't see any use of the payload
field in kdd_hdr so it looks like that is the one that ought to be dropped.

  Paul

> 
> kdd.c: In function 'kdd_tx':
> kdd.c:746:30: error: array subscript 65534 is outside the bounds of an interior zero-length array
> 'uint8_t[0]' {aka 'unsigned char[]'} [-Werror=zero-length-bounds]
>   746 |         sum += s->txp.payload[i];
>       |                ~~~~~~~~~~~~~~^~~
> In file included from kdd.c:53:
> kdd.h:326:17: note: while referencing 'payload'
>   326 |         uint8_t payload[0];
>       |                 ^~~~~~~
> cc1: all warnings being treated as errors
> 
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
> ---
>  tools/debugger/kdd/kdd.c | 10 +++++-----
>  tools/debugger/kdd/kdd.h |  3 +--
>  2 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/debugger/kdd/kdd.c b/tools/debugger/kdd/kdd.c
> index 3ebda9b12c..4c6b39c22b 100644
> --- a/tools/debugger/kdd/kdd.c
> +++ b/tools/debugger/kdd/kdd.c
> @@ -249,7 +249,7 @@ static void kdd_log_pkt(kdd_state *s, char *name, kdd_pkt *p)
> 
>      /* Re-check the checksum */
>      for (i = 0; i < p->h.len; i++)
> -        sum += p->payload[i];
> +        sum += p->h.payload[i];
> 
>      fprintf(f, "\n"
>              "%s: %s type 0x%4.4"PRIx16" len 0x%4.4"PRIx16
> @@ -267,8 +267,8 @@ static void kdd_log_pkt(kdd_state *s, char *name, kdd_pkt *p)
>              fprintf(f, "%8.8x ", i);
>          } else if (i % 8 == 0)
>              fprintf(f, " ");
> -        fprintf(f, " %2.2x", p->payload[i]);
> -        ascii[i % 16] = (isprint(((int)p->payload[i])) ? p->payload[i] : 0x2e);
> +        fprintf(f, " %2.2x", p->h.payload[i]);
> +        ascii[i % 16] = (isprint(((int)p->h.payload[i])) ? p->h.payload[i] : 0x2e);
>          if (i % 16 == 15)
>              fprintf(f, "  |%s|\n", ascii);
>      }
> @@ -743,7 +743,7 @@ static void kdd_tx(kdd_state *s)
> 
>      /* Fix up the checksum before we send */
>      for (i = 0; i < s->txp.h.len; i++)
> -        sum += s->txp.payload[i];
> +        sum += s->txp.h.payload[i];
>      s->txp.h.sum = sum;
> 
>      kdd_log_pkt(s, "TX", &s->txp);
> @@ -1127,7 +1127,7 @@ static void kdd_handle_pkt(kdd_state *s, kdd_pkt *p)
> 
>      /* Simple checksum: add all the bytes */
>      for (i = 0; i < p->h.len; i++)
> -        sum += p->payload[i];
> +        sum += p->h.payload[i];
>      if (p->h.sum != sum) {
>          kdd_send_ack(s, p->h.id, KDD_ACK_BAD);
>          return;
> diff --git a/tools/debugger/kdd/kdd.h b/tools/debugger/kdd/kdd.h
> index bfb00ba5c5..57525d36c6 100644
> --- a/tools/debugger/kdd/kdd.h
> +++ b/tools/debugger/kdd/kdd.h
> @@ -68,7 +68,7 @@ typedef struct {
>      uint16_t len;     /* Payload length, excl. header and trailing byte */
>      uint32_t id;      /* Echoed in responses */
>      uint32_t sum;     /* Unsigned sum of all payload bytes */
> -    uint8_t payload[0];
> +    uint8_t payload[];
>  } PACKED kdd_hdr;
> 
>  #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
> @@ -323,7 +323,6 @@ typedef struct {
>          kdd_msg msg;
>          kdd_reg reg;
>          kdd_stc stc;
> -        uint8_t payload[0];
>      };
>  } PACKED kdd_pkt;
> 




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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09  8:55 ` Paul Durrant
@ 2020-06-09  9:00   ` Olaf Hering
  2020-06-09  9:04     ` Paul Durrant
  2020-06-09 12:15   ` Tim Deegan
  1 sibling, 1 reply; 18+ messages in thread
From: Olaf Hering @ 2020-06-09  9:00 UTC (permalink / raw)
  To: Paul Durrant
  Cc: xen-devel, 'Tim Deegan', 'Ian Jackson',
	'Wei Liu',
	paul

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]

Am Tue, 9 Jun 2020 09:55:52 +0100
schrieb Paul Durrant <xadimgnik@gmail.com>:

> Is it not sufficient to just change the declaration of payload in kdd_pkt from [0] to []?

AFAIR this lead to compile errors.

Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* RE: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09  9:00   ` Olaf Hering
@ 2020-06-09  9:04     ` Paul Durrant
  2020-06-09  9:06       ` Jürgen Groß
  2020-06-09  9:37       ` Olaf Hering
  0 siblings, 2 replies; 18+ messages in thread
From: Paul Durrant @ 2020-06-09  9:04 UTC (permalink / raw)
  To: 'Olaf Hering', 'Paul Durrant'
  Cc: xen-devel, 'Ian Jackson', 'Wei Liu',
	'Tim Deegan'

> -----Original Message-----
> From: Olaf Hering <olaf@aepfle.de>
> Sent: 09 June 2020 10:00
> To: Paul Durrant <xadimgnik@gmail.com>
> Cc: paul@xen.org; xen-devel@lists.xenproject.org; 'Ian Jackson' <ian.jackson@eu.citrix.com>; 'Tim
> Deegan' <tim@xen.org>; 'Wei Liu' <wl@xen.org>
> Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> 
> Am Tue, 9 Jun 2020 09:55:52 +0100
> schrieb Paul Durrant <xadimgnik@gmail.com>:
> 
> > Is it not sufficient to just change the declaration of payload in kdd_pkt from [0] to []?
> 
> AFAIR this lead to compile errors.
> 

OOI which compiler (might be worth mentioning in the commit comment too, for reference)? I'm not seeing a problem.

  Paul

> Olaf



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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09  9:04     ` Paul Durrant
@ 2020-06-09  9:06       ` Jürgen Groß
  2020-06-09  9:08         ` Paul Durrant
  2020-06-09  9:37       ` Olaf Hering
  1 sibling, 1 reply; 18+ messages in thread
From: Jürgen Groß @ 2020-06-09  9:06 UTC (permalink / raw)
  To: paul, 'Olaf Hering', 'Paul Durrant'
  Cc: xen-devel, 'Ian Jackson', 'Wei Liu',
	'Tim Deegan'

On 09.06.20 11:04, Paul Durrant wrote:
>> -----Original Message-----
>> From: Olaf Hering <olaf@aepfle.de>
>> Sent: 09 June 2020 10:00
>> To: Paul Durrant <xadimgnik@gmail.com>
>> Cc: paul@xen.org; xen-devel@lists.xenproject.org; 'Ian Jackson' <ian.jackson@eu.citrix.com>; 'Tim
>> Deegan' <tim@xen.org>; 'Wei Liu' <wl@xen.org>
>> Subject: Re: [PATCH v1] kdd: remove zero-length arrays
>>
>> Am Tue, 9 Jun 2020 09:55:52 +0100
>> schrieb Paul Durrant <xadimgnik@gmail.com>:
>>
>>> Is it not sufficient to just change the declaration of payload in kdd_pkt from [0] to []?
>>
>> AFAIR this lead to compile errors.
>>
> 
> OOI which compiler (might be worth mentioning in the commit comment too, for reference)? I'm not seeing a problem.

We don't use array[] in public headers, but AFAIK using them internally
is fine.


Juergen



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

* RE: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09  9:06       ` Jürgen Groß
@ 2020-06-09  9:08         ` Paul Durrant
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Durrant @ 2020-06-09  9:08 UTC (permalink / raw)
  To: 'Jürgen Groß', 'Olaf Hering',
	'Paul Durrant'
  Cc: xen-devel, 'Ian Jackson', 'Wei Liu',
	'Tim Deegan'

> -----Original Message-----
> From: Jürgen Groß <jgross@suse.com>
> Sent: 09 June 2020 10:06
> To: paul@xen.org; 'Olaf Hering' <olaf@aepfle.de>; 'Paul Durrant' <xadimgnik@gmail.com>
> Cc: xen-devel@lists.xenproject.org; 'Ian Jackson' <ian.jackson@eu.citrix.com>; 'Wei Liu' <wl@xen.org>;
> 'Tim Deegan' <tim@xen.org>
> Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> 
> On 09.06.20 11:04, Paul Durrant wrote:
> >> -----Original Message-----
> >> From: Olaf Hering <olaf@aepfle.de>
> >> Sent: 09 June 2020 10:00
> >> To: Paul Durrant <xadimgnik@gmail.com>
> >> Cc: paul@xen.org; xen-devel@lists.xenproject.org; 'Ian Jackson' <ian.jackson@eu.citrix.com>; 'Tim
> >> Deegan' <tim@xen.org>; 'Wei Liu' <wl@xen.org>
> >> Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> >>
> >> Am Tue, 9 Jun 2020 09:55:52 +0100
> >> schrieb Paul Durrant <xadimgnik@gmail.com>:
> >>
> >>> Is it not sufficient to just change the declaration of payload in kdd_pkt from [0] to []?
> >>
> >> AFAIR this lead to compile errors.
> >>
> >
> > OOI which compiler (might be worth mentioning in the commit comment too, for reference)? I'm not
> seeing a problem.
> 
> We don't use array[] in public headers, but AFAIK using them internally
> is fine.
> 

Yeah, we have XEN_FLEX_ARRAY_DIM for public headers.

  Paul

> 
> Juergen




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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09  9:04     ` Paul Durrant
  2020-06-09  9:06       ` Jürgen Groß
@ 2020-06-09  9:37       ` Olaf Hering
  1 sibling, 0 replies; 18+ messages in thread
From: Olaf Hering @ 2020-06-09  9:37 UTC (permalink / raw)
  To: Paul Durrant
  Cc: xen-devel, 'Tim Deegan', 'Ian Jackson',
	'Wei Liu',
	paul

[-- Attachment #1: Type: text/plain, Size: 347 bytes --]

Am Tue, 9 Jun 2020 10:04:30 +0100
schrieb Paul Durrant <xadimgnik@gmail.com>:

> OOI which compiler (might be worth mentioning in the commit comment too, for reference)? I'm not seeing a problem.

This is from gcc10. I think the build automation for Tumbleweed will show this error, unless the Tumbleweed image is older than a week.

Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09  8:55 ` Paul Durrant
  2020-06-09  9:00   ` Olaf Hering
@ 2020-06-09 12:15   ` Tim Deegan
  2020-06-09 13:22     ` Olaf Hering
  1 sibling, 1 reply; 18+ messages in thread
From: Tim Deegan @ 2020-06-09 12:15 UTC (permalink / raw)
  To: paul
  Cc: xen-devel, 'Olaf Hering', 'Ian Jackson',
	'Wei Liu'

Hi,

At 09:55 +0100 on 09 Jun (1591696552), Paul Durrant wrote:
> > -----Original Message-----
> > From: Xen-devel <xen-devel-bounces@lists.xenproject.org> On Behalf Of Olaf Hering
> > Sent: 08 June 2020 21:39
> > To: xen-devel@lists.xenproject.org
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>; Olaf Hering <olaf@aepfle.de>; Tim Deegan <tim@xen.org>;
> > Wei Liu <wl@xen.org>
> > Subject: [PATCH v1] kdd: remove zero-length arrays
> > 
> > Struct 'kdd_hdr' already has a member named 'payload[]' to easily
> > refer to the data after the header.  Remove the payload member from
> > 'kdd_pkt' and always use 'kdd_hdr' to fix the following compile error:
> 
> Is it not sufficient to just change the declaration of payload in kdd_pkt from [0] to []? In fact I can't see any use of the payload
> field in kdd_hdr so it looks like that is the one that ought to be dropped.

Yes, if one of these has to go, it should be the one in the header,
since it's not used and the one in the packet is neatly in the union
with the other decriptions of the packet payload.

I'm not currently in a position to test patches, but might be later in
the week.  Olaf, can you try dropping the 'payload' field from the
header and replacing the payload[0] in pkt with payload[] ?

Cheers,

Tim.


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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09 12:15   ` Tim Deegan
@ 2020-06-09 13:22     ` Olaf Hering
  2020-06-09 13:26       ` Ian Jackson
  2020-06-10 19:16       ` Tim Deegan
  0 siblings, 2 replies; 18+ messages in thread
From: Olaf Hering @ 2020-06-09 13:22 UTC (permalink / raw)
  To: Tim Deegan; +Cc: xen-devel, 'Ian Jackson', 'Wei Liu', paul

[-- Attachment #1: Type: text/plain, Size: 951 bytes --]

Am Tue, 9 Jun 2020 13:15:49 +0100
schrieb Tim Deegan <tim@xen.org>:

> Olaf, can you try dropping the 'payload' field from the header and replacing the payload[0] in pkt with payload[] ?

In file included from kdd.c:53:
kdd.h:325:17: error: flexible array member in union
  325 |         uint8_t payload[];

--- orig/kdd.h  2020-06-08 17:40:05.000000000 +0000
+++ kdd.h       2020-06-09 13:20:36.724887538 +0000
@@ -68,7 +68,6 @@
     uint16_t len;     /* Payload length, excl. header and trailing byte */
     uint32_t id;      /* Echoed in responses */
     uint32_t sum;     /* Unsigned sum of all payload bytes */
-    uint8_t payload[0];
 } PACKED kdd_hdr;
 
 #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
@@ -323,7 +322,7 @@
         kdd_msg msg;
         kdd_reg reg;
         kdd_stc stc;
-        uint8_t payload[0];
+        uint8_t payload[];
     };
 } PACKED kdd_pkt;
 

Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09 13:22     ` Olaf Hering
@ 2020-06-09 13:26       ` Ian Jackson
  2020-06-09 13:32         ` Olaf Hering
  2020-06-10 19:16       ` Tim Deegan
  1 sibling, 1 reply; 18+ messages in thread
From: Ian Jackson @ 2020-06-09 13:26 UTC (permalink / raw)
  To: Olaf Hering
  Cc: xen-devel, Tim Deegan, 'Ian Jackson', 'Wei Liu', paul

Olaf Hering writes ("Re: [PATCH v1] kdd: remove zero-length arrays"):
> Am Tue, 9 Jun 2020 13:15:49 +0100
> schrieb Tim Deegan <tim@xen.org>:
> 
> > Olaf, can you try dropping the 'payload' field from the header and replacing the payload[0] in pkt with payload[] ?
> 
> In file included from kdd.c:53:
> kdd.h:325:17: error: flexible array member in union
>   325 |         uint8_t payload[];
...
>          kdd_stc stc;
> -        uint8_t payload[0];
> +        uint8_t payload[];
>      };
>  } PACKED kdd_pkt;

Try

>          kdd_stc stc;
> -        uint8_t payload[0];
>      };
  +    uint8_t payload[];
>  } PACKED kdd_pkt;

?

(I haven't read the surrounding code...)

Ian.


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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09 13:26       ` Ian Jackson
@ 2020-06-09 13:32         ` Olaf Hering
  0 siblings, 0 replies; 18+ messages in thread
From: Olaf Hering @ 2020-06-09 13:32 UTC (permalink / raw)
  To: Ian Jackson
  Cc: xen-devel, Tim Deegan, 'Ian Jackson', 'Wei Liu', paul

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

Am Tue, 9 Jun 2020 14:26:46 +0100
schrieb Ian Jackson <ian.jackson@citrix.com>:

>   +    uint8_t payload[];

This compiles, but will access memory behind the union{};, which is most likely not what the intention is.

Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-09 13:22     ` Olaf Hering
  2020-06-09 13:26       ` Ian Jackson
@ 2020-06-10 19:16       ` Tim Deegan
  2020-06-11 19:10         ` Olaf Hering
  1 sibling, 1 reply; 18+ messages in thread
From: Tim Deegan @ 2020-06-10 19:16 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel, 'Ian Jackson', 'Wei Liu', paul

At 15:22 +0200 on 09 Jun (1591716153), Olaf Hering wrote:
> Am Tue, 9 Jun 2020 13:15:49 +0100
> schrieb Tim Deegan <tim@xen.org>:
> 
> > Olaf, can you try dropping the 'payload' field from the header and replacing the payload[0] in pkt with payload[] ?
> 
> In file included from kdd.c:53:
> kdd.h:325:17: error: flexible array member in union
>   325 |         uint8_t payload[];

How tedious.  Well, the only place we actually allocate one of these
we already leave enough space for a max-size packet, so how about
this?

kdd: stop using [0] arrays to access packet contents.

GCC 10 is unhappy about this, and we already use 64k buffers
in the only places where packets are allocated, so move the
64k size into the packet definition.

Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Tim Deegan <tim@xen.org>
---
 tools/debugger/kdd/kdd.c | 4 ++--
 tools/debugger/kdd/kdd.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git tools/debugger/kdd/kdd.c tools/debugger/kdd/kdd.c
index 3ebda9b12c..a7d0976ea4 100644
--- tools/debugger/kdd/kdd.c
+++ tools/debugger/kdd/kdd.c
@@ -79,11 +79,11 @@ typedef struct {
 /* State of the debugger stub */
 typedef struct {
     union {
-        uint8_t txb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for tx */
+        uint8_t txb[sizeof (kdd_pkt)];           /* Marshalling area for tx */
         kdd_pkt txp;                 /* Also readable as a packet structure */
     };
     union {
-        uint8_t rxb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for rx */
+        uint8_t rxb[sizeof (kdd_pkt)];           /* Marshalling area for rx */
         kdd_pkt rxp;                 /* Also readable as a packet structure */
     };
     unsigned int cur;       /* Offset into rx where we'll put the next byte */
diff --git tools/debugger/kdd/kdd.h tools/debugger/kdd/kdd.h
index bfb00ba5c5..b9a17440df 100644
--- tools/debugger/kdd/kdd.h
+++ tools/debugger/kdd/kdd.h
@@ -68,7 +68,6 @@ typedef struct {
     uint16_t len;     /* Payload length, excl. header and trailing byte */
     uint32_t id;      /* Echoed in responses */
     uint32_t sum;     /* Unsigned sum of all payload bytes */
-    uint8_t payload[0];
 } PACKED kdd_hdr;
 
 #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
@@ -323,7 +322,7 @@ typedef struct {
         kdd_msg msg;
         kdd_reg reg;
         kdd_stc stc;
-        uint8_t payload[0];
+        uint8_t payload[65536];
     };
 } PACKED kdd_pkt;
 
-- 
2.26.2



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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-10 19:16       ` Tim Deegan
@ 2020-06-11 19:10         ` Olaf Hering
  2020-06-16 20:50           ` Christopher Clark
  0 siblings, 1 reply; 18+ messages in thread
From: Olaf Hering @ 2020-06-11 19:10 UTC (permalink / raw)
  To: Tim Deegan; +Cc: xen-devel, 'Ian Jackson', 'Wei Liu', paul

[-- Attachment #1: Type: text/plain, Size: 1558 bytes --]

Am Wed, 10 Jun 2020 20:16:57 +0100
schrieb Tim Deegan <tim@xen.org>:

> How tedious.

Indeed. This compiles for me as well:

--- orig/kdd.h  2020-06-08 17:40:05.000000000 +0000
+++ kdd.h       2020-06-11 19:00:44.234364040 +0000
@@ -68,7 +68,6 @@
     uint16_t len;     /* Payload length, excl. header and trailing byte */
     uint32_t id;      /* Echoed in responses */
     uint32_t sum;     /* Unsigned sum of all payload bytes */
-    uint8_t payload[0];
 } PACKED kdd_hdr;
 
 #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
@@ -323,7 +322,7 @@
         kdd_msg msg;
         kdd_reg reg;
         kdd_stc stc;
-        uint8_t payload[0];
+        uint8_t payload[65536];
     };
 } PACKED kdd_pkt;
 
--- orig/kdd.c  2020-06-08 17:40:05.000000000 +0000
+++ kdd.c       2020-06-11 19:08:36.775724640 +0000
@@ -79,11 +79,11 @@
 /* State of the debugger stub */
 typedef struct {
     union {
-        uint8_t txb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for tx */
+        uint8_t txb[sizeof (kdd_hdr) + 0xffff];   /* Marshalling area for tx */
         kdd_pkt txp;                 /* Also readable as a packet structure */
     };
     union {
-        uint8_t rxb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for rx */
+        uint8_t rxb[sizeof (kdd_hdr)];   /* Marshalling area for rx */
         kdd_pkt rxp;                 /* Also readable as a packet structure */
     };
     unsigned int cur;       /* Offset into rx where we'll put the next byte */

Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-11 19:10         ` Olaf Hering
@ 2020-06-16 20:50           ` Christopher Clark
  2020-06-17  8:21             ` Paul Durrant
  0 siblings, 1 reply; 18+ messages in thread
From: Christopher Clark @ 2020-06-16 20:50 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel, Tim Deegan, Ian Jackson, Wei Liu, paul

On Thu, Jun 11, 2020 at 12:12 PM Olaf Hering <olaf@aepfle.de> wrote:
>
> Am Wed, 10 Jun 2020 20:16:57 +0100
> schrieb Tim Deegan <tim@xen.org>:
>
> > How tedious.
>
> Indeed. This compiles for me as well:

just a nudge on this; it would be nice to get a patch into the tree
since the build failure affects master builds of Xen in OpenEmbedded
now.

Christopher

>
> --- orig/kdd.h  2020-06-08 17:40:05.000000000 +0000
> +++ kdd.h       2020-06-11 19:00:44.234364040 +0000
> @@ -68,7 +68,6 @@
>      uint16_t len;     /* Payload length, excl. header and trailing byte */
>      uint32_t id;      /* Echoed in responses */
>      uint32_t sum;     /* Unsigned sum of all payload bytes */
> -    uint8_t payload[0];
>  } PACKED kdd_hdr;
>
>  #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
> @@ -323,7 +322,7 @@
>          kdd_msg msg;
>          kdd_reg reg;
>          kdd_stc stc;
> -        uint8_t payload[0];
> +        uint8_t payload[65536];
>      };
>  } PACKED kdd_pkt;
>
> --- orig/kdd.c  2020-06-08 17:40:05.000000000 +0000
> +++ kdd.c       2020-06-11 19:08:36.775724640 +0000
> @@ -79,11 +79,11 @@
>  /* State of the debugger stub */
>  typedef struct {
>      union {
> -        uint8_t txb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for tx */
> +        uint8_t txb[sizeof (kdd_hdr) + 0xffff];   /* Marshalling area for tx */
>          kdd_pkt txp;                 /* Also readable as a packet structure */
>      };
>      union {
> -        uint8_t rxb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for rx */
> +        uint8_t rxb[sizeof (kdd_hdr)];   /* Marshalling area for rx */
>          kdd_pkt rxp;                 /* Also readable as a packet structure */
>      };
>      unsigned int cur;       /* Offset into rx where we'll put the next byte */
>
> Olaf


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

* RE: [PATCH v1] kdd: remove zero-length arrays
  2020-06-16 20:50           ` Christopher Clark
@ 2020-06-17  8:21             ` Paul Durrant
  2020-06-26 10:26               ` Wei Liu
  0 siblings, 1 reply; 18+ messages in thread
From: Paul Durrant @ 2020-06-17  8:21 UTC (permalink / raw)
  To: 'Christopher Clark', 'Olaf Hering'
  Cc: 'xen-devel', 'Tim Deegan', 'Ian Jackson',
	'Wei Liu'

> -----Original Message-----
> From: Christopher Clark <christopher.w.clark@gmail.com>
> Sent: 16 June 2020 21:50
> To: Olaf Hering <olaf@aepfle.de>
> Cc: Tim Deegan <tim@xen.org>; xen-devel <xen-devel@lists.xenproject.org>; Ian Jackson
> <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; paul@xen.org
> Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> 
> On Thu, Jun 11, 2020 at 12:12 PM Olaf Hering <olaf@aepfle.de> wrote:
> >
> > Am Wed, 10 Jun 2020 20:16:57 +0100
> > schrieb Tim Deegan <tim@xen.org>:
> >
> > > How tedious.
> >
> > Indeed. This compiles for me as well:
> 
> just a nudge on this; it would be nice to get a patch into the tree
> since the build failure affects master builds of Xen in OpenEmbedded
> now.
> 

I'd be happy to take a patch into 4.14 if someone can provide one with a suitable maintainer ack.

  Paul

> Christopher
> 
> >
> > --- orig/kdd.h  2020-06-08 17:40:05.000000000 +0000
> > +++ kdd.h       2020-06-11 19:00:44.234364040 +0000
> > @@ -68,7 +68,6 @@
> >      uint16_t len;     /* Payload length, excl. header and trailing byte */
> >      uint32_t id;      /* Echoed in responses */
> >      uint32_t sum;     /* Unsigned sum of all payload bytes */
> > -    uint8_t payload[0];
> >  } PACKED kdd_hdr;
> >
> >  #define KDD_PKT_CMD 0x0002      /* Debugger commands (and replies to them) */
> > @@ -323,7 +322,7 @@
> >          kdd_msg msg;
> >          kdd_reg reg;
> >          kdd_stc stc;
> > -        uint8_t payload[0];
> > +        uint8_t payload[65536];
> >      };
> >  } PACKED kdd_pkt;
> >
> > --- orig/kdd.c  2020-06-08 17:40:05.000000000 +0000
> > +++ kdd.c       2020-06-11 19:08:36.775724640 +0000
> > @@ -79,11 +79,11 @@
> >  /* State of the debugger stub */
> >  typedef struct {
> >      union {
> > -        uint8_t txb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for tx */
> > +        uint8_t txb[sizeof (kdd_hdr) + 0xffff];   /* Marshalling area for tx */
> >          kdd_pkt txp;                 /* Also readable as a packet structure */
> >      };
> >      union {
> > -        uint8_t rxb[sizeof (kdd_hdr) + 65536];   /* Marshalling area for rx */
> > +        uint8_t rxb[sizeof (kdd_hdr)];   /* Marshalling area for rx */
> >          kdd_pkt rxp;                 /* Also readable as a packet structure */
> >      };
> >      unsigned int cur;       /* Offset into rx where we'll put the next byte */
> >
> > Olaf



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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-17  8:21             ` Paul Durrant
@ 2020-06-26 10:26               ` Wei Liu
  2020-06-26 10:31                 ` Paul Durrant
  0 siblings, 1 reply; 18+ messages in thread
From: Wei Liu @ 2020-06-26 10:26 UTC (permalink / raw)
  To: paul
  Cc: 'Olaf Hering', 'Wei Liu', 'Tim Deegan',
	'Ian Jackson', 'Christopher Clark',
	'xen-devel'

On Wed, Jun 17, 2020 at 09:21:22AM +0100, Paul Durrant wrote:
> > -----Original Message-----
> > From: Christopher Clark <christopher.w.clark@gmail.com>
> > Sent: 16 June 2020 21:50
> > To: Olaf Hering <olaf@aepfle.de>
> > Cc: Tim Deegan <tim@xen.org>; xen-devel <xen-devel@lists.xenproject.org>; Ian Jackson
> > <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; paul@xen.org
> > Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> > 
> > On Thu, Jun 11, 2020 at 12:12 PM Olaf Hering <olaf@aepfle.de> wrote:
> > >
> > > Am Wed, 10 Jun 2020 20:16:57 +0100
> > > schrieb Tim Deegan <tim@xen.org>:
> > >
> > > > How tedious.
> > >
> > > Indeed. This compiles for me as well:
> > 
> > just a nudge on this; it would be nice to get a patch into the tree
> > since the build failure affects master builds of Xen in OpenEmbedded
> > now.
> > 
> 
> I'd be happy to take a patch into 4.14 if someone can provide one with a suitable maintainer ack.

Tim is the maintainer of KDD. :-)

I take it you're happy with me committing his patch then?

Wei.


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

* RE: [PATCH v1] kdd: remove zero-length arrays
  2020-06-26 10:26               ` Wei Liu
@ 2020-06-26 10:31                 ` Paul Durrant
  2020-06-26 10:33                   ` Wei Liu
  0 siblings, 1 reply; 18+ messages in thread
From: Paul Durrant @ 2020-06-26 10:31 UTC (permalink / raw)
  To: 'Wei Liu'
  Cc: 'Ian Jackson', 'xen-devel', 'Olaf Hering',
	'Tim Deegan', 'Christopher Clark'

> -----Original Message-----
> From: Wei Liu <wl@xen.org>
> Sent: 26 June 2020 11:27
> To: paul@xen.org
> Cc: 'Christopher Clark' <christopher.w.clark@gmail.com>; 'Olaf Hering' <olaf@aepfle.de>; 'Tim Deegan'
> <tim@xen.org>; 'xen-devel' <xen-devel@lists.xenproject.org>; 'Ian Jackson'
> <ian.jackson@eu.citrix.com>; 'Wei Liu' <wl@xen.org>
> Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> 
> On Wed, Jun 17, 2020 at 09:21:22AM +0100, Paul Durrant wrote:
> > > -----Original Message-----
> > > From: Christopher Clark <christopher.w.clark@gmail.com>
> > > Sent: 16 June 2020 21:50
> > > To: Olaf Hering <olaf@aepfle.de>
> > > Cc: Tim Deegan <tim@xen.org>; xen-devel <xen-devel@lists.xenproject.org>; Ian Jackson
> > > <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; paul@xen.org
> > > Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> > >
> > > On Thu, Jun 11, 2020 at 12:12 PM Olaf Hering <olaf@aepfle.de> wrote:
> > > >
> > > > Am Wed, 10 Jun 2020 20:16:57 +0100
> > > > schrieb Tim Deegan <tim@xen.org>:
> > > >
> > > > > How tedious.
> > > >
> > > > Indeed. This compiles for me as well:
> > >
> > > just a nudge on this; it would be nice to get a patch into the tree
> > > since the build failure affects master builds of Xen in OpenEmbedded
> > > now.
> > >
> >
> > I'd be happy to take a patch into 4.14 if someone can provide one with a suitable maintainer ack.
> 
> Tim is the maintainer of KDD. :-)
> 
> I take it you're happy with me committing his patch then?
> 

I'm happy, but ought it not have an ack from 'the rest' since Tim submitted the patch?

Release-acked-by: Paul Durrant <paul@xen.org>

> Wei.



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

* Re: [PATCH v1] kdd: remove zero-length arrays
  2020-06-26 10:31                 ` Paul Durrant
@ 2020-06-26 10:33                   ` Wei Liu
  0 siblings, 0 replies; 18+ messages in thread
From: Wei Liu @ 2020-06-26 10:33 UTC (permalink / raw)
  To: paul
  Cc: 'Olaf Hering', 'Wei Liu', 'Tim Deegan',
	'Ian Jackson', 'Christopher Clark',
	'xen-devel'

On Fri, Jun 26, 2020 at 11:31:48AM +0100, Paul Durrant wrote:
> > -----Original Message-----
> > From: Wei Liu <wl@xen.org>
> > Sent: 26 June 2020 11:27
> > To: paul@xen.org
> > Cc: 'Christopher Clark' <christopher.w.clark@gmail.com>; 'Olaf Hering' <olaf@aepfle.de>; 'Tim Deegan'
> > <tim@xen.org>; 'xen-devel' <xen-devel@lists.xenproject.org>; 'Ian Jackson'
> > <ian.jackson@eu.citrix.com>; 'Wei Liu' <wl@xen.org>
> > Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> > 
> > On Wed, Jun 17, 2020 at 09:21:22AM +0100, Paul Durrant wrote:
> > > > -----Original Message-----
> > > > From: Christopher Clark <christopher.w.clark@gmail.com>
> > > > Sent: 16 June 2020 21:50
> > > > To: Olaf Hering <olaf@aepfle.de>
> > > > Cc: Tim Deegan <tim@xen.org>; xen-devel <xen-devel@lists.xenproject.org>; Ian Jackson
> > > > <ian.jackson@eu.citrix.com>; Wei Liu <wl@xen.org>; paul@xen.org
> > > > Subject: Re: [PATCH v1] kdd: remove zero-length arrays
> > > >
> > > > On Thu, Jun 11, 2020 at 12:12 PM Olaf Hering <olaf@aepfle.de> wrote:
> > > > >
> > > > > Am Wed, 10 Jun 2020 20:16:57 +0100
> > > > > schrieb Tim Deegan <tim@xen.org>:
> > > > >
> > > > > > How tedious.
> > > > >
> > > > > Indeed. This compiles for me as well:
> > > >
> > > > just a nudge on this; it would be nice to get a patch into the tree
> > > > since the build failure affects master builds of Xen in OpenEmbedded
> > > > now.
> > > >
> > >
> > > I'd be happy to take a patch into 4.14 if someone can provide one with a suitable maintainer ack.
> > 
> > Tim is the maintainer of KDD. :-)
> > 
> > I take it you're happy with me committing his patch then?
> > 
> 
> I'm happy, but ought it not have an ack from 'the rest' since Tim submitted the patch?

Alright. FWIW:

Acked-by: Wei Liu <wl@xen.org>

> 
> Release-acked-by: Paul Durrant <paul@xen.org>

Thanks.

Wei.

> 
> > Wei.
> 


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

end of thread, other threads:[~2020-06-26 10:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08 20:38 [PATCH v1] kdd: remove zero-length arrays Olaf Hering
2020-06-09  8:55 ` Paul Durrant
2020-06-09  9:00   ` Olaf Hering
2020-06-09  9:04     ` Paul Durrant
2020-06-09  9:06       ` Jürgen Groß
2020-06-09  9:08         ` Paul Durrant
2020-06-09  9:37       ` Olaf Hering
2020-06-09 12:15   ` Tim Deegan
2020-06-09 13:22     ` Olaf Hering
2020-06-09 13:26       ` Ian Jackson
2020-06-09 13:32         ` Olaf Hering
2020-06-10 19:16       ` Tim Deegan
2020-06-11 19:10         ` Olaf Hering
2020-06-16 20:50           ` Christopher Clark
2020-06-17  8:21             ` Paul Durrant
2020-06-26 10:26               ` Wei Liu
2020-06-26 10:31                 ` Paul Durrant
2020-06-26 10:33                   ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.