Skip to contentSkip to conversation

drm/crtc: fix uninitialized variable use even harder

PATCH Applied Rob Clark 4 participants 7 messages Feb 12, 2024 – Feb 13, 2024

Subsystems (2)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm/crtc: fix uninitialized variable use even harder

From: Rob Clark <[email protected]>

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Fixes 6e455f5dcdd1 ("drm/crtc: fix uninitialized variable use")

---
I have mixed feelings about DRM_MODESET_LOCK_ALL_BEGIN() (and friends) magic. On one hand it simplifies the deadlock/back dance. OTOH it conceals a nasty sharp edge. Maybe it is better to have the complicated restart path a bit more explicit, like it was originally.

 drivers/gpu/drm/drm_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_crtc.c +1 -0
index cb90e70d85e8..65f9f66933bb 100644
@@ -904,6 +904,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 	connector_set = NULL;
 	fb = NULL;
 	mode = NULL;
+	num_connectors = 0;
 
 	DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
 
Signature · 1 line
2.43.0
author
#1 lore raw
Quoted 6 lines · Rob Clark

From: Rob Clark <[email protected]>

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Quoted 7 lines
Fixes 6e455f5dcdd1 ("drm/crtc: fix uninitialized variable use")

---
I have mixed feelings about DRM_MODESET_LOCK_ALL_BEGIN() (and friends) magic. On one hand it simplifies the deadlock/back dance. OTOH it conceals a nasty sharp edge. Maybe it is better to have the complicated restart path a bit more explicit, like it was originally.

I should also point out, had drm-misc-next been using gitlab MRs and gitlab CI, we would have caught this ;-)

BR,
-R

Quoted 18 lines
 drivers/gpu/drm/drm_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_crtc.c +1 -1
index cb90e70d85e8..65f9f66933bb 100644
@@ -904,6 +904,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
        connector_set = NULL;
        fb = NULL;
        mode = NULL;
+       num_connectors = 0;
 
        DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
 
--

2.43.0

Reviewed-by on v1 1/1
#2 lore raw
In reply to Rob Clark
Quoted 7 lines · Rob Clark

From: Rob Clark <[email protected]>

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Fixes 6e455f5dcdd1 ("drm/crtc: fix uninitialized variable use")
Quoted 9 lines

---
I have mixed feelings about DRM_MODESET_LOCK_ALL_BEGIN() (and friends) magic. On one hand it simplifies the deadlock/back dance. OTOH it conceals a nasty sharp edge. Maybe it is better to have the complicated restart path a bit more explicit, like it was originally.

  drivers/gpu/drm/drm_crtc.c | 1 +
  1 file changed, 1 insertion(+)

Nice catch !!

Reviewed-by on v1 1/1
#3 lore raw
In reply to Rob Clark
Quoted 22 lines · Rob Clark

From: Rob Clark <[email protected]>

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Fixes 6e455f5dcdd1 ("drm/crtc: fix uninitialized variable use")

---
I have mixed feelings about DRM_MODESET_LOCK_ALL_BEGIN() (and friends) magic. On one hand it simplifies the deadlock/back dance. OTOH it conceals a nasty sharp edge. Maybe it is better to have the complicated restart path a bit more explicit, like it was originally.

 drivers/gpu/drm/drm_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_crtc.c +0 -0
index cb90e70d85e8..65f9f66933bb 100644

drivers/gpu/drm/drm_crtc.c int drm_mode_setcrtc(struct drm_device *dev, void *data, · line 907

Quoted 4 lines
drivers/gpu/drm/drm_crtc.c +1 -0
@@ -904,6 +904,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
        connector_set = NULL;
        fb = NULL;
        mode = NULL;
+       num_connectors = 0;

Nit: I think we should move all this next to the DRM_MODESET_LOCK_ALL_BEGIN() and drop initialisation from the prologue of the function, but it's definitely a separate and more intrusive story.

Quoted 1 line
drivers/gpu/drm/drm_crtc.c +0 -0
        DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
Signature · 2 lines
With best wishes
Dmitry
#4 lore raw
Quoted 34 lines · Dmitry Baryshkov
Quoted 22 lines · Rob Clark

From: Rob Clark <[email protected]>

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Fixes 6e455f5dcdd1 ("drm/crtc: fix uninitialized variable use")

---
I have mixed feelings about DRM_MODESET_LOCK_ALL_BEGIN() (and friends) magic. On one hand it simplifies the deadlock/back dance. OTOH it conceals a nasty sharp edge. Maybe it is better to have the complicated restart path a bit more explicit, like it was originally.

 drivers/gpu/drm/drm_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_crtc.c +0 -0
index cb90e70d85e8..65f9f66933bb 100644

drivers/gpu/drm/drm_crtc.c int drm_mode_setcrtc(struct drm_device *dev, void *data, · line 907

Quoted 4 lines
drivers/gpu/drm/drm_crtc.c +1 -0
@@ -904,6 +904,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
        connector_set = NULL;
        fb = NULL;
        mode = NULL;
+       num_connectors = 0;

Nit: I think we should move all this next to the DRM_MODESET_LOCK_ALL_BEGIN() and drop initialisation from the prologue of the function, but it's definitely a separate and more intrusive story.

Quoted 1 line

After running this through CI:

Quoted 6 lines

drivers/gpu/drm/drm_crtc.c int drm_mode_setcrtc(struct drm_device *dev, void *data, · line 909

Quoted 1 line
drivers/gpu/drm/drm_crtc.c +0 -0
        DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);

--
With best wishes
Dmitry

Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 1/1
#5 lore raw
In reply to Rob Clark
Quoted 7 lines · Rob Clark

From: Rob Clark <[email protected]>

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Fixes 6e455f5dcdd1 ("drm/crtc: fix uninitialized variable use")

I guess at least ...

Quoted 5 lines

---
I have mixed feelings about DRM_MODESET_LOCK_ALL_BEGIN() (and friends) magic. On one hand it simplifies the deadlock/back dance. OTOH it conceals a nasty sharp edge. Maybe it is better to have the complicated restart path a bit more explicit, like it was originally.

Alternative would be a very magic for {} macro, but those tend to get easily defeated with goto/break and friends. Maybe it works now that linux/cleanup.h has landed, but I'm not sure it's actually better and not just trading one set of sharp edges for another. Worth a shot in a prototype at least, if someone's bored.

drivers/gpu/drm/drm_crtc.c int drm_mode_setcrtc(struct drm_device *dev, void *data, · line 907

Quoted 13 lines
 drivers/gpu/drm/drm_crtc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_crtc.c +1 -0
index cb90e70d85e8..65f9f66933bb 100644
@@ -904,6 +904,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 	connector_set = NULL;
 	fb = NULL;
 	mode = NULL;
+	num_connectors = 0;

I think it'd be neater to have all these right below the DRM_MODESET_LOCK_A_BEGIN instead of duplicated here and at the beginning of the function. But it's a bit a bikeshed and in some cases (when you use it later on) gcc might get pissed too. So either way:

Cheers, Sima

Quoted 6 lines
drivers/gpu/drm/drm_crtc.c +0 -0
 	DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
 
Signature · 1 line
2.43.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#6 lore raw
In reply to Rob Clark
Quoted 4 lines · Rob Clark

DRM_MODESET_LOCK_ALL_BEGIN() has a hidden trap-door (aka retry loop), which means we can't rely too much on variable initializers.

Applied to drm-misc-fixes, thanks!

[1/1] drm/crtc: fix uninitialized variable use even harder

      commit: b6802b61a9d0e99dcfa6fff7c50db7c48a9623d3

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>