W dniu 07.11.2013 19:28, Mark Charlebois pisze:
On Sat, Nov 2, 2013 at 10:44 AM, Michal Nazarewicz <min...@mina86.com <mailto:min...@mina86.com>> wrote: On Wed, Oct 23 2013, Andrzej Pietrasiewicz wrote: > From: Mark Charlebois <charl...@gmail.com <mailto:charl...@gmail.com>> > > The use of variable length arrays in structs (VLAIS) in the Linux Kernel code > precludes the use of compilers which don't implement VLAIS (for instance the > Clang compiler). This alternate patch calculates offsets into the kmalloc-ed > memory buffer using macros. The previous patch required multiple kmalloc and > kfree calls. This version uses "group" vs "struct" since it really is not a > struct and is essentially a group of VLA in a common allocated block. This > version also fixes the issues pointed out by Andrzej Pietrasiewicz. > > Signed-off-by: Mark Charlebois <charl...@gmail.com <mailto:charl...@gmail.com>> > Signed-off-by: Behan Webster <beh...@converseincode.com <mailto:beh...@converseincode.com>> > > [elimination of miexed declaration and code, checkpatch cleanup] > Signed-off-by: Andrzej Pietrasiewicz <andrze...@samsung.com <mailto:andrze...@samsung.com>> > Signed-off-by: Kyungmin Park <kyungmin.p...@samsung.com <mailto:kyungmin.p...@samsung.com>> > --- > drivers/usb/gadget/f_fs.c | 110 +++++++++++++++++++++++++++++---------------- > 1 files changed, 71 insertions(+), 39 deletions(-) > > diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c > index 0658908..9ccda73 100644 > --- a/drivers/usb/gadget/f_fs.c > +++ b/drivers/usb/gadget/f_fs.c > @@ -30,6 +30,21 @@ > > #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ I think something more explicit with fewer automatically declared variables cloud be more readable: > +/* Variable Length Array Macros **********************************************/ > +#define vla_group(groupname) size_t groupname##__##next = 0 > +#define vla_group_size(groupname) groupname##__##next #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 = \ > + (groupname##__##next + __alignof__(type) - 1) & \ > + ~(__alignof__(type) - 1); \ > + size_t groupname##_##name##__##sz = (n) * sizeof(type); \ > + type *groupname##_##name = ({ \ > + groupname##__##next = groupname##_##name##__##offset + \ > + groupname##_##name##__##sz; NULL; }) #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; }) I agree. Your proposal is cleaner. I can resubmit it.
I have already done so in the v2 series. There is an issue pointed by Sebastian, though. AP -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html