usb: gadget: FunctionFS: share VLA macros with all usb gadget files
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Thu, 8 May 2014 12:06:21 +0000 (14:06 +0200)
committerFelipe Balbi <balbi@ti.com>
Wed, 14 May 2014 14:37:27 +0000 (09:37 -0500)
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>
drivers/usb/gadget/f_fs.c
drivers/usb/gadget/u_f.h

index a01b3bd8fa0014e0ca63b0a35949dd9e79939463..38641ea820a803eaafa903034351c77dcb994f96 100644 (file)
 #include <linux/poll.h>
 
 #include "u_fs.h"
+#include "u_f.h"
 #include "configfs.h"
 
 #define FUNCTIONFS_MAGIC       0xa647361 /* Chosen by a honest dice roll ;) */
 
-/* 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))
-
 /* Reference counter handling */
 static void ffs_data_get(struct ffs_data *ffs);
 static void ffs_data_put(struct ffs_data *ffs);
index 71034c061fca864790ce5949433c7d88c8deb0c1..1d5f0eb685521c3a3ce6942571b78413161c54ef 100644 (file)
 #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;