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

From: CK Hu (胡俊光)

Date: Wed Aug 26 2026 - 04:49:09 EST


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@xxxxxxxxxxxx>

>
> Fixes: 605c83753d97 ("drm/mediatek: mtk_dsi: Reset the dsi0 hardware")
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>
> ---
> 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,