dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 04/12] drm/mediatek: mtk_dp: Fix hdmi codec and phy driver unregistration
Date: Thu, 09 Jul 2026 11:48:59 +0000	[thread overview]
Message-ID: <20260709114900.41B611F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709113148.49090-5-angelogioacchino.delregno@collabora.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The hardware interrupt is not disabled during driver unbind (`mtk_dp_remove`), allowing the IRQ handler and thread to execute while resources are being destroyed, leading to use-after-free, timer re-arming, and bus errors.
- [High] The ALSA `get_eld` callback can dereference a NULL `mtk_dp->conn` if called between a hotplug event and a DRM modeset.
--

--- Patch [4]: [PATCH v4 04/12] drm/mediatek: mtk_dp: Fix hdmi codec and phy driver unregistration ---
commit 6ce33bac50c12bbd077cc2e659b77509b20cd720
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Subject: drm/mediatek: mtk_dp: Fix hdmi codec and phy driver unregistration

This commit converts the unregistration of the HDMI Codec and DisplayPort PHY
platform devices to use devm actions. This ensures they are properly cleaned
up even during probe deferrals or failures.

> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 0d0507890d993..8399a6b411689 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
[ ... ]
> @@ -2680,18 +2687,28 @@ static int mtk_dp_register_audio_driver(struct device *dev)
>  		.data = mtk_dp,
>  		.no_capture_mute = 1,
>  	};
> +	int ret;
>  
>  	mtk_dp->audio_pdev = platform_device_register_data(dev,
>  							   HDMI_CODEC_DRV_NAME,
>  							   PLATFORM_DEVID_AUTO,
>  							   &codec_data,
>  							   sizeof(codec_data));

[Severity: High]
This is a pre-existing issue, but does the ALSA get_eld callback have a
potential NULL pointer dereference race with hotplug events?

When a display is plugged in, mtk_dp_hpd_event_thread() unconditionally sets
the enabled flag before the DRM core populates mtk_dp->conn during a modeset:

mtk_dp_hpd_event_thread()
    ...
    mtk_dp->enabled = true;

If userspace or the sound subsystem queries the ELD via mtk_dp_audio_get_eld()
in the window between the hotplug event and the DRM modeset, it seems we
dereference mtk_dp->conn without checking if it is NULL:

mtk_dp_audio_get_eld()
    if (mtk_dp->enabled)
        memcpy(buf, mtk_dp->conn->eld, len);

Could this lead to a crash if a local user probes ALSA mixers before the
modeset completes?

[ ... ]
> @@ -2870,9 +2890,6 @@ static void mtk_dp_remove(struct platform_device *pdev)
>  	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);
>  }

[Severity: High]
This isn't a bug introduced by this patch, but since we are modifying driver
removal, is there a risk of the hardware interrupt firing during or after
mtk_dp_remove()?

The hardware interrupt is managed by devres and remains active until after
mtk_dp_remove() returns. Since pm_runtime_disable() is called here, the
device power domain might be turned off.

If a hotplug interrupt fires during this window, mtk_dp_hpd_event() will
attempt to read hardware registers:

mtk_dp_hpd_event()
    u32 irq_status = mtk_dp_swirq_get_clear(mtk_dp) |
                     mtk_dp_hwirq_get_clear(mtk_dp);

Could this cause a bus error or crash if the power domain is already off?

Furthermore, if the interrupt handler schedules the IRQ thread,
mtk_dp_hpd_event_thread() could re-arm the debounce timer or attempt to
access the PHY during training after it has been unregistered by devres,
leading to a use-after-free:

mtk_dp_hpd_event_thread()
    /* Training */
    ret = mtk_dp_training(mtk_dp);

Should the IRQ be explicitly disabled in mtk_dp_remove() before deleting
the timers and disabling pm runtime?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709113148.49090-1-angelogioacchino.delregno@collabora.com?part=4

  reply	other threads:[~2026-07-09 11:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 11:31 [PATCH v4 00/12] drm: MediaTek DisplayPort cleanups and MT8196 eDP AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 01/12] dt-bindings: display: mediatek: dp: Deprecate nvmem efuse data AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 02/12] dt-bindings: display: mediatek: dp: Add compatible for MT8196 eDP AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 03/12] drm/mediatek: mtk_dp: Call pm_runtime_put_sync() in removal path AngeloGioacchino Del Regno
2026-07-09 11:42   ` sashiko-bot
2026-07-09 11:31 ` [PATCH v4 04/12] drm/mediatek: mtk_dp: Fix hdmi codec and phy driver unregistration AngeloGioacchino Del Regno
2026-07-09 11:48   ` sashiko-bot [this message]
2026-07-09 11:31 ` [PATCH v4 05/12] drm/mediatek: mtk_dp: Clarify SMC eDP/DP video unmute commands AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 06/12] drm/mediatek: mtk_dp: Rework register offsets for proper PHY usage AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 07/12] drm/mediatek: mtk_dp: Use PHY API for PHY power sequences AngeloGioacchino Del Regno
2026-07-09 11:53   ` sashiko-bot
2026-07-09 11:31 ` [PATCH v4 08/12] drm/mediatek: mtk_dp: Add support for PHY from devicetree AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 09/12] drm/mediatek: mtk_dp: Move max link rate to SoC specific data AngeloGioacchino Del Regno
2026-07-09 11:53   ` sashiko-bot
2026-07-09 11:31 ` [PATCH v4 10/12] drm/mediatek: mtk_dp: Add support for HotPlug Detection in DP AUX AngeloGioacchino Del Regno
2026-07-09 12:00   ` sashiko-bot
2026-07-09 12:05     ` AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 11/12] drm/mediatek: mtk_dp: Add support for eDP1.5 IPs and MT8196 SoC AngeloGioacchino Del Regno
2026-07-09 12:11   ` sashiko-bot
2026-07-09 12:17     ` AngeloGioacchino Del Regno
2026-07-09 11:31 ` [PATCH v4 12/12] drm/mediatek: mtk_dp: Clarify XTAL freq and Debounce registers AngeloGioacchino Del Regno
2026-07-09 11:57   ` sashiko-bot

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=20260709114900.41B611F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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