mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "CK Hu (胡俊光)" <ck.hu@mediatek.com>
To: "p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>,
	"Hank Liou (柳瀚揚)" <Hank.Liou@mediatek.com>
Cc: "simona@ffwll.ch" <simona@ffwll.ch>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Jitao Shi (石记涛)" <jitao.shi@mediatek.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>
Subject: Re: [PATCH] drm/mediatek: dp: Disable HPD IRQ before cancelling debounce timer
Date: Mon, 30 Nov 2026 07:48:58 +0000	[thread overview]
Message-ID: <aa3bda8e03ca34d37f7677b0786623da17d1de1b.camel@mediatek.com> (raw)
In-Reply-To: <20261126-mtk-dp-hpd-irq-v1-1-0b8663980732@mediatek.com>

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,


      reply	other threads:[~2026-11-30  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  3:15 Hank Liou via B4 Relay
2026-11-30  7:48 ` CK Hu (胡俊光) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa3bda8e03ca34d37f7677b0786623da17d1de1b.camel@mediatek.com \
    --to=ck.hu@mediatek.com \
    --cc=Hank.Liou@mediatek.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jitao.shi@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®