Skip to contentSkip to conversation

drm/nouveau/outp: Avoid -Wflex-array-member-not-at-end warning

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Mar 28, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau/outp: Avoid -Wflex-array-member-not-at-end warning

-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/outp.c:199:45: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
 drivers/gpu/drm/nouveau/nvif/outp.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/nouveau/nvif/outp.c +7 -9
index 6daeb7f0b09b..403cf16d5e84 100644
@@ -195,20 +195,18 @@ nvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable)
 int
 nvif_outp_hda_eld(struct nvif_outp *outp, int head, void *data, u32 size)
 {
-	struct {
-		struct nvif_outp_hda_eld_v0 mthd;
-		u8 data[128];
-	} args;
+	DEFINE_RAW_FLEX(struct nvif_outp_hda_eld_v0, mthd, data, 128);
 	int ret;
 
-	if (WARN_ON(size > ARRAY_SIZE(args.data)))
+	if (WARN_ON(size > 128))
 		return -EINVAL;
 
-	args.mthd.version = 0;
-	args.mthd.head = head;
+	mthd->version = 0;
+	mthd->head = head;
 
-	memcpy(args.data, data, size);
-	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, &args, sizeof(args.mthd) + size);
+	memcpy(mthd->data, data, size);
+	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, mthd,
+			__struct_size(mthd) + size);
 	NVIF_ERRON(ret, &outp->object, "[HDA_ELD head:%d size:%d]", head, size);
 	return ret;
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 24 lines · Gustavo A. R. Silva

-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/outp.c:199:45: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
 drivers/gpu/drm/nouveau/nvif/outp.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/nouveau/nvif/outp.c +0 -0
index 6daeb7f0b09b..403cf16d5e84 100644
@@ -195,20 +195,18 @@ nvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable)
 int
 nvif_outp_hda_eld(struct nvif_outp *outp, int head, void *data, u32 size)

drivers/gpu/drm/nouveau/nvif/outp.c nvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable) · line 201

Quoted 10 lines
drivers/gpu/drm/nouveau/nvif/outp.c +2 -5
 {
-	struct {
-		struct nvif_outp_hda_eld_v0 mthd;
-		u8 data[128];
-	} args;
+	DEFINE_RAW_FLEX(struct nvif_outp_hda_eld_v0, mthd, data, 128);
 	int ret;
 
-	if (WARN_ON(size > ARRAY_SIZE(args.data)))
+	if (WARN_ON(size > 128))

Seems a bit unfortunate that the size is duplicated here.

Can we have an accessor macro to derive the size for us?

	union {
		u8 bytes[struct_size_t(type, member, count)];
		type obj;
	} name##_u initializer;

Maybe a macro that returns the size difference between bytes and obj?

Quoted 18 lines
drivers/gpu/drm/nouveau/nvif/outp.c +5 -4
 		return -EINVAL;
 
-	args.mthd.version = 0;
-	args.mthd.head = head;
+	mthd->version = 0;
+	mthd->head = head;
 
-	memcpy(args.data, data, size);
-	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, &args, sizeof(args.mthd) + size);
+	memcpy(mthd->data, data, size);
+	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, mthd,
+			__struct_size(mthd) + size);
 	NVIF_ERRON(ret, &outp->object, "[HDA_ELD head:%d size:%d]", head, size);
 	return ret;
 }
Signature · 1 line
2.43.0
#2 lore raw
Quoted 33 lines · Danilo Krummrich
Quoted 32 lines · Gustavo A. R. Silva

-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/outp.c:199:45: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
  drivers/gpu/drm/nouveau/nvif/outp.c | 16 +++++++---------
  1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/drm/nouveau/nvif/outp.c +1 -4
index 6daeb7f0b09b..403cf16d5e84 100644
@@ -195,20 +195,18 @@ nvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable)
  int
  nvif_outp_hda_eld(struct nvif_outp *outp, int head, void *data, u32 size)
  {
-	struct {
-		struct nvif_outp_hda_eld_v0 mthd;
-		u8 data[128];
-	} args;
+	DEFINE_RAW_FLEX(struct nvif_outp_hda_eld_v0, mthd, data, 128);
  	int ret;
 
Quoted 4 lines

drivers/gpu/drm/nouveau/nvif/outp.c nvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable) · line 201

Quoted 2 lines
drivers/gpu/drm/nouveau/nvif/outp.c +1 -1
-	if (WARN_ON(size > ARRAY_SIZE(args.data)))
+	if (WARN_ON(size > 128))

Seems a bit unfortunate that the size is duplicated here.

For now, I think we can do something like this instead:

- if (WARN_ON(size > ARRAY_SIZE(args.data)))
+ if (WARN_ON(size > (__struct_size(mthd) - sizeof(*mthd))))

Thanks
-Gustavo

Quoted 29 lines

Can we have an accessor macro to derive the size for us?

	union {
		u8 bytes[struct_size_t(type, member, count)];
		type obj;
	} name##_u initializer;

Maybe a macro that returns the size difference between bytes and obj?

Quoted 18 lines
drivers/gpu/drm/nouveau/nvif/outp.c +5 -4
  		return -EINVAL;
 
-	args.mthd.version = 0;
-	args.mthd.head = head;
+	mthd->version = 0;
+	mthd->head = head;
 
-	memcpy(args.data, data, size);
-	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, &args, sizeof(args.mthd) + size);
+	memcpy(mthd->data, data, size);
+	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, mthd,
+			__struct_size(mthd) + size);
  	NVIF_ERRON(ret, &outp->object, "[HDA_ELD head:%d size:%d]", head, size);
  	return ret;
  }
Signature · 1 line
2.43.0