mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: Use separate iterator for preferred mode lookup
@ 2026-10-08  5:17 Yibiao Li
  2026-10-16 15:50 ` Alex Hung
  0 siblings, 1 reply; 3+ messages in thread
From: Yibiao Li @ 2026-10-08  5:17 UTC (permalink / raw)
  To: amd-gfx, Harry Wentland, Leo Li
  Cc: Rodrigo Siqueira, Alex Deucher, Christian König, dri-devel,
	linux-kernel, kernel test robot

From: Yibiao Li <biaobiao2233@gmail.com>

create_stream_for_sink() uses preferred_mode both as the list iterator
and as the selected mode. This triggers a false positive from
scripts/coccinelle/iterators/use_after_iter.cocci: native_mode_found
already ensures that an exhausted iterator is replaced before use.

Use a separate iterator and assign preferred_mode only when a preferred
entry is found. This keeps the selected mode separate from the iterator
state and makes native_mode_found unnecessary. Preserve the fallback to
the first entry, or NULL when the list is empty.

No functional change intended.

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202609190901.yKTzhsGz-lkp@intel.com/
Assisted-by: LLM coccinelle
Signed-off-by: Yibiao Li <biaobiao2233@gmail.com>
---
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
index d386bb1475..ceea8fe481 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
@@ -1453,12 +1453,12 @@ create_stream_for_sink(struct drm_connector *connector,
 	struct drm_device *dev = connector->dev;
 	struct amdgpu_dm_connector *aconnector = NULL;
 	struct drm_display_mode *preferred_mode = NULL;
+	struct drm_display_mode *connector_mode;
 	const struct drm_connector_state *con_state = &dm_state->base;
 	struct dc_stream_state *stream = NULL;
 	struct drm_display_mode mode;
 	struct drm_display_mode saved_mode;
 	struct drm_display_mode *freesync_mode = NULL;
-	bool native_mode_found = false;
 	bool recalculate_timing = false;
 	bool scale = dm_state->scaling != RMX_OFF;
 	int mode_refresh;
@@ -1509,14 +1509,14 @@ create_stream_for_sink(struct drm_connector *connector,
 	stream->timing.flags.LTE_340MCSC_SCRAMBLE =
 		connector->display_info.hdmi.scdc.scrambling.low_rates;

-	list_for_each_entry(preferred_mode, &connector->modes, head) {
+	list_for_each_entry(connector_mode, &connector->modes, head) {
 		/* Search for preferred mode */
-		if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED) {
-			native_mode_found = true;
+		if (connector_mode->type & DRM_MODE_TYPE_PREFERRED) {
+			preferred_mode = connector_mode;
 			break;
 		}
 	}
-	if (!native_mode_found)
+	if (!preferred_mode)
 		preferred_mode = list_first_entry_or_null(
 				&connector->modes,
 				struct drm_display_mode,
-- 
2.43.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amd/display: Use separate iterator for preferred mode lookup
  2026-10-08  5:17 [PATCH] drm/amd/display: Use separate iterator for preferred mode lookup Yibiao Li
@ 2026-10-16 15:50 ` Alex Hung
  2026-10-16 17:37   ` Yibiao Li
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Hung @ 2026-10-16 15:50 UTC (permalink / raw)
  To: Yibiao Li, amd-gfx, Harry Wentland, Leo Li
  Cc: Rodrigo Siqueira, Alex Deucher, Christian König, dri-devel,
	linux-kernel, kernel test robot

Reviewed-by: Alex Hung <alex.hung@amd.com>

On 10/7/26 23:17, Yibiao Li wrote:
> [Some people who received this message don't often get email from biaobiao2233@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> From: Yibiao Li <biaobiao2233@gmail.com>
> 
> create_stream_for_sink() uses preferred_mode both as the list iterator
> and as the selected mode. This triggers a false positive from
> scripts/coccinelle/iterators/use_after_iter.cocci: native_mode_found
> already ensures that an exhausted iterator is replaced before use.
> 
> Use a separate iterator and assign preferred_mode only when a preferred
> entry is found. This keeps the selected mode separate from the iterator
> state and makes native_mode_found unnecessary. Preserve the fallback to
> the first entry, or NULL when the list is empty.
> 
> No functional change intended.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/oe-kbuild-all/202609190901.yKTzhsGz-lkp@intel.com/
> Assisted-by: LLM coccinelle
> Signed-off-by: Yibiao Li <biaobiao2233@gmail.com>
> ---
>   .../drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c    | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> index d386bb1475..ceea8fe481 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> @@ -1453,12 +1453,12 @@ create_stream_for_sink(struct drm_connector *connector,
>          struct drm_device *dev = connector->dev;
>          struct amdgpu_dm_connector *aconnector = NULL;
>          struct drm_display_mode *preferred_mode = NULL;
> +       struct drm_display_mode *connector_mode;
>          const struct drm_connector_state *con_state = &dm_state->base;
>          struct dc_stream_state *stream = NULL;
>          struct drm_display_mode mode;
>          struct drm_display_mode saved_mode;
>          struct drm_display_mode *freesync_mode = NULL;
> -       bool native_mode_found = false;
>          bool recalculate_timing = false;
>          bool scale = dm_state->scaling != RMX_OFF;
>          int mode_refresh;
> @@ -1509,14 +1509,14 @@ create_stream_for_sink(struct drm_connector *connector,
>          stream->timing.flags.LTE_340MCSC_SCRAMBLE =
>                  connector->display_info.hdmi.scdc.scrambling.low_rates;
> 
> -       list_for_each_entry(preferred_mode, &connector->modes, head) {
> +       list_for_each_entry(connector_mode, &connector->modes, head) {
>                  /* Search for preferred mode */
> -               if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED) {
> -                       native_mode_found = true;
> +               if (connector_mode->type & DRM_MODE_TYPE_PREFERRED) {
> +                       preferred_mode = connector_mode;
>                          break;
>                  }
>          }
> -       if (!native_mode_found)
> +       if (!preferred_mode)
>                  preferred_mode = list_first_entry_or_null(
>                                  &connector->modes,
>                                  struct drm_display_mode,
> --
> 2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amd/display: Use separate iterator for preferred mode lookup
  2026-10-16 15:50 ` Alex Hung
@ 2026-10-16 17:37   ` Yibiao Li
  0 siblings, 0 replies; 3+ messages in thread
From: Yibiao Li @ 2026-10-16 17:37 UTC (permalink / raw)
  To: Alex Hung
  Cc: amd-gfx, Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, dri-devel, linux-kernel, kernel test robot

On Fri, Oct 16, 2026 at 09:50:44AM -0600, Alex Hung wrote:
> Reviewed-by: Alex Hung <alex.hung@amd.com>

Thanks for the review, Alex!

Best regards,
Yibiao


On Fri, 16 Oct 2026 09:50:44 -0600, Alex Hung <alex.hung@amd.com> wrote:
> Reviewed-by: Alex Hung <alex.hung@amd.com>
>
> On 10/7/26 23:17, Yibiao Li wrote:
> > [Some people who received this message don't often get email from biaobiao2233@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> >
> > From: Yibiao Li <biaobiao2233@gmail.com>
> >
> > create_stream_for_sink() uses preferred_mode both as the list iterator
> > and as the selected mode. This triggers a false positive from
> > scripts/coccinelle/iterators/use_after_iter.cocci: native_mode_found
> > already ensures that an exhausted iterator is replaced before use.
> >
> > Use a separate iterator and assign preferred_mode only when a preferred
> > entry is found. This keeps the selected mode separate from the iterator
> > state and makes native_mode_found unnecessary. Preserve the fallback to
> > the first entry, or NULL when the list is empty.
> >
> > No functional change intended.
> >
> > Reported-by: kernel test robot <lkp@intel.com>
> > Link: https://lore.kernel.org/oe-kbuild-all/202609190901.yKTzhsGz-lkp@intel.com/
> > Assisted-by: LLM coccinelle
> > Signed-off-by: Yibiao Li <biaobiao2233@gmail.com>
> > ---
> >   .../drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c    | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> > b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> > index d386bb1475..ceea8fe481 100644
> > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
> > @@ -1453,12 +1453,12 @@ create_stream_for_sink(struct drm_connector *connector,
> >          struct drm_device *dev = connector->dev;
> >          struct amdgpu_dm_connector *aconnector = NULL;
> >          struct drm_display_mode *preferred_mode = NULL;
> > +       struct drm_display_mode *connector_mode;
> >          const struct drm_connector_state *con_state = &dm_state->base;
> >          struct dc_stream_state *stream = NULL;
> >          struct drm_display_mode mode;
> >          struct drm_display_mode saved_mode;
> >          struct drm_display_mode *freesync_mode = NULL;
> > -       bool native_mode_found = false;
> >          bool recalculate_timing = false;
> >          bool scale = dm_state->scaling != RMX_OFF;
> >          int mode_refresh;
> > @@ -1509,14 +1509,14 @@ create_stream_for_sink(struct drm_connector *connector,
> >          stream->timing.flags.LTE_340MCSC_SCRAMBLE =
> >                  connector->display_info.hdmi.scdc.scrambling.low_rates;
> >
> > -       list_for_each_entry(preferred_mode, &connector->modes, head) {
> > +       list_for_each_entry(connector_mode, &connector->modes, head) {
> >                  /* Search for preferred mode */
> > -               if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED) {
> > -                       native_mode_found = true;
> > +               if (connector_mode->type & DRM_MODE_TYPE_PREFERRED) {
> > +                       preferred_mode = connector_mode;
> >                          break;
> >                  }
> >          }
> > -       if (!native_mode_found)
> > +       if (!preferred_mode)
> >                  preferred_mode = list_first_entry_or_null(
> >                                  &connector->modes,
> >                                  struct drm_display_mode,
> > --
> > 2.43.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-16 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08  5:17 [PATCH] drm/amd/display: Use separate iterator for preferred mode lookup Yibiao Li
2026-10-16 15:50 ` Alex Hung
2026-10-16 17:37   ` Yibiao Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®