public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
To: charlebm@gmail.com
Cc: balbi@ti.com, Behan Webster <behanw@converseincode.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	USB list <linux-usb@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Remove VLAIS usage from gadget code - alternate patch
Date: Wed, 25 Sep 2013 16:35:14 +0200	[thread overview]
Message-ID: <5242F4A2.60308@samsung.com> (raw)
In-Reply-To: <1380045419-10367-1-git-send-email-charlebm@gmail.com>

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@gmail.com pisze:
> From: Mark Charlebois <charlebm@gmail.com>
>
>
> --- 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

  parent reply	other threads:[~2013-09-25 14:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 17:56 [PATCH] Remove VLAIS usage from gadget code - alternate patch charlebm
2013-09-24 21:12 ` Behan Webster
2013-09-25 14:35 ` Andrzej Pietrasiewicz [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-09-25 21:23 charlebm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5242F4A2.60308@samsung.com \
    --to=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=behanw@converseincode.com \
    --cc=charlebm@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox