drm/mediatek: Fix access violation in mtk_drm_crtc_dma_dev_get
authorStuart Lee <stuart.lee@mediatek.com>
Fri, 10 Nov 2023 01:29:14 +0000 (09:29 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Dec 2023 16:02:02 +0000 (17:02 +0100)
commit b6961d187fcd138981b8707dac87b9fcdbfe75d1 upstream.

Add error handling to check NULL input in
mtk_drm_crtc_dma_dev_get function.

While display path is not configured correctly, none of crtc is
established. So the caller of mtk_drm_crtc_dma_dev_get may pass
input parameter *crtc as NULL, Which may cause coredump when
we try to get the container of NULL pointer.

Fixes: cb1d6bcca542 ("drm/mediatek: Add dma dev get function")
Signed-off-by: Stuart Lee <stuart.lee@mediatek.com>
Cc: stable@vger.kernel.org
Reviewed-by: AngeloGioacchino DEl Regno <angelogioacchino.delregno@collabora.com>
Tested-by: Macpaul Lin <macpaul.lin@mediatek.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/20231110012914.14884-2-stuart.lee@mediatek.com/
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/mediatek/mtk_drm_crtc.c

index a033da279a94322253ac84be18b6670f3decea3b..80e34b39a6b117f89274e07c8efab5b3c8653c29 100644 (file)
@@ -885,7 +885,14 @@ static int mtk_drm_crtc_init_comp_planes(struct drm_device *drm_dev,
 
 struct device *mtk_drm_crtc_dma_dev_get(struct drm_crtc *crtc)
 {
-       struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
+       struct mtk_drm_crtc *mtk_crtc = NULL;
+
+       if (!crtc)
+               return NULL;
+
+       mtk_crtc = to_mtk_crtc(crtc);
+       if (!mtk_crtc)
+               return NULL;
 
        return mtk_crtc->dma_dev;
 }