drm/msm/dpu: avoid uninitialized variable use
PATCH 1/1 drm/msm/dpu: avoid uninitialized variable use
From: Arnd Bergmann <[email protected]>
clang-21 points out a variable that is conditionally initialized but then dereferenced:
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:6: error: variable 'crtc_state' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1138 | if (plane_state->crtc)
| ^~~~~~~~~~~~~~~~~
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1142:58: note: uninitialized use occurs here
1142 | ret = dpu_plane_atomic_check_nosspp(plane, plane_state, crtc_state);
| ^~~~~~~~~~drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:2: note: remove the 'if' if its condition is always true
1138 | if (plane_state->crtc)
| ^~~~~~~~~~~~~~~~~~~~~~
1139 | crtc_state = drm_atomic_get_new_crtc_state(state,
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1132:35: note: initialize the variable 'crtc_state' to silence this warning
1132 | struct drm_crtc_state *crtc_state;
| ^
| = NULLThe bug is real, but the suggestion from clang to set it to NULL is unfortunately just as harmful as dereferencing a NULL pointer is little better than uninitialized data.
Change the function to return an error in this case.
--- drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +3 -3
@@ -1135,10 +1135,10 @@ static int dpu_plane_virtual_atomic_check(struct drm_plane *plane,if (IS_ERR (plane_state))return PTR_ERR (plane_state); -if (plane_state->crtc) - crtc_state =drm_atomic_get_new_crtc_state (state, - plane_state->crtc); +if (!plane_state->crtc) +return -ENXIO ; + crtc_state =drm_atomic_get_new_crtc_state (state, plane_state->crtc); ret =dpu_plane_atomic_check_nosspp (plane, plane_state, crtc_state);if (ret)return ret;
Signature · 1 line
2.39.5
Quoted 20 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
clang-21 points out a variable that is conditionally initialized but then dereferenced:
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:6: error: variable 'crtc_state' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1138 | if (plane_state->crtc)| ^~~~~~~~~~~~~~~~~
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1142:58: note: uninitialized use occurs here
1142 | ret =dpu_plane_atomic_check_nosspp(plane, plane_state, crtc_state);
| ^~~~~~~~~~drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:2: note: remove the 'if' if its condition is always true1138 | if (plane_state->crtc) | ^~~~~~~~~~~~~~~~~~~~~~ 1139 | crtc_state = drm_atomic_get_new_crtc_state(state, drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1132:35: note: initialize the variable 'crtc_state' to silence this warning 1132 | struct drm_crtc_state *crtc_state; | ^ | = NULL
Quoted 3 lines
The bug is real, but the suggestion from clang to set it to NULL is unfortunately just as harmful as dereferencing a NULL pointer is little better than uninitialized data.
Having no plane->crtc is a valid setting and it is handled inside drm_atomic_helper_check_plane_state() by setting plane_state->visible = false and returning early. Setting crtc_state to NULL is a correct fix. Could you please send it?
Quoted 9 lines
Change the function to return an error in this case.
Fixes 774bcfb73176 ("drm/msm/dpu: add support for virtual planes")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
With best wishes Dmitry
Quoted 4 lines · Dmitry Baryshkov
Having no
plane->crtcis a valid setting and it is handled insidedrm_atomic_helper_check_plane_state()by settingplane_state->visible= false and returning early. Settingcrtc_stateto NULL is a correct fix. Could you please send it?
I sent this fix three weeks ago, could this be applied?
https://lore.kernel.org/20250715-drm-msm-fix-const-uninit-warning-v1-1-d6a366fd9a32@kernel.org/
Cheers,
Nathan
Quoted 7 lines · Nathan Chancellor
Quoted 4 lines · Dmitry Baryshkov
Having no
plane->crtcis a valid setting and it is handled insidedrm_atomic_helper_check_plane_state()by settingplane_state->visible= false and returning early. Settingcrtc_stateto NULL is a correct fix. Could you please send it?I sent this fix three weeks ago, could this be applied?
It will be picked up for -rc2 (hopefully)
Quoted 5 lines
https://lore.kernel.org/20250715-drm-msm-fix-const-uninit-warning-v1-1-d6a366fd9a32@kernel.org/
Cheers,
Nathan
Signature · 2 lines
With best wishes Dmitry
Quoted 10 lines · Dmitry Baryshkov
Quoted 7 lines · Nathan Chancellor
Quoted 4 lines · Dmitry Baryshkov
Having no
plane->crtcis a valid setting and it is handled insidedrm_atomic_helper_check_plane_state()by settingplane_state->visible= false and returning early. Settingcrtc_stateto NULL is a correct fix. Could you please send it?I sent this fix three weeks ago, could this be applied?
It will be picked up for -rc2 (hopefully)
Great, thank you! Even if it slips to -rc3, no worries, as long it is in the pipeline to get there.
Cheers,
Nathan
Quoted 11 lines · Dmitry Baryshkov
Quoted 4 lines · Arnd Bergmann
The bug is real, but the suggestion from clang to set it to NULL is unfortunately just as harmful as dereferencing a NULL pointer is little better than uninitialized data.
Having no
plane->crtcis a valid setting and it is handled insidedrm_atomic_helper_check_plane_state()by settingplane_state->visible= false and returning early. Settingcrtc_stateto NULL is a correct fix. Could you please send it?
Ah, I see. I saw the crtc_state dereference in
WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc);
but that is indeed guarded by the plane_state->crtc check.
Nathan's patch is sufficient then.
Arnd