On Thu, Apr 24 2014, Andrzej Pietrasiewicz wrote: > 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@xxxxxxxxxxx> Acked-by: Michal Nazarewicz <mina86@xxxxxxxxxx> > --- > drivers/usb/gadget/f_fs.c | 27 +-------------------------- > drivers/usb/gadget/u_f.h | 26 ++++++++++++++++++++++++++ > 2 files changed, 27 insertions(+), 26 deletions(-) > > diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c > index 1e12b3e..be2983a 100644 > --- a/drivers/usb/gadget/f_fs.c > +++ b/drivers/usb/gadget/f_fs.c > @@ -33,36 +33,11 @@ > #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); > diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h > index 71034c0..1d5f0eb 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; > > -- > 1.8.3.2 > -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +--<mpn@xxxxxxxxxx>--<xmpp:mina86@xxxxxxxxxx>--ooO--(_)--Ooo--
Attachment:
signature.asc
Description: PGP signature