lkml.org 
[lkml]   [2020]   [Jan]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH net-next] net: sched: cls_u32: Use flexible-array member
On Thu, Jan 16, 2020 at 1:36 PM Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
>
> Old code in the kernel uses 1-byte and 0-byte arrays to indicate the
> presence of a "variable length array":
>
> struct something {
> int length;
> u8 data[1];
> };
>
> struct something *instance;
>
> instance = kmalloc(sizeof(*instance) + size, GFP_KERNEL);
> instance->length = size;
> memcpy(instance->data, source, size);

Hmm, your patch is not correct, for u32 it is length+1, so you have
to allocate size+1 after you switch to zero-length array.

Take a look at u32_walk() if you have any doubt.

Thanks.

\
 
 \ /
  Last update: 2020-01-17 05:45    [W:0.033 / U:0.368 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site