diff options
author | Andrzej Pietrasiewicz <andrzej.p@samsung.com> | 2014-05-08 16:06:21 +0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-05-14 18:37:27 +0400 |
commit | 74d484669784836c83f23f80ee21a44e9fbf4d59 (patch) | |
tree | 64e4c7d73805d82294c92fcfae9b0a6b0dabec91 /drivers/usb/gadget/u_f.h | |
parent | 10f0577aa5cb03c81cf6ddc2ff7de1b6d6152d0b (diff) | |
download | linux-74d484669784836c83f23f80ee21a44e9fbf4d59.tar.xz |
usb: gadget: FunctionFS: share VLA macros with all usb gadget files
Variable Length Array macros allow portable (compilable with both gcc
and clang) way of allocating a number of structures using a single
memory chunk. They can be useful for files other than f_fs.c,
so move them to a header file.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/u_f.h')
-rw-r--r-- | drivers/usb/gadget/u_f.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h index 71034c061fca..1d5f0eb68552 100644 --- a/drivers/usb/gadget/u_f.h +++ b/drivers/usb/gadget/u_f.h @@ -16,6 +16,32 @@ #ifndef __U_F_H__ #define __U_F_H__ +/* Variable Length Array Macros **********************************************/ +#define vla_group(groupname) size_t groupname##__next = 0 +#define vla_group_size(groupname) groupname##__next + +#define vla_item(groupname, type, name, n) \ + size_t groupname##_##name##__offset = ({ \ + size_t align_mask = __alignof__(type) - 1; \ + size_t offset = (groupname##__next + align_mask) & ~align_mask;\ + size_t size = (n) * sizeof(type); \ + groupname##__next = offset + size; \ + offset; \ + }) + +#define vla_item_with_sz(groupname, type, name, n) \ + size_t groupname##_##name##__sz = (n) * sizeof(type); \ + size_t groupname##_##name##__offset = ({ \ + size_t align_mask = __alignof__(type) - 1; \ + size_t offset = (groupname##__next + align_mask) & ~align_mask;\ + size_t size = groupname##_##name##__sz; \ + groupname##__next = offset + size; \ + offset; \ + }) + +#define vla_ptr(ptr, groupname, name) \ + ((void *) ((char *)ptr + groupname##_##name##__offset)) + struct usb_ep; struct usb_request; |