Skip to contentSkip to conversation

gma500: fix an incorrect NULL check on list iterator

PATCH Applied Xiaomeng Tong 2 participants 2 messages Mar 27, 2022 – Mar 29, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gma500: fix an incorrect NULL check on list iterator

The bug is here:

	return crtc;

The list iterator value 'crtc' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found.

To fix the bug, return 'crtc' when found, otherwise return NULL.

Fixes 89c78134cc54d ("gma500: Add Poulsbo support")
---
 drivers/gpu/drm/gma500/psb_intel_display.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/gma500/psb_intel_display.c +4 -3
index d5f95212934e..42d1a733e124 100644
@@ -535,14 +535,15 @@ void psb_intel_crtc_init(struct drm_device *dev, int pipe,
 
 struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
 {
-	struct drm_crtc *crtc = NULL;
+	struct drm_crtc *crtc;
 
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
 		struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
+
 		if (gma_crtc->pipe == pipe)
-			break;
+			return crtc;
 	}
-	return crtc;
+	return NULL;
 }
 
 int gma_connector_clones(struct drm_device *dev, int type_mask)
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Xiaomeng Tong

The bug is here:

        return crtc;

The list iterator value 'crtc' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found.

Quoted 5 lines

To fix the bug, return 'crtc' when found, otherwise return NULL.

Fixes 89c78134cc54d ("gma500: Add Poulsbo support")

Thanks for the patch

Applied to drm-misc-next

-Patrik

Quoted 30 lines
---
 drivers/gpu/drm/gma500/psb_intel_display.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/gma500/psb_intel_display.c +4 -4
index d5f95212934e..42d1a733e124 100644
@@ -535,14 +535,15 @@ void psb_intel_crtc_init(struct drm_device *dev, int pipe,
 
 struct drm_crtc *psb_intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
 {
-       struct drm_crtc *crtc = NULL;
+       struct drm_crtc *crtc;
 
        list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
                struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
+
                if (gma_crtc->pipe == pipe)
-                       break;
+                       return crtc;
        }
-       return crtc;
+       return NULL;
 }
 
 int gma_connector_clones(struct drm_device *dev, int type_mask)
--

2.17.1