]> www.infradead.org Git - linux.git/commitdiff
drm/mediatek: Fix potential NULL dereference in mtk_crtc_destroy()
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 12 Sep 2024 08:44:59 +0000 (11:44 +0300)
committerChun-Kuang Hu <chunkuang.hu@kernel.org>
Wed, 23 Oct 2024 14:09:13 +0000 (14:09 +0000)
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: 7627122fd1c0 ("drm/mediatek: Add cmdq_handle in mtk_crtc")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: CK Hu <ck.hu@mediatek.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/cc537bd6-837f-4c85-a37b-1a007e268310@stanley.mountain/
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
drivers/gpu/drm/mediatek/mtk_crtc.c

index b65f196f201547068b725ed60696288add6f904a..eb0e1233ad0435a372fffce25c1c365fec6f211d 100644 (file)
@@ -127,9 +127,8 @@ static void mtk_crtc_destroy(struct drm_crtc *crtc)
 
        mtk_mutex_put(mtk_crtc->mutex);
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
-       cmdq_pkt_destroy(&mtk_crtc->cmdq_client, &mtk_crtc->cmdq_handle);
-
        if (mtk_crtc->cmdq_client.chan) {
+               cmdq_pkt_destroy(&mtk_crtc->cmdq_client, &mtk_crtc->cmdq_handle);
                mbox_free_channel(mtk_crtc->cmdq_client.chan);
                mtk_crtc->cmdq_client.chan = NULL;
        }