Re: [PATCH] drm/mediatek: dp: Disable HPD IRQ before cancelling debounce timer

From: CK Hu (胡俊光)

Date: Mon Nov 30 2026 - 02:49:13 EST


On Thu, 2026-11-26 at 11:15 +0800, Hank Liou via B4 Relay wrote:
> From: Hank Liou <hank.liou@xxxxxxxxxxxx>
>
> mtk_dp_remove() cancels debounce_timer with timer_delete_sync(), but the
> HPD interrupt that re-arms it from mtk_dp_hpd_event_thread() is
> requested with devm_request_threaded_irq() and stays enabled until
> devres runs after .remove returns. An HPD falling edge between the
> timer cancellation and the IRQ release re-arms the timer, which can
> then expire after the driver has been unbound, when the struct mtk_dp
> that embeds it may already be freed.
>
> Disable the IRQ first, which also waits for a running hard or threaded
> handler, then cancel the timer. Do this before the runtime PM calls so
> the interrupt is quiesced while the hardware is still powered.
>
> Fixes: 4652e95e7ea6 ("drm/mediatek: dp: Add hpd debounce")
> Signed-off-by: Hank Liou <hank.liou@xxxxxxxxxxxx>
> ---
> Fix the ordering of the HPD IRQ disable and the debounce timer cancellation in mtk_dp_remove().
> ---
> drivers/gpu/drm/mediatek/mtk_dp.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 974c4fff6..7a5e380fd 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -2865,10 +2865,13 @@ static void mtk_dp_remove(struct platform_device *pdev)
> {
> struct mtk_dp *mtk_dp = platform_get_drvdata(pdev);
>
> + if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) {
> + disable_irq(mtk_dp->irq);

In normal flow, detach function would disable irq.
The only case which detach does not happen but remove happen is removing mtk_dp.ko before removing mediatek-drm.ko.
There are still many problem if that case happen.
So the simple way to prevent other bugs in that case, add device link between mtk dp device and mediatek drm device
to make sure detach() would execute before remove().

This is a sample code:

static int mtk_dp_bridge_attach(...)
{
...
if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) {
irq_clear_status_flags(mtk_dp->irq, IRQ_NOAUTOEN);
enable_irq(mtk_dp->irq);
mtk_dp_hwirq_enable(mtk_dp, true);
}

/*
* The DRM device uses this bridge until drm_encoder_cleanup() calls
* .detach. Make it a consumer so it is always unbound before us.
*/
if (!device_link_add(bridge->dev->dev, mtk_dp->dev,
DL_FLAG_AUTOREMOVE_CONSUMER)) {
ret = -EINVAL;
goto err_link;
}
return 0;
...
}

static void mtk_dp_bridge_detach(struct drm_bridge *bridge)
{
if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP) {
mtk_dp_hwirq_enable(mtk_dp, false);
disable_irq(mtk_dp->irq);
timer_delete_sync(&mtk_dp->debounce_timer);
}
mtk_dp->drm_dev = NULL;
mtk_dp_poweroff(mtk_dp);
drm_dp_aux_unregister(&mtk_dp->aux);
}

Regards,
CK

> + timer_delete_sync(&mtk_dp->debounce_timer);
> + }
> +
> pm_runtime_put(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
> - if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP)
> - timer_delete_sync(&mtk_dp->debounce_timer);
> platform_device_unregister(mtk_dp->phy_dev);
> if (mtk_dp->audio_pdev)
> platform_device_unregister(mtk_dp->audio_pdev);
>
> ---
> base-commit: ebb7a8dc1e74c705daffe11c2faf38ec2628f838
> change-id: 20261126-mtk-dp-hpd-irq-5fc8b6f72e6e
>
> Best regards,