Skip to contentSkip to conversation

media: xilinx: Avoid -Wflex-array-member-not-at-end warning

PATCH In review Gustavo A. R. Silva 3 participants 5 messages Apr 29 – Apr 30

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

PATCH 1/1 media: xilinx: 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 TRAILING_OVERLAP() helper to fix the following warning:

drivers/media/platform/xilinx/xilinx-dma.h:99:41: 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 data_chunk sgl; is not inadvertently changed, and it's intentionally placed inmediately after the related structure (that is, no blank line in between).

---
 drivers/media/platform/xilinx/xilinx-dma.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/xilinx/xilinx-dma.h +7 -2
index 18f77e1a7b39..65f6147ff6c6 100644
@@ -96,9 +96,14 @@ struct xvip_dma {
 
 	struct dma_chan *dma;
 	unsigned int align;
-	struct dma_interleaved_template xt;
-	struct data_chunk sgl;
+
+	/* Must be last as it ends in a flexible-array member. */
+	TRAILING_OVERLAP(struct dma_interleaved_template, xt, sgl,
+		struct data_chunk sgl;
+	);
 };
+static_assert(offsetof(struct xvip_dma, xt.sgl) ==
+	      offsetof(struct xvip_dma, sgl));
 
 #define to_xvip_dma(vdev)	container_of(vdev, struct xvip_dma, video)
 
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

CC'ing Tomi Valkeinen.

On a side note, Tomi, can I send a patch to add you to the "XILINX VIDEO IP CORES" section of MAINTAINERS ?

Quoted 12 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 TRAILING_OVERLAP() helper to fix the following warning:

drivers/media/platform/xilinx/xilinx-dma.h:99:41: 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.

Quoted 6 lines

Lastly, the static_assert() ensures the alignment between the FAM and struct data_chunk sgl; is not inadvertently changed, and it's intentionally placed inmediately after the related structure (that is, no blank line in between).

Quoted 25 lines
---
 drivers/media/platform/xilinx/xilinx-dma.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/xilinx/xilinx-dma.h +7 -2
index 18f77e1a7b39..65f6147ff6c6 100644
@@ -96,9 +96,14 @@ struct xvip_dma {
 
 	struct dma_chan *dma;
 	unsigned int align;
-	struct dma_interleaved_template xt;
-	struct data_chunk sgl;
+
+	/* Must be last as it ends in a flexible-array member. */
+	TRAILING_OVERLAP(struct dma_interleaved_template, xt, sgl,
+		struct data_chunk sgl;
+	);
 };
+static_assert(offsetof(struct xvip_dma, xt.sgl) ==
+	      offsetof(struct xvip_dma, sgl));
 
 #define to_xvip_dma(vdev)	container_of(vdev, struct xvip_dma, video)
 
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#2 lore raw

I forgot to ask, how do you want to get this merged? Will you collect all similar patches and send a tree-wide pull request, or should they be merged by individual subsystems ? In the latter case, Tomi, could you please handle this with other Xilinx patches ?

Quoted 52 lines · Laurent Pinchart

CC'ing Tomi Valkeinen.

On a side note, Tomi, can I send a patch to add you to the "XILINX VIDEO IP CORES" section of MAINTAINERS ?

Quoted 12 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 TRAILING_OVERLAP() helper to fix the following warning:

drivers/media/platform/xilinx/xilinx-dma.h:99:41: 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.

Quoted 6 lines

Lastly, the static_assert() ensures the alignment between the FAM and struct data_chunk sgl; is not inadvertently changed, and it's intentionally placed inmediately after the related structure (that is, no blank line in between).

Quoted 25 lines
---
 drivers/media/platform/xilinx/xilinx-dma.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/xilinx/xilinx-dma.h +7 -2
index 18f77e1a7b39..65f6147ff6c6 100644
@@ -96,9 +96,14 @@ struct xvip_dma {
 
 	struct dma_chan *dma;
 	unsigned int align;
-	struct dma_interleaved_template xt;
-	struct data_chunk sgl;
+
+	/* Must be last as it ends in a flexible-array member. */
+	TRAILING_OVERLAP(struct dma_interleaved_template, xt, sgl,
+		struct data_chunk sgl;
+	);
 };
+static_assert(offsetof(struct xvip_dma, xt.sgl) ==
+	      offsetof(struct xvip_dma, sgl));
 
 #define to_xvip_dma(vdev)	container_of(vdev, struct xvip_dma, video)
 
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw
Quoted 4 lines · Laurent Pinchart

I forgot to ask, how do you want to get this merged? Will you collect all similar patches and send a tree-wide pull request, or should they be merged by individual subsystems ? In the latter case, Tomi, could you please handle this with other Xilinx patches ?

You folks can take this in your tree. :)

Thanks!
-Gustavo

Quoted 55 lines · Laurent Pinchart
Quoted 52 lines

CC'ing Tomi Valkeinen.

On a side note, Tomi, can I send a patch to add you to the "XILINX VIDEO IP CORES" section of MAINTAINERS ?

Quoted 12 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 TRAILING_OVERLAP() helper to fix the following warning:

drivers/media/platform/xilinx/xilinx-dma.h:99:41: 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.

Quoted 6 lines

Lastly, the static_assert() ensures the alignment between the FAM and struct data_chunk sgl; is not inadvertently changed, and it's intentionally placed inmediately after the related structure (that is, no blank line in between).

Quoted 25 lines
---
  drivers/media/platform/xilinx/xilinx-dma.h | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/xilinx/xilinx-dma.h +7 -2
index 18f77e1a7b39..65f6147ff6c6 100644
@@ -96,9 +96,14 @@ struct xvip_dma {
 
  	struct dma_chan *dma;
  	unsigned int align;
-	struct dma_interleaved_template xt;
-	struct data_chunk sgl;
+
+	/* Must be last as it ends in a flexible-array member. */
+	TRAILING_OVERLAP(struct dma_interleaved_template, xt, sgl,
+		struct data_chunk sgl;
+	);
  };
+static_assert(offsetof(struct xvip_dma, xt.sgl) ==
+	      offsetof(struct xvip_dma, sgl));
 
  #define to_xvip_dma(vdev)	container_of(vdev, struct xvip_dma, video)
 
#4 lore raw
In reply to Laurent Pinchart
Quoted 4 lines · Laurent Pinchart

I forgot to ask, how do you want to get this merged? Will you collect all similar patches and send a tree-wide pull request, or should they be merged by individual subsystems ? In the latter case, Tomi, could you please handle this with other Xilinx patches ?

You folks can take this in your tree. 🙂

Thanks!
-Gustavo

Quoted 55 lines · Laurent Pinchart
Quoted 52 lines

CC'ing Tomi Valkeinen.

On a side note, Tomi, can I send a patch to add you to the "XILINX VIDEO IP CORES" section of MAINTAINERS ?

Quoted 12 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 TRAILING_OVERLAP() helper to fix the following warning:

drivers/media/platform/xilinx/xilinx-dma.h:99:41: 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.

Quoted 6 lines

Lastly, the static_assert() ensures the alignment between the FAM and struct data_chunk sgl; is not inadvertently changed, and it's intentionally placed inmediately after the related structure (that is, no blank line in between).

Quoted 25 lines
---
  drivers/media/platform/xilinx/xilinx-dma.h | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/xilinx/xilinx-dma.h +7 -2
index 18f77e1a7b39..65f6147ff6c6 100644
@@ -96,9 +96,14 @@ struct xvip_dma {
 
  	struct dma_chan *dma;
  	unsigned int align;
-	struct dma_interleaved_template xt;
-	struct data_chunk sgl;
+
+	/* Must be last as it ends in a flexible-array member. */
+	TRAILING_OVERLAP(struct dma_interleaved_template, xt, sgl,
+		struct data_chunk sgl;
+	);
  };
+static_assert(offsetof(struct xvip_dma, xt.sgl) ==
+	      offsetof(struct xvip_dma, sgl));
 
  #define to_xvip_dma(vdev)	container_of(vdev, struct xvip_dma, video)