* [PATCH] drm/mediatek: dp: Disable HPD IRQ before cancelling debounce timer
@ 2026-11-26 3:15 Hank Liou via B4 Relay
2026-11-30 7:48 ` CK Hu (胡俊光)
0 siblings, 1 reply; 2+ messages in thread
From: Hank Liou via B4 Relay @ 2026-11-26 3:15 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, CK Hu, Jitao Shi, dri-devel,
linux-mediatek, linux-kernel, linux-arm-kernel, Hank Liou
From: Hank Liou <hank.liou@mediatek.com>
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@mediatek.com>
---
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);
+ 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,
--
Hank Liou <hank.liou@mediatek.com>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] drm/mediatek: dp: Disable HPD IRQ before cancelling debounce timer
2026-11-26 3:15 [PATCH] drm/mediatek: dp: Disable HPD IRQ before cancelling debounce timer Hank Liou via B4 Relay
@ 2026-11-30 7:48 ` CK Hu (胡俊光)
0 siblings, 0 replies; 2+ messages in thread
From: CK Hu (胡俊光) @ 2026-11-30 7:48 UTC (permalink / raw)
To: p.zabel, chunkuang.hu, Hank Liou (柳瀚揚)
Cc: simona, dri-devel, AngeloGioacchino Del Regno, airlied,
linux-kernel, Jitao Shi (石记涛),
linux-arm-kernel, matthias.bgg, linux-mediatek
On Thu, 2026-11-26 at 11:15 +0800, Hank Liou via B4 Relay wrote:
> From: Hank Liou <hank.liou@mediatek.com>
>
> 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@mediatek.com>
> ---
> 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,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 7:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 3:15 [PATCH] drm/mediatek: dp: Disable HPD IRQ before cancelling debounce timer Hank Liou via B4 Relay
2026-11-30 7:48 ` CK Hu (胡俊光)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®