Re: [PATCH v2 01/28] drm/atomic: Fix unused but set warning in state iterator macros

From: Simona Vetter

Date: Thu May 21 2026 - 06:22:34 EST


On Thu, Apr 23, 2026 at 12:18:14PM +0200, Maxime Ripard wrote:
> A number of state iterator macros trigger a compiler warning if an
> iterator parameter isn't used in the code block.
>
> Add a similar workaround than in most other macros.

I'm not on top of macro-fu, so not leaning out the window and dropping an
r-b here. But sounds reasonable.

Acked-by: Simona Vetter <simona.vetter@xxxxxxxx>

>
> Signed-off-by: Maxime Ripard <mripard@xxxxxxxxxx>
> ---
> include/drm/drm_atomic.h | 64 +++++++++++++++++++++++++++++++-----------------
> 1 file changed, 42 insertions(+), 22 deletions(-)
>
> diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> index f03cd199aee7..b9e7281cfc97 100644
> --- a/include/drm/drm_atomic.h
> +++ b/include/drm/drm_atomic.h
> @@ -946,13 +946,15 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> for ((__i) = 0; \
> (__i) < (__state)->num_connector; \
> (__i)++) \
> for_each_if ((__state)->connectors[__i].ptr && \
> ((connector) = (__state)->connectors[__i].ptr, \
> - (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
> - (old_connector_state) = (__state)->connectors[__i].old_state, \
> - (new_connector_state) = (__state)->connectors[__i].new_state, 1))
> + (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
> + (old_connector_state) = (__state)->connectors[__i].old_state, \
> + (void)(old_connector_state) /* Only to avoid unused-but-set-variable warning */, \
> + (new_connector_state) = (__state)->connectors[__i].new_state, \
> + (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_old_connector_in_state - iterate over all connectors in an atomic update
> * @__state: &struct drm_atomic_state pointer
> * @connector: &struct drm_connector iteration cursor
> @@ -968,12 +970,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> for ((__i) = 0; \
> (__i) < (__state)->num_connector; \
> (__i)++) \
> for_each_if ((__state)->connectors[__i].ptr && \
> ((connector) = (__state)->connectors[__i].ptr, \
> - (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
> - (old_connector_state) = (__state)->connectors[__i].old_state, 1))
> + (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
> + (old_connector_state) = (__state)->connectors[__i].old_state, \
> + (void)(old_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_new_connector_in_state - iterate over all connectors in an atomic update
> * @__state: &struct drm_atomic_state pointer
> * @connector: &struct drm_connector iteration cursor
> @@ -989,13 +992,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> for ((__i) = 0; \
> (__i) < (__state)->num_connector; \
> (__i)++) \
> for_each_if ((__state)->connectors[__i].ptr && \
> ((connector) = (__state)->connectors[__i].ptr, \
> - (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
> - (new_connector_state) = (__state)->connectors[__i].new_state, \
> - (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
> + (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
> + (new_connector_state) = (__state)->connectors[__i].new_state, \
> + (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
> * @__state: &struct drm_atomic_state pointer
> * @crtc: &struct drm_crtc iteration cursor
> @@ -1012,14 +1015,14 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> (__i) < (__state)->dev->mode_config.num_crtc; \
> (__i)++) \
> for_each_if ((__state)->crtcs[__i].ptr && \
> ((crtc) = (__state)->crtcs[__i].ptr, \
> (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
> - (old_crtc_state) = (__state)->crtcs[__i].old_state, \
> - (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
> - (new_crtc_state) = (__state)->crtcs[__i].new_state, \
> - (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
> + (old_crtc_state) = (__state)->crtcs[__i].old_state, \
> + (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
> + (new_crtc_state) = (__state)->crtcs[__i].new_state, \
> + (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
> * @__state: &struct drm_atomic_state pointer
> * @crtc: &struct drm_crtc iteration cursor
> @@ -1035,11 +1038,12 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> (__i) < (__state)->dev->mode_config.num_crtc; \
> (__i)++) \
> for_each_if ((__state)->crtcs[__i].ptr && \
> ((crtc) = (__state)->crtcs[__i].ptr, \
> (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
> - (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
> + (old_crtc_state) = (__state)->crtcs[__i].old_state, \
> + (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
> * @__state: &struct drm_atomic_state pointer
> * @crtc: &struct drm_crtc iteration cursor
> @@ -1120,12 +1124,14 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> (__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,\
> - (new_plane_state) = (__state)->planes[__i].new_state, 1))
> + (old_plane_state) = (__state)->planes[__i].old_state, \
> + (void)(old_plane_state) /* Only to avoid unused-but-set-variable warning */, \
> + (new_plane_state) = (__state)->planes[__i].new_state, \
> + (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
> * update in reverse order
> * @__state: &struct drm_atomic_state pointer
> @@ -1142,12 +1148,15 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
> (__i) >= 0; \
> (__i)--) \
> for_each_if ((__state)->planes[__i].ptr && \
> ((plane) = (__state)->planes[__i].ptr, \
> - (old_plane_state) = (__state)->planes[__i].old_state,\
> - (new_plane_state) = (__state)->planes[__i].new_state, 1))
> + (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
> + (old_plane_state) = (__state)->planes[__i].old_state, \
> + (void)(old_plane_state) /* Only to avoid unused-but-set-variable warning */, \
> + (new_plane_state) = (__state)->planes[__i].new_state, \
> + (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_new_plane_in_state_reverse - other than only tracking new state,
> * it's the same as for_each_oldnew_plane_in_state_reverse
> * @__state: &struct drm_atomic_state pointer
> @@ -1159,11 +1168,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
> (__i) >= 0; \
> (__i)--) \
> for_each_if ((__state)->planes[__i].ptr && \
> ((plane) = (__state)->planes[__i].ptr, \
> - (new_plane_state) = (__state)->planes[__i].new_state, 1))
> + (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
> + (new_plane_state) = (__state)->planes[__i].new_state, \
> + (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
>
> /**
> * for_each_old_plane_in_state - iterate over all planes in an atomic update
> * @__state: &struct drm_atomic_state pointer
> * @plane: &struct drm_plane iteration cursor
> @@ -1178,11 +1189,14 @@ 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, \
> - (old_plane_state) = (__state)->planes[__i].old_state, 1))
> + (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
> + (old_plane_state) = (__state)->planes[__i].old_state, \
> + (void)(old_plane_state) /* Only to avoid unused-but-set-variable warning */, 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
> @@ -1216,12 +1230,15 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> */
> #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
> for ((__i) = 0; \
> (__i) < (__state)->num_private_objs && \
> ((obj) = (__state)->private_objs[__i].ptr, \
> + (void)(obj) /* Only to avoid unused-but-set-variable warning */, \
> (old_obj_state) = (__state)->private_objs[__i].old_state, \
> - (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
> + (void)(old_obj_state) /* Only to avoid unused-but-set-variable warning */, \
> + (new_obj_state) = (__state)->private_objs[__i].new_state, \
> + (void)(new_obj_state) /* Only to avoid unused-but-set-variable warning */, 1); \
> (__i)++)
>
> /**
> * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
> * @__state: &struct drm_atomic_state pointer
> @@ -1235,11 +1252,13 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> */
> #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
> for ((__i) = 0; \
> (__i) < (__state)->num_private_objs && \
> ((obj) = (__state)->private_objs[__i].ptr, \
> - (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
> + (void)(obj) /* Only to avoid unused-but-set-variable warning */, \
> + (old_obj_state) = (__state)->private_objs[__i].old_state, \
> + (void)(old_obj_state) /* Only to avoid unused-but-set-variable warning */, 1); \
> (__i)++)
>
> /**
> * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
> * @__state: &struct drm_atomic_state pointer
> @@ -1254,11 +1273,12 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
> #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
> for ((__i) = 0; \
> (__i) < (__state)->num_private_objs && \
> ((obj) = (__state)->private_objs[__i].ptr, \
> (void)(obj) /* Only to avoid unused-but-set-variable warning */, \
> - (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
> + (new_obj_state) = (__state)->private_objs[__i].new_state, \
> + (void)(new_obj_state) /* Only to avoid unused-but-set-variable warning */, 1); \
> (__i)++)
>
> /**
> * drm_atomic_crtc_needs_modeset - compute combined modeset need
> * @state: &drm_crtc_state for the CRTC
>
> --
> 2.53.0
>

--
Simona Vetter
Software Engineer
http://blog.ffwll.ch