Skip to contentSkip to conversation

drm/mediathek: fix kernel oops if no crtc is found

PATCH Superseded Michael Walle 2 participants 5 messages Aug 29, 2023 – Aug 30, 2023

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/mediathek: fix kernel oops if no crtc is found

drm_crtc_from_index(0) might return NULL if there are not 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 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +4 -1
index 93552d76b6e7..2c582498817e 100644
@@ -420,6 +420,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())
@@ -494,7 +495,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");
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 drm/mediatek: dpi/dsi: fix possible_crtcs calculation

mtk_drm_find_possible_crtc_by_comp() assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment in mtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 1 and the third path will be 2.

To fix that, dynamically calculate the IDs by the precence of the paths.

Fixes 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way")
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 41 ++++++++++++++-------
 1 file changed, 27 insertions(+), 14 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +27 -14
index 771f4e173353..f3064bff64e8 100644
@@ -526,21 +526,34 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
 						struct device *dev)
 {
 	struct mtk_drm_private *private = drm->dev_private;
-	unsigned int ret = 0;
-
-	if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path, private->data->main_len,
-				     private->ddp_comp))
-		ret = BIT(0);
-	else if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path,
-					  private->data->ext_len, private->ddp_comp))
-		ret = BIT(1);
-	else if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path,
-					  private->data->third_len, private->ddp_comp))
-		ret = BIT(2);
-	else
-		DRM_INFO("Failed to find comp in ddp table\n");
+	int i = 0;
+
+	if (private->data->main_path) {
+		if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path,
+					     private->data->main_len,
+					     private->ddp_comp))
+			return BIT(i);
+		i++;
+	}
+
+	if (private->data->ext_path) {
+		if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path,
+					     private->data->ext_len,
+					     private->ddp_comp))
+			return BIT(i);
+		i++;
+	}
 
-	return ret;
+	if (private->data->third_path) {
+		if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path,
+					     private->data->third_len,
+					     private->ddp_comp))
+			return BIT(i);
+		i++;
+	}
+
+	DRM_INFO("Failed to find comp in ddp table\n");
+	return 0;
 }
 
 int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation

Quoted 43 lines · Michael Walle

mtk_drm_find_possible_crtc_by_comp() assumed that the main path will always have the CRTC with id 0, the ext id 1 and the third id 2. This is only true if the paths are all available. But paths are optional (see also comment in mtk_drm_kms_init()), e.g. the main path might not be enabled or available at all. Then the CRTC IDs will shift one up, e.g. ext will be 1 and the third path will be 2.

To fix that, dynamically calculate the IDs by the precence of the paths.

Fixes 5aa8e7647676 ("drm/mediatek: dpi/dsi: Change the getting possible_crtc way")
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 41 ++++++++++++++-------
 1 file changed, 27 insertions(+), 14 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +6 -13
index 771f4e173353..f3064bff64e8 100644
@@ -526,21 +526,34 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
 						struct device *dev)
 {
 	struct mtk_drm_private *private = drm->dev_private;
-	unsigned int ret = 0;
-
-	if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path, private->data->main_len,
-				     private->ddp_comp))
-		ret = BIT(0);
-	else if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path,
-					  private->data->ext_len, private->ddp_comp))
-		ret = BIT(1);
-	else if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path,
-					  private->data->third_len, private->ddp_comp))
-		ret = BIT(2);
-	else
-		DRM_INFO("Failed to find comp in ddp table\n");
+	int i = 0;
+
+	if (private->data->main_path) {
+		if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path,
+					     private->data->main_len,
+					     private->ddp_comp))

drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm, · line 544

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +10 -0
+			return BIT(i);
+		i++;
+	}
+
+	if (private->data->ext_path) {
+		if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path,
+					     private->data->ext_len,
+					     private->ddp_comp))
+			return BIT(i);
+		i++;

This won't work. On MT8195 there are two display IPs, vdosys0 and vdosys1, vdosys0 only has the main path while vdosys1 only has the external path. So you need to loop over each one in all_drm_private[j] to get the right crtc ID for MT8195.

Thanks,
Nícolas

#3 lore raw

Re: [PATCH 2/2] drm/mediatek: dpi/dsi: fix possible_crtcs calculation

Quoted 4 lines

This won't work. On MT8195 there are two display IPs, vdosys0 and vdosys1, vdosys0 only has the main path while vdosys1 only has the external path. So you need to loop over each one in all_drm_private[j] to get the right crtc ID for MT8195.

Ahh thanks, got it.

-michael

Reviewed-by Tested-by on v1 1/2
#4 lore raw
In reply to Michael Walle
Quoted 1 line · Michael Walle

drm_crtc_from_index(0) might return NULL if there are not CRTCs

Typo: not -> no

Quoted 5 lines

registered at all which will lead to a kernel oops in mtk_drm_crtc_dma_dev_get(). Add the missing return value check.

Fixes 0d9eee9118b7 ("drm/mediatek: Add drm ovl_adaptor sub driver for MT8195")

There's also a typo in the commit subject: mediathek -> mediatek. But regardless,

(tested that the patch fixes the oops on mt8195-cherry-tomato when no display pipeline is available)

Thanks,
Nícolas