Reviewed-by: Alex Hung <[email protected]>

On 10/7/26 23:17, Yibiao Li wrote:
[Some people who received this message don't often get email from 
[email protected]. Learn why this is important at 
https://aka.ms/LearnAboutSenderIdentification ]

From: Yibiao Li <[email protected]>

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 <[email protected]>
Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Assisted-by: LLM coccinelle
Signed-off-by: Yibiao Li <[email protected]>
---
  .../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

Reply via email to