Re: [PATCH] Remove VLAIS usage from gadget code - alternate patch
From: Andrzej Pietrasiewicz
Date: Wed Sep 25 2013 - 10:35:26 EST
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@xxxxxxxxx pisze:
From: Mark Charlebois <charlebm@xxxxxxxxx>
--- 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/