drm/mediatek: mtk_hdmi: Fix DDC adapter double put in v2
Subsystems (4)
PATCH v3 1/1 drm/mediatek: mtk_hdmi: Fix DDC adapter double put in v2
mtk_hdmi_common_probe() gets the DDC adapter with of_find_i2c_adapter_by_node() and registers a devm action to release the adapter device reference with put_device().
The HDMI v2 remove callback also calls i2c_put_adapter() on the same DDC adapter. This is not paired with of_find_i2c_adapter_by_node(): it drops the adapter device reference before the devm action drops it again, and it also puts a module reference that was never taken.
Remove the extra i2c_put_adapter() call and drop the now-empty HDMI v2 remove callback. The common devm action releases the adapter device reference.
---
v3:
- Add Reviewed-by tag from Johan Hovold.
- No code changes.
v2:
- Drop the empty remove callback, as suggested by Johan Hovold.
- Mention that i2c_put_adapter() also drops a module reference that was never taken.
- Fix the Fixes tag.
- Add Cc stable.
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +0 -8
@@ -1499,13 +1499,6 @@ static int mtk_hdmi_v2_probe(struct platform_device *pdev)return 0 ; } -static void mtk_hdmi_v2_remove (struct platform_device *pdev) -{ -struct mtk_hdmi *hdmi =platform_get_drvdata (pdev); - -i2c_put_adapter (hdmi->ddc_adpt); -} -static const struct of_device_id mtk_drm_hdmi_v2_of_ids[] = { { .compatible ="mediatek,mt8188-hdmi-tx" , .data = &mtk_hdmi_conf_mt8188 }, { .compatible ="mediatek,mt8195-hdmi-tx" , .data = &mtk_hdmi_conf_mt8195 },
@@ -1515,7 +1508,6 @@ MODULE_DEVICE_TABLE(of, mtk_drm_hdmi_v2_of_ids);static struct platform_driver mtk_hdmi_v2_driver = { .probe = mtk_hdmi_v2_probe, - .remove = mtk_hdmi_v2_remove, .driver = { .name ="mediatek-drm-hdmi-v2" , .of_match_table = mtk_drm_hdmi_v2_of_ids,
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Clocks acquired via of_clk_get_by_name() are never released, causing a permanent memory and module reference leak.
- [High] The bridge reference acquired via of_drm_find_and_get_bridge() is leaked on error paths and during driver unbind.
- [High] The driver uses of_find_i2c_adapter_by_node() instead of of_get_i2c_adapter_by_node(), failing to pin the I2C adapter module. --
--- Patch [1]: [PATCH v3] drm/mediatek: mtk_hdmi: Fix DDC adapter double put in v2 --- commit 0f15e03f2f19d66ee64acb93c6d5a19fae97377f
Author: Guangshuo Li <[email protected]>
Subject: drm/mediatek: mtk_hdmi: Fix DDC adapter double put in v2
This commit fixes a double-put issue with the DDC I2C adapter in the HDMI v2 driver. The probe function registers a devm action to release the adapter, but the remove callback also manually dropped the reference. This removes the manual drop and the empty remove callback.
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +0
-0
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c static int mtk_hdmi_v2_probe(struct platform_device *pdev) · line 1508
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +0
-7@@ -1499,13 +1499,6 @@ static int mtk_hdmi_v2_probe(struct platform_device *pdev)return 0 ; } -static void mtk_hdmi_v2_remove (struct platform_device *pdev) -{ -struct mtk_hdmi *hdmi =platform_get_drvdata (pdev); - -i2c_put_adapter (hdmi->ddc_adpt); -} -
[Severity: High]
This isn't a bug introduced by this patch, but while you are cleaning up the I2C adapter references here, the underlying use of of_find_i2c_adapter_by_node() in mtk_hdmi_dt_parse_pdata() might be incorrect:
drivers/gpu/drm/mediatek/mtk_hdmi_common.c:mtk_hdmi_dt_parse_pdata() {
...
hdmi->ddc_adpt = of_find_i2c_adapter_by_node(i2c_np);
...
}It appears of_find_i2c_adapter_by_node() only increments the device reference count, but does not pin the I2C adapter driver module.
Could this allow the adapter module to be unexpectedly unloaded while the HDMI driver is still bound? If drm_edid_read_ddc() later attempts to read the EDID via i2c_transfer(), it might cause a crash by accessing the unloaded module.
Would it be safer to use of_get_i2c_adapter_by_node() to properly pin the module?
[Severity: High]
This is a pre-existing issue, but I noticed there might be a memory and module reference leak during clock initialization.
drivers/gpu/drm/mediatek/mtk_hdmi_common.c:mtk_hdmi_get_all_clk() {
...
hdmi->clk[i] = of_clk_get_by_name(np, clock_names[i]);
...
}The of_clk_get_by_name() function allocates a new struct clk and increments the provider's module reference count, but these clocks don't seem to ever be released with clk_put().
If the probe is later deferred (e.g., returning -EPROBE_DEFER when waiting for the remote bridge or DDC I2C adapter), will all successfully acquired clocks be permanently leaked?
[Severity: High]
This is also a pre-existing issue, but there appears to be a leaked bridge module reference on error paths:
drivers/gpu/drm/mediatek/mtk_hdmi_common.c:mtk_hdmi_dt_parse_pdata() {
...
hdmi->bridge.next_bridge = of_drm_find_and_get_bridge(remote);
...
}This successfully bumps the module reference count of the bridge driver.
However, if the subsequent call to of_find_i2c_adapter_by_node() fails and returns -EPROBE_DEFER, the driver bails out of probe without dropping the bridge reference via drm_bridge_put().
Could this permanently leak the bridge module reference count, preventing the external bridge module from being unloaded?
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +0
-1static const struct of_device_id mtk_drm_hdmi_v2_of_ids[] = { { .compatible ="mediatek,mt8188-hdmi-tx" , .data = &mtk_hdmi_conf_mt8188 }, { .compatible ="mediatek,mt8195-hdmi-tx" , .data = &mtk_hdmi_conf_mt8195 },@@ -1515,7 +1508,6 @@ MODULE_DEVICE_TABLE(of, mtk_drm_hdmi_v2_of_ids);static struct platform_driver mtk_hdmi_v2_driver = { .probe = mtk_hdmi_v2_probe, - .remove = mtk_hdmi_v2_remove, .driver = { .name ="mediatek-drm-hdmi-v2" ,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 13 lines · Guangshuo Li
mtk_hdmi_common_probe()gets the DDC adapter withof_find_i2c_adapter_by_node()and registers a devm action to release the adapter device reference withput_device().The HDMI v2 remove callback also calls
i2c_put_adapter()on the same DDC adapter. This is not paired withof_find_i2c_adapter_by_node(): it drops the adapter device reference before the devm action drops it again, and it also puts a module reference that was never taken.Remove the extra
i2c_put_adapter()call and drop the now-empty HDMI v2 remove callback. The common devm action releases the adapter device reference.
Quoted 8 lines
Fixes 8d0f79886273 ("drm/mediatek: Introduce HDMI/DDC v2 for MT8195/MT8188")Reviewed-by Johan Hovold <[email protected]>Signed-off-by Guangshuo Li <[email protected]>---
v3:
- Add Reviewed-by tag from Johan Hovold.
- No code changes.
No need to resend just to add a tag. It will be added when the patch is applied.
Johan
Quoted 7 lines · Guangshuo Li
External email : Please do not click links or open attachments until you have verified the sender or the content.
mtk_hdmi_common_probe()gets the DDC adapter withof_find_i2c_adapter_by_node()and registers a devm action to release the adapter device reference withput_device().
Quoted 8 lines
The HDMI v2 remove callback also calls
i2c_put_adapter()on the same DDC adapter. This is not paired withof_find_i2c_adapter_by_node(): it drops the adapter device reference before the devm action drops it again, and it also puts a module reference that was never taken.Remove the extra
i2c_put_adapter()call and drop the now-empty HDMI v2 remove callback. The common devm action releases the adapter device reference.
Quoted 7 lines
Fixes 8d0f79886273 ("drm/mediatek: Introduce HDMI/DDC v2 for MT8195/MT8188")Reviewed-by Johan Hovold <[email protected]>Signed-off-by Guangshuo Li <[email protected]>---
Guangshuo Li <[email protected]> 於 2026年7月13日週一 上午11:32寫道:
Quoted 5 lines
mtk_hdmi_common_probe()gets the DDC adapter withof_find_i2c_adapter_by_node()and registers a devm action to release the adapter device reference withput_device().
Quoted 8 lines
The HDMI v2 remove callback also calls
i2c_put_adapter()on the same DDC adapter. This is not paired withof_find_i2c_adapter_by_node(): it drops the adapter device reference before the devm action drops it again, and it also puts a module reference that was never taken.Remove the extra
i2c_put_adapter()call and drop the now-empty HDMI v2 remove callback. The common devm action releases the adapter device reference.
Applied to mediatek-drm-fixes [1], thanks.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-fixes
Regards,
Chun-Kuang.
Quoted 6 lines
Fixes 8d0f79886273 ("drm/mediatek: Introduce HDMI/DDC v2 for MT8195/MT8188")Reviewed-by Johan Hovold <[email protected]>Signed-off-by Guangshuo Li <[email protected]>---