From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Zhenyu Wang <zhenyuw.linux@gmail.com>,
Zhi Wang <zhi.wang.linux@gmail.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tursulin@ursulin.net>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] drm/i915/gvt: Avoid -Wflex-array-member-not-at-end warning
Date: Tue, 28 Apr 2026 10:53:28 +0300 [thread overview]
Message-ID: <4d5f5949b34f7bba00ed570ad2098074aa0c05f5@intel.com> (raw)
In-Reply-To: <ae_4GkBsNl_0SYTm@kspp>
On Mon, 27 Apr 2026, "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> Use the TRAILING_OVERLAP() helper to fix the following warning:
>
> drivers/gpu/drm/i915/gvt/opregion.c:126:40: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>
> This helper creates a union between a flexible-array member (FAM)
> and a set of members that would otherwise follow it. This overlays
> the trailing members onto the FAM while preserving the original
> memory layout.
>
> Lastly, the static_assert() ensures the alignment between the FAM and
> struct efp_child_device_config child0; is not inadvertently changed,
> and it's intentionally placed inmediately after the related structure
> (that is, no blank line in between).
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/gpu/drm/i915/gvt/opregion.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
> index d6e76ba31d60..efe457c02788 100644
> --- a/drivers/gpu/drm/i915/gvt/opregion.c
> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
> @@ -122,17 +122,21 @@ struct vbt {
> struct bdb_data_header general_features_header;
> struct bdb_general_features general_features;
>
> - struct bdb_data_header general_definitions_header;
> - struct bdb_general_definitions general_definitions;
> -
> - struct efp_child_device_config child0;
> - struct efp_child_device_config child1;
> - struct efp_child_device_config child2;
> - struct efp_child_device_config child3;
> -
> struct bdb_data_header driver_features_header;
> struct bdb_driver_features driver_features;
> +
> + struct bdb_data_header general_definitions_header;
> +
> + /* Must be last as it ends in a flexible-array member. */
> + TRAILING_OVERLAP(struct bdb_general_definitions, general_definitions, devices,
> + struct efp_child_device_config child0;
> + struct efp_child_device_config child1;
> + struct efp_child_device_config child2;
> + struct efp_child_device_config child3;
> + );
So this impacts the generation of a binary blob, parsed by the client OS
driver. In theory, the order of the BDB blocks shouldn't matter, but who
knows.
Anyway, I'm more worried about inadvertent padding potentially being
introduced. struct vbt should have __packed attribute, which is missing,
but I also think the union and the struct within TRAILING_OVERLAP()
should also have __packed.
Like, if struct efp_child_device_config gets extended by one byte,
what's going to happen with padding? It's __packed on its own, but IIUC
that doesn't automatically apply to the enclosing structs or unions.
> };
> +static_assert(offsetof(struct vbt, general_definitions.devices) ==
> + offsetof(struct vbt, child0));
Perhaps also assert child1 offset is child0 offset + sizeof(struct
efp_child_device_config)? That should cover the padding, right?
BR,
Jani.
>
> static void virt_vbt_generation(struct vbt *v)
> {
--
Jani Nikula, Intel
next prev parent reply other threads:[~2026-04-28 7:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 23:58 Gustavo A. R. Silva
2026-04-28 7:53 ` Jani Nikula [this message]
2026-04-28 16:32 ` Gustavo A. R. Silva
2026-05-11 20:01 ` Gustavo A. R. Silva
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=4d5f5949b34f7bba00ed570ad2098074aa0c05f5@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavoars@kernel.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=tursulin@ursulin.net \
--cc=zhenyuw.linux@gmail.com \
--cc=zhi.wang.linux@gmail.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
all inboxes | Powered by JetHome®