Linux Hardening
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Przemek Kitszel <przemyslaw.kitszel@intel.com>, netdev@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
	Jacob Keller <jacob.e.keller@intel.com>,
	intel-wired-lan@lists.osuosl.org,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	linux-hardening@vger.kernel.org,
	Steven Zou <steven.zou@intel.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Anthony Nguyen <anthony.l.nguyen@intel.com>,
	David Laight <David.Laight@ACULAB.COM>
Subject: Re: [RFC net-next v4 1/7] overflow: add DEFINE_FLEX() for on-stack allocs
Date: Mon, 04 Sep 2023 20:55:29 -0700	[thread overview]
Message-ID: <7AB970A3-883F-49A4-BBCD-23E2CD1E869C@kernel.org> (raw)
In-Reply-To: <20230904123107.116381-2-przemyslaw.kitszel@intel.com>

On September 4, 2023 5:31:01 AM PDT, Przemek Kitszel <przemyslaw.kitszel@intel.com> wrote:
> [...]
>+/**
>+ * _DEFINE_FLEX() - helper macro for DEFINE_FLEX() family.
>+ * Enables caller macro to pass (different) initializer.
>+ *
>+ * @type: structure type name, including "struct" keyword.
>+ * @name: Name for a variable to define.
>+ * @member: Name of the array member.
>+ * @count: Number of elements in the array; must be compile-time const.
>+ * @initializer: initializer expression (could be empty for no init).
>+ */
>+#define _DEFINE_FLEX(type, name, member, count, initializer)			\
>+	_Static_assert(__builtin_constant_p(count),				\
>+		       "onstack flex array members require compile-time const count"); \
>+	union {									\
>+		u8 bytes[struct_size_t(type, member, count)];			\
>+		type obj;							\
>+	} name##_u initializer;							\
>+	type *name = (type *)&name##_u

Yeah, I like this! This will make it easy to add __counted_by initializers when we have the need in the future.



-- 
Kees Cook

  reply	other threads:[~2023-09-05 16:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04 12:31 [RFC net-next v4 0/7] introduce DEFINE_FLEX() macro Przemek Kitszel
2023-09-04 12:31 ` [RFC net-next v4 1/7] overflow: add DEFINE_FLEX() for on-stack allocs Przemek Kitszel
2023-09-05  3:55   ` Kees Cook [this message]
2023-09-04 12:31 ` [RFC net-next v4 2/7] ice: ice_sched_remove_elems: replace 1 elem array param by u32 Przemek Kitszel
2023-09-04 12:31 ` [RFC net-next v4 3/7] ice: drop two params of ice_aq_move_sched_elems() Przemek Kitszel
2023-09-04 12:31 ` [RFC net-next v4 4/7] ice: make use of DEFINE_FLEX() in ice_ddp.c Przemek Kitszel
2023-09-04 12:31 ` [RFC net-next v4 5/7] ice: make use of DEFINE_FLEX() for struct ice_aqc_add_tx_qgrp Przemek Kitszel
2023-09-04 12:31 ` [RFC net-next v4 6/7] ice: make use of DEFINE_FLEX() for struct ice_aqc_dis_txq_item Przemek Kitszel
2023-09-04 12:31 ` [RFC net-next v4 7/7] ice: make use of DEFINE_FLEX() in ice_switch.c Przemek Kitszel
2023-09-04 12:37 ` [RFC net-next v4 0/7] introduce DEFINE_FLEX() macro Przemek Kitszel
2023-09-05  3:53 ` Kees Cook

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=7AB970A3-883F-49A4-BBCD-23E2CD1E869C@kernel.org \
    --to=kees@kernel.org \
    --cc=David.Laight@ACULAB.COM \
    --cc=aleksander.lobakin@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jacob.e.keller@intel.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=steven.zou@intel.com \
    /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