[PATCH 02/29] drm/atomic: Fix unused but set warning in for_each_old_plane_in_state

Maxime Ripard posted 29 patches 1 month ago
[PATCH 02/29] drm/atomic: Fix unused but set warning in for_each_old_plane_in_state
Posted by Maxime Ripard 1 month ago
The for_each_old_plane_in_state() macro triggers a compiler warning if
the plane parameter passed to it isn't used in the code block.

Add a similar workaround than in most other macros.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 include/drm/drm_atomic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 38636a593c9d98cadda85ccd67326cb152f0dd27..689a29bdeb4a06672ab6fffecb513d58ff6e07f9 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -1053,11 +1053,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
 	for ((__i) = 0;							\
 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
 	     (__i)++)							\
 		for_each_if ((__state)->planes[__i].ptr &&		\
 			     ((plane) = (__state)->planes[__i].ptr,	\
+			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
 			      (old_plane_state) = (__state)->planes[__i].old_state, 1))
+
 /**
  * for_each_new_plane_in_state - iterate over all planes in an atomic update
  * @__state: &struct drm_atomic_state pointer
  * @plane: &struct drm_plane iteration cursor
  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state

-- 
2.50.1
Re: [PATCH 02/29] drm/atomic: Fix unused but set warning in for_each_old_plane_in_state
Posted by Laurent Pinchart 1 month ago
Hi Maxime,

Thank you for the patch.

On Tue, Sep 02, 2025 at 10:32:30AM +0200, Maxime Ripard wrote:
> The for_each_old_plane_in_state() macro triggers a compiler warning if
> the plane parameter passed to it isn't used in the code block.
> 
> Add a similar workaround than in most other macros.
> 
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
>  include/drm/drm_atomic.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index 38636a593c9d98cadda85ccd67326cb152f0dd27..689a29bdeb4a06672ab6fffecb513d58ff6e07f9 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -1053,11 +1053,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
>  	for ((__i) = 0;							\
>  	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
>  	     (__i)++)							\
>  		for_each_if ((__state)->planes[__i].ptr &&		\
>  			     ((plane) = (__state)->planes[__i].ptr,	\
> +			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
>  			      (old_plane_state) = (__state)->planes[__i].old_state, 1))
> +

While at it, shouldn't you apply the same workaround to the
old_plane_state variable, like done for new_plane_state in
for_each_new_plane_in_state() ? Or is it expected that drivers will
always make use of it.

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

>  /**
>   * for_each_new_plane_in_state - iterate over all planes in an atomic update
>   * @__state: &struct drm_atomic_state pointer
>   * @plane: &struct drm_plane iteration cursor
>   * @new_plane_state: &struct drm_plane_state iteration cursor for the new state

-- 
Regards,

Laurent Pinchart
Re: [PATCH 02/29] drm/atomic: Fix unused but set warning in for_each_old_plane_in_state
Posted by Thomas Zimmermann 1 month ago
Hi

Am 02.09.25 um 10:32 schrieb Maxime Ripard:
> The for_each_old_plane_in_state() macro triggers a compiler warning if
> the plane parameter passed to it isn't used in the code block.
>
> Add a similar workaround than in most other macros.
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

This patch should probably get merged in any case

Best regards
Thomas

> ---
>   include/drm/drm_atomic.h | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index 38636a593c9d98cadda85ccd67326cb152f0dd27..689a29bdeb4a06672ab6fffecb513d58ff6e07f9 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -1053,11 +1053,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
>   	for ((__i) = 0;							\
>   	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
>   	     (__i)++)							\
>   		for_each_if ((__state)->planes[__i].ptr &&		\
>   			     ((plane) = (__state)->planes[__i].ptr,	\
> +			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
>   			      (old_plane_state) = (__state)->planes[__i].old_state, 1))
> +
>   /**
>    * for_each_new_plane_in_state - iterate over all planes in an atomic update
>    * @__state: &struct drm_atomic_state pointer
>    * @plane: &struct drm_plane iteration cursor
>    * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)