Skip to contentSkip to conversation

drm/mediatek: Fix access violation in mtk_drm_crtc_dma_dev_get

PATCH New Stuart Lee 1 participant 1 message Nov 9, 2023 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

Stuart Lee

author
#1 lore raw

PATCH 1/1 drm/mediatek: Fix access violation in mtk_drm_crtc_dma_dev_get

In reply to a message not in the archive

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")
---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +8 -1
index c277b9fae950..047c9a31d306 100644
@@ -921,7 +921,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;
 }
Signature · 1 line
2.18.0