Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/mediatek: dp: Fix potential stale PHY device on probe failure
@ 2026-12-02 11:28 Guangshuo Li
  0 siblings, 0 replies; only message in thread
From: Guangshuo Li @ 2026-12-02 11:28 UTC (permalink / raw)
  To: chunkuang.hu, p.zabel, airlied, simona, matthias.bgg,
	angelogioacchino.delregno
  Cc: ck.hu, amergnat, dri-devel, linux-mediatek, linux-kernel,
	linux-arm-kernel

The DP PHY child keeps a pointer to the parent regmap. A later DP probe
failure releases that regmap but leaves the child registered, allowing
its PHY operations to access freed storage.

Manage child removal with the parent so it also runs on probe failure,
before the parent regmap is released.

This issue was found by our static analysis tool under development.

Fixes: caf2ae486742 ("drm/mediatek: dp: Add support for embedded DisplayPort aux-bus")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/gpu/drm/mediatek/mtk_dp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index 974c4fff6fd3..b3c8b1088c47 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -2688,6 +2688,11 @@ static int mtk_dp_register_audio_driver(struct device *dev)
 	return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev);
 }
 
+static void mtk_dp_unregister_phy(void *data)
+{
+	platform_device_unregister(data);
+}
+
 static int mtk_dp_register_phy(struct mtk_dp *mtk_dp)
 {
 	struct device *dev = mtk_dp->dev;
@@ -2708,7 +2713,7 @@ static int mtk_dp_register_phy(struct mtk_dp *mtk_dp)
 		return dev_err_probe(dev, PTR_ERR(mtk_dp->phy), "Failed to get phy\n");
 	}
 
-	return 0;
+	return devm_add_action_or_reset(dev, mtk_dp_unregister_phy, mtk_dp->phy_dev);
 }
 
 static int mtk_dp_edp_link_panel(struct drm_dp_aux *mtk_aux)
@@ -2869,7 +2874,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);
 }

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 11:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:28 [PATCH] drm/mediatek: dp: Fix potential stale PHY device on probe failure Guangshuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox