lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-id: <5242F4A2.60308@samsung.com>
Date:	Wed, 25 Sep 2013 16:35:14 +0200
From:	Andrzej Pietrasiewicz <andrzej.p@...sung.com>
To:	charlebm@...il.com
Cc:	balbi@...com, Behan Webster <behanw@...verseincode.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	USB list <linux-usb@...r.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Remove VLAIS usage from gadget code - alternate patch

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@...il.com pisze:
> From: Mark Charlebois <charlebm@...il.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ