drm/mediatek: Check CRTC state before freeing
Subsystems (3)
PATCH 1/1 drm/mediatek: Check CRTC state before freeing
mtk_crtc_reset() destroys the current CRTC state only when crtc->state is non-NULL, but it always converts crtc->state to struct mtk_crtc_state and passes the result to kfree().
When reset is called without an existing state, container_of(NULL, ...) does not produce NULL. Keep the mtk state free in the same crtc->state guard as the helper state destruction.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/gpu/drm/mediatek/mtk_crtc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/mediatek/mtk_crtc.c +3 -3
@@ -154,10 +154,10 @@ static void mtk_crtc_reset(struct drm_crtc *crtc) {struct mtk_crtc_state *state; -if (crtc->state) +if (crtc->state) {__drm_atomic_helper_crtc_destroy_state (crtc->state); - -kfree (to_mtk_crtc_state (crtc->state)); +kfree (to_mtk_crtc_state (crtc->state)); + } crtc->state =NULL ; state =kzalloc_obj (*state);
Signature · 1 line
2.51.0
Quoted 7 lines · Ruoyu Wang
External email : Please do not click links or open attachments until you have verified the sender or the content.
mtk_crtc_reset()destroys the current CRTC state only whencrtc->stateis non-NULL, but it always convertscrtc->stateto structmtk_crtc_stateand passes the result tokfree().
Quoted 6 lines
When reset is called without an existing state,
container_of(NULL, ...)does not produce NULL. Keep the mtk state free in the samecrtc->stateguard as the helper state destruction.This issue was found by a static analysis checker and confirmed by manual source review.
Quoted 29 lines
Fixes 2d267b81898e ("drm/mtk: Use __drm_atomic_helper_crtc_reset")Signed-off-by Ruoyu Wang <[email protected]>--- drivers/gpu/drm/mediatek/mtk_crtc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/mediatek/mtk_crtc.c +3
-4@@ -154,10 +154,10 @@ static void mtk_crtc_reset(struct drm_crtc *crtc) {struct mtk_crtc_state *state; -if (crtc->state) +if (crtc->state) {__drm_atomic_helper_crtc_destroy_state (crtc->state); - -kfree (to_mtk_crtc_state (crtc->state)); +kfree (to_mtk_crtc_state (crtc->state)); + } crtc->state =NULL ; state =kzalloc_obj (*state); --2.51.0
Ruoyu Wang <[email protected]> 於 2026年7月7日週二 下午3:05寫道:
Quoted 11 lines
mtk_crtc_reset()destroys the current CRTC state only whencrtc->stateis non-NULL, but it always convertscrtc->stateto structmtk_crtc_stateand passes the result tokfree().When reset is called without an existing state,
container_of(NULL, ...)does not produce NULL. Keep the mtk state free in the samecrtc->stateguard as the helper state destruction.This issue was found by a static analysis checker and confirmed by manual source review.
Applied to mediatek-drm-fixes [1], thanks.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-fixes
Regards,
Chun-Kuang.
Quoted 28 lines
Fixes 2d267b81898e ("drm/mtk: Use __drm_atomic_helper_crtc_reset")Signed-off-by Ruoyu Wang <[email protected]>--- drivers/gpu/drm/mediatek/mtk_crtc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/mediatek/mtk_crtc.c +3
-4@@ -154,10 +154,10 @@ static void mtk_crtc_reset(struct drm_crtc *crtc) {struct mtk_crtc_state *state; -if (crtc->state) +if (crtc->state) {__drm_atomic_helper_crtc_destroy_state (crtc->state); - -kfree (to_mtk_crtc_state (crtc->state)); +kfree (to_mtk_crtc_state (crtc->state)); + } crtc->state =NULL ; state =kzalloc_obj (*state); --2.51.0