* [PATCH][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning
@ 2025-04-03 17:41 Gustavo A. R. Silva
2025-04-04 15:16 ` Gustavo A. R. Silva
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-03 17:41 UTC (permalink / raw)
To: Lyude Paul, Danilo Krummrich, David Airlie, Simona Vetter
Cc: dri-devel, nouveau, linux-kernel, Gustavo A. R. Silva,
linux-hardening
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.
Use the `DEFINE_RAW_FLEX()` helper for an on-stack definition of
a flexible structure where the size of the flexible-array member
is known at compile-time, and refactor the rest of the code,
accordingly.
So, with these changes, fix the following warning:
drivers/gpu/drm/nouveau/nvif/fifo.c:29:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/gpu/drm/nouveau/nvif/fifo.c | 32 ++++++++++++-----------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/nvif/fifo.c b/drivers/gpu/drm/nouveau/nvif/fifo.c
index a463289962b2..f8772340fec4 100644
--- a/drivers/gpu/drm/nouveau/nvif/fifo.c
+++ b/drivers/gpu/drm/nouveau/nvif/fifo.c
@@ -25,33 +25,28 @@ static int
nvif_fifo_runlists(struct nvif_device *device)
{
struct nvif_object *object = &device->object;
- struct {
- struct nv_device_info_v1 m;
- struct {
- struct nv_device_info_v1_data runlists;
- struct nv_device_info_v1_data runlist[64];
- } v;
- } *a;
+ DEFINE_RAW_FLEX(struct nv_device_info_v1, a, data, 65);
+ struct nv_device_info_v1_data *runlists = &a->data[0];
+ struct nv_device_info_v1_data *runlist = &a->data[1];
+ const u8 rl_cnt = (__struct_size(a) - sizeof(*a)) / sizeof(*a->data) - 1;
int ret, i;
if (device->runlist)
return 0;
- if (!(a = kmalloc(sizeof(*a), GFP_KERNEL)))
- return -ENOMEM;
- a->m.version = 1;
- a->m.count = sizeof(a->v) / sizeof(a->v.runlists);
- a->v.runlists.mthd = NV_DEVICE_HOST_RUNLISTS;
- for (i = 0; i < ARRAY_SIZE(a->v.runlist); i++) {
- a->v.runlist[i].mthd = NV_DEVICE_HOST_RUNLIST_ENGINES;
- a->v.runlist[i].data = i;
+ a->version = 1;
+ a->count = (__struct_size(a) - sizeof(*a)) / sizeof(*a->data);
+ runlists->mthd = NV_DEVICE_HOST_RUNLISTS;
+ for (i = 0; i < rl_cnt; i++) {
+ runlist[i].mthd = NV_DEVICE_HOST_RUNLIST_ENGINES;
+ runlist[i].data = i;
}
ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, a, sizeof(*a));
if (ret)
goto done;
- device->runlists = fls64(a->v.runlists.data);
+ device->runlists = fls64(runlists->data);
device->runlist = kcalloc(device->runlists, sizeof(*device->runlist),
GFP_KERNEL);
if (!device->runlist) {
@@ -60,12 +55,11 @@ nvif_fifo_runlists(struct nvif_device *device)
}
for (i = 0; i < device->runlists; i++) {
- if (a->v.runlist[i].mthd != NV_DEVICE_INFO_INVALID)
- device->runlist[i].engines = a->v.runlist[i].data;
+ if (runlist[i].mthd != NV_DEVICE_INFO_INVALID)
+ device->runlist[i].engines = runlist[i].data;
}
done:
- kfree(a);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning
2025-04-03 17:41 [PATCH][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-04-04 15:16 ` Gustavo A. R. Silva
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2025-04-04 15:16 UTC (permalink / raw)
To: Gustavo A. R. Silva, Lyude Paul, Danilo Krummrich, David Airlie,
Simona Vetter
Cc: dri-devel, nouveau, linux-kernel, linux-hardening
On 03/04/25 11:41, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> Use the `DEFINE_RAW_FLEX()` helper for an on-stack definition of
> a flexible structure where the size of the flexible-array member
> is known at compile-time, and refactor the rest of the code,
> accordingly.
>
> So, with these changes, fix the following warning:
>
> drivers/gpu/drm/nouveau/nvif/fifo.c:29:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/gpu/drm/nouveau/nvif/fifo.c | 32 ++++++++++++-----------------
> 1 file changed, 13 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nvif/fifo.c b/drivers/gpu/drm/nouveau/nvif/fifo.c
> index a463289962b2..f8772340fec4 100644
> --- a/drivers/gpu/drm/nouveau/nvif/fifo.c
> +++ b/drivers/gpu/drm/nouveau/nvif/fifo.c
> @@ -25,33 +25,28 @@ static int
> nvif_fifo_runlists(struct nvif_device *device)
> {
> struct nvif_object *object = &device->object;
> - struct {
> - struct nv_device_info_v1 m;
> - struct {
> - struct nv_device_info_v1_data runlists;
> - struct nv_device_info_v1_data runlist[64];
> - } v;
> - } *a;
> + DEFINE_RAW_FLEX(struct nv_device_info_v1, a, data, 65);
> + struct nv_device_info_v1_data *runlists = &a->data[0];
> + struct nv_device_info_v1_data *runlist = &a->data[1];
> + const u8 rl_cnt = (__struct_size(a) - sizeof(*a)) / sizeof(*a->data) - 1;
> int ret, i;
>
> if (device->runlist)
> return 0;
>
> - if (!(a = kmalloc(sizeof(*a), GFP_KERNEL)))
I'll send v2 preserving the above allocation (with some adjustments to
remove the flex-array-in-the-middle issue), as I just got this report
from the kernel test robot:
https://lore.kernel.org/lkml/202504041254.6e26LBdj-lkp@intel.com/
Thanks
--
Gustavo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-04 15:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-03 17:41 [PATCH][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-04-04 15:16 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).