Skip to content

Commit

Permalink
drm/mediatek: fix kernel oops if no crtc is found
Browse files Browse the repository at this point in the history
drm_crtc_from_index(0) might return NULL if there are no CRTCs
registered at all which will lead to a kernel oops in
mtk_drm_crtc_dma_dev_get(). Add the missing return value check.

Fixes: 0d9eee9 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")
Signed-off-by: Michael Walle <[email protected]>
Reviewed-by: Nícolas F. R. A. Prado <[email protected]>
Tested-by: Nícolas F. R. A. Prado <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
Tested-by: Eugen Hristev <[email protected]>
Reviewed-by: Eugen Hristev <[email protected]>
Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/
Signed-off-by: Chun-Kuang Hu <[email protected]>
  • Loading branch information
mwalle authored and Chun-Kuang Hu committed Nov 23, 2023
1 parent 9aa6a66 commit 4662817
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/gpu/drm/mediatek/mtk_drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
struct mtk_drm_private *private = drm->dev_private;
struct mtk_drm_private *priv_n;
struct device *dma_dev = NULL;
struct drm_crtc *crtc;
int ret, i, j;

if (drm_firmware_drivers_only())
Expand Down Expand Up @@ -519,7 +520,9 @@ static int mtk_drm_kms_init(struct drm_device *drm)
}

/* Use OVL device for all DMA memory allocations */
dma_dev = mtk_drm_crtc_dma_dev_get(drm_crtc_from_index(drm, 0));
crtc = drm_crtc_from_index(drm, 0);
if (crtc)
dma_dev = mtk_drm_crtc_dma_dev_get(crtc);
if (!dma_dev) {
ret = -ENODEV;
dev_err(drm->dev, "Need at least one OVL device\n");
Expand Down

0 comments on commit 4662817

Please sign in to comment.