On Sat, 2026-10-10 at 20:42 -0400, zoan37 wrote:
> External email : Please do not click links or open attachments until you have 
> verified the sender or the content.
> 
> 
> A CRTC created with connector routes gets one extra ddp_comp[] slot for
> its output component, and ddp_comp_nr counts it, but the slot stays
> NULL until mtk_crtc_update_output() fills it in the first atomic
> enable.
> 
> mtk_crtc_destroy() walks all ddp_comp_nr slots and passes each one to
> mtk_ddp_comp_unregister_vblank_cb(), which dereferences it. Tearing
> down a CRTC that was never enabled therefore dereferences NULL: unbinding
> or removing mediatek-drm while that display path was never used, or
> an error in mtk_drm_kms_init() after the CRTC was created.
> 
> Skip the empty slot. Nothing was registered for it anyway: the routed
> components (DSI, DPI, DP_INTF, ...) have no vblank callback.

Reviewed-by: CK Hu <[email protected]>

> 
> Fixes: 01389b324c97 ("drm/mediatek: Add connector dynamic selection 
> capability")
> Assisted-by: LLM
> Signed-off-by: zoan37 <[email protected]>
> ---
> 
> Notes:
>     Testing: found by reading the code; not reproduced. The same check runs
>     on the MT8189 Chromebook described in patch 1 (boot, HDMI/DP hotplug,
>     suspend/resume), but that does not exercise the destroy path (the
>     driver is built in and was not unbound). Compile-tested (W=1) on
>     next-20261008.
> 
>  drivers/gpu/drm/mediatek/mtk_crtc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c 
> b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index b54f8565d2fa..704931b369b6 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -145,6 +145,10 @@ static void mtk_crtc_destroy(struct drm_crtc *crtc)
>                 struct mtk_ddp_comp *comp;
> 
>                 comp = mtk_crtc->ddp_comp[i];
> +               /* The connector route slot is empty until the first enable */
> +               if (!comp)
> +                       continue;
> +
>                 mtk_ddp_comp_unregister_vblank_cb(comp);
>         }
> 
> --
> 2.43.0
> 

Reply via email to