[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1f9cb37f21294c31a01af62fd920f070@AcuMS.aculab.com>
Date: Thu, 17 Aug 2023 14:35:23 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Przemek Kitszel' <przemyslaw.kitszel@...el.com>,
Kees Cook <keescook@...omium.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC: Jacob Keller <jacob.e.keller@...el.com>,
"intel-wired-lan@...ts.osuosl.org" <intel-wired-lan@...ts.osuosl.org>,
Alexander Lobakin <aleksander.lobakin@...el.com>,
"linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>,
"Steven Zou" <steven.zou@...el.com>
Subject: RE: [PATCH net-next v3 1/7] overflow: add DEFINE_FLEX() for on-stack
allocs
From: Przemek Kitszel
> Sent: Wednesday, August 16, 2023 3:06 PM
>
> Using underlying array for on-stack storage lets us to declare
> known-at-compile-time structures without kzalloc().
Isn't DEFINE_FLEX() a bit misleading?
One thing it isn't is 'flexible' since it has a fixed size.
> +#define DEFINE_FLEX(type, name, member, count) \
> + union { \
> + u8 bytes[struct_size_t(type, member, count)]; \
> + type obj; \
> + } name##_u __aligned(_Alignof(type)) = {}; \
You shouldn't need the _Alignof() it is the default.
I'm not sure you should be forcing the memset() either.
> + type *name = (type *)&name##_u
How about?
type *const name = &name_##_u.obj;
You might want to add:
Static_assert(is_constexpr(count), "DEFINE_FLEX: non-constant count " #count);
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists