lkml.org 
[lkml]   [2013]   [Sep]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Remove VLAIS usage from gadget code - alternate patch
Hi Mark,

Nice to hear from you again; on Saturday LOT's dreamliner was not
grounded and I have safely returned home ;)

Please see my comments inline.

W dniu 24.09.2013 19:56, charlebm@gmail.com pisze:
> From: Mark Charlebois <charlebm@gmail.com>
>
>
> --- linux.orig/drivers/usb/gadget/f_fs.c
> +++ linux/drivers/usb/gadget/f_fs.c
> @@ -30,6 +30,21 @@
>
> #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
>
> +/* Variable Length Array Macros **********************************************/
> +#define vla_struct(structname) size_t structname##__##next = 0
> +#define vla_struct_size(structname) structname##__##next
> +
> +#define vla_item(structname, type, name, n) \
> + type * structname##_##name; \
> + size_t structname##_##name##__##offset = \
> + (structname##__##next + __alignof__(type) - 1) & \
> + ~(__alignof__(type) - 1); \
> + size_t structname##_##name##__##sz = n * sizeof(type); \

most likely this shoud read:

+ size_t structname##_##name##__##sz = (n) * sizeof(type); \

otherwise vla_item(....., lang_count + 1); will expand to:

size_t d_stringtabs__sz = lang_count + \
1 * sizeof(struct usb_gadget_strings *);

> + structname##__##next = structname##_##name##__##offset + \
> + structname##_##name##__##sz;
> +
> +#define vla_ptr(ptr,structname,name) structname##_##name = \
> + (__typeof__(structname##_##name))&ptr[structname##_##name##__##offset]

<snip>

> unsigned i = 0;
> + vla_struct(d);
> + vla_item(d, struct usb_gadget_strings *, stringtabs,
> + lang_count + 1);

Can you somehow avoid mixing code and declarations? The last thing in
the expansion of this vla_item(.......) is an assignment, and

> + vla_item(d, struct usb_gadget_strings, stringtab, lang_count);

the first thing in expansion of the next vla_item(.......) is a
declaration. GCC most likely will complain (issue a warning).

One solution I can think of here (a bit hackish) is to use a braced
group as an expression: define vla_item() in such a way that first
it declares e.g. d_stringtabs__offset, then d_stringtabs__sz, and
then

struct usb_gadget_strings **d_stringtabs =
({d__next = d_stringtabs__offset + d_stringtabs__sz; NULL;});

I am not a fan of this kind of style, but can't think of any better way
now. And I don't know what Clang thinks of it :O

Thanks,

AP


\
 
 \ /
  Last update: 2013-09-25 17:01    [W:0.041 / U:0.324 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site