Skip to content

Commit 4018651

Browse files
Dan CarpenterChun-Kuang Hu
authored andcommitted
drm/mediatek: Fix potential NULL dereference in mtk_crtc_destroy()
In mtk_crtc_create(), if the call to mbox_request_channel() fails then we set the "mtk_crtc->cmdq_client.chan" pointer to NULL. In that situation, we do not call cmdq_pkt_create(). During the cleanup, we need to check if the "mtk_crtc->cmdq_client.chan" is NULL first before calling cmdq_pkt_destroy(). Calling cmdq_pkt_destroy() is unnecessary if we didn't call cmdq_pkt_create() and it will result in a NULL pointer dereference. Fixes: 7627122 ("drm/mediatek: Add cmdq_handle in mtk_crtc") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: CK Hu <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 3ded11b commit 4018651

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/gpu/drm/mediatek/mtk_crtc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ static void mtk_crtc_destroy(struct drm_crtc *crtc)
127127

128128
mtk_mutex_put(mtk_crtc->mutex);
129129
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
130-
cmdq_pkt_destroy(&mtk_crtc->cmdq_client, &mtk_crtc->cmdq_handle);
131-
132130
if (mtk_crtc->cmdq_client.chan) {
131+
cmdq_pkt_destroy(&mtk_crtc->cmdq_client, &mtk_crtc->cmdq_handle);
133132
mbox_free_channel(mtk_crtc->cmdq_client.chan);
134133
mtk_crtc->cmdq_client.chan = NULL;
135134
}

0 commit comments

Comments
 (0)