[PATCH v6 04/11] drm/mediatek: mtk_dsi: Cleanup encoder if reset fails during bind

CK Hu (胡俊光) ck.hu at mediatek.com
Wed Aug 26 01:47:26 PDT 2026


On Wed, 2026-07-15 at 15:56 +0200, AngeloGioacchino Del Regno wrote:
> When binding the dsi component, the .bind() callback initializes
> the encoder, and then will optionally trigger resets.
> 
> Should that last operation fail, binding will as well fail but
> the encoder is never removed from the DRM encoder list and if
> the driver gets removed afterwards, this may crash the kernel
> because of an use-after-free condition.
> 
> In order to avoid that, cleanup the encoder upon reset failure.

Reviewed-by: CK Hu <ck.hu at mediatek.com>

> 
> Fixes: 605c83753d97 ("drm/mediatek: mtk_dsi: Reset the dsi0 hardware")
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_dsi.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index 8ab5c3431dbb..e3d7338c35e3 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> @@ -1090,7 +1090,13 @@ static int mtk_dsi_bind(struct device *dev, struct device *master, void *data)
>  	if (ret)
>  		return ret;
>  
> -	return device_reset_optional(dev);
> +	ret = device_reset_optional(dev);
> +	if (ret) {
> +		drm_encoder_cleanup(&dsi->encoder);
> +		return ret;
> +	}
> +
> +	return 0;
>  }
>  
>  static void mtk_dsi_unbind(struct device *dev, struct device *master,



More information about the Linux-mediatek mailing list