[PATCH v3][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning

Gustavo A. R. Silva posted 1 patch 1 month, 3 weeks ago
drivers/gpu/drm/nouveau/nvif/fifo.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[PATCH v3][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning
Posted by Gustavo A. R. Silva 1 month, 3 weeks ago
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

Use the new TRAILING_OVERLAP() helper to 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]

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.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes in v3:
 - Use the new TRAILING_OVERLAP() helper.

Changes in v2:
 - Adjust heap allocation.

 drivers/gpu/drm/nouveau/nvif/fifo.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvif/fifo.c b/drivers/gpu/drm/nouveau/nvif/fifo.c
index a463289962b2..b0ab80995d98 100644
--- a/drivers/gpu/drm/nouveau/nvif/fifo.c
+++ b/drivers/gpu/drm/nouveau/nvif/fifo.c
@@ -25,13 +25,12 @@ static int
 nvif_fifo_runlists(struct nvif_device *device)
 {
 	struct nvif_object *object = &device->object;
-	struct {
-		struct nv_device_info_v1 m;
+	TRAILING_OVERLAP(struct nv_device_info_v1, m, data,
 		struct {
 			struct nv_device_info_v1_data runlists;
 			struct nv_device_info_v1_data runlist[64];
 		} v;
-	} *a;
+	) *a;
 	int ret, i;
 
 	if (device->runlist)
-- 
2.43.0
Re: [PATCH v3][next] drm/nouveau: fifo: Avoid -Wflex-array-member-not-at-end warning
Posted by Justin Stitt 2 weeks, 4 days ago
Hi,

On Thu, Aug 14, 2025 at 03:01:07PM +0900, 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 new TRAILING_OVERLAP() helper to 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]
> 
> 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.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

I took a look at the modified structure layout with the union from the
macro using pahole and found the layouts and sizes to be equivalent --
all the while fixing the warning you demonstrated.

Reviewed-by: Justin Stitt <justinstitt@google.com>

> ---
> Changes in v3:
>  - Use the new TRAILING_OVERLAP() helper.

There's really starting to be a lot of these helper macros!

> 
> Changes in v2:
>  - Adjust heap allocation.
> 
>  drivers/gpu/drm/nouveau/nvif/fifo.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvif/fifo.c b/drivers/gpu/drm/nouveau/nvif/fifo.c
> index a463289962b2..b0ab80995d98 100644
> --- a/drivers/gpu/drm/nouveau/nvif/fifo.c
> +++ b/drivers/gpu/drm/nouveau/nvif/fifo.c
> @@ -25,13 +25,12 @@ static int
>  nvif_fifo_runlists(struct nvif_device *device)
>  {
>  	struct nvif_object *object = &device->object;
> -	struct {
> -		struct nv_device_info_v1 m;
> +	TRAILING_OVERLAP(struct nv_device_info_v1, m, data,
>  		struct {
>  			struct nv_device_info_v1_data runlists;
>  			struct nv_device_info_v1_data runlist[64];
>  		} v;
> -	} *a;
> +	) *a;
>  	int ret, i;
>  
>  	if (device->runlist)
> -- 
> 2.43.0
> 
>

Thanks
Justin