Skip to contentSkip to conversation

drm/bridge: dw-hdmi: Fix next_bridge reference leak in dw_hdmi_parse_dt()

PATCH New Wentao Liang 2 participants 2 messages Sep 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: dw-hdmi: Fix next_bridge reference leak in dw_hdmi_parse_dt()

dw_hdmi_parse_dt() takes a reference to the next bridge in the pipeline with of_drm_find_and_get_bridge() and stores it in hdmi->bridge.next_bridge, but neither the probe error paths nor the driver teardown release it. Drop the reference in the err_res label of dw_hdmi_probe() and in dw_hdmi_remove().

Fixes 4e7fd5aa3f39 ("drm/bridge: dw-hdmi: convert to of_drm_find_and_get_bridge()")
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +2 -0
index 1da12e4616fe..3000572d99fe 100644
@@ -3599,6 +3599,7 @@ struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev,
 	return hdmi;
 
 err_res:
+	drm_bridge_put(hdmi->bridge.next_bridge);
 	i2c_put_adapter(hdmi->ddc);
 
 	return ERR_PTR(ret);
@@ -3608,6 +3609,7 @@ EXPORT_SYMBOL_GPL(dw_hdmi_probe);
 void dw_hdmi_remove(struct dw_hdmi *hdmi)
 {
 	drm_bridge_remove(&hdmi->bridge);
+	drm_bridge_put(hdmi->bridge.next_bridge);
 
 	if (hdmi->audio && !IS_ERR(hdmi->audio))
 		platform_device_unregister(hdmi->audio);
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] drm/bridge: dw-hdmi: bogus fix introduces dead code and double-put risk --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] drm/bridge: dw-hdmi: bogus fix introduces dead code and double-put risk --

commit a2a89ee3551f54a10aa7baa4ebb98caa3f85eb6f
Author: Wentao Liang <[email protected]>

drm/bridge: dw-hdmi: Fix next_bridge reference leak in dw_hdmi_parse_dt()

This commit attempts to fix a claimed reference leak of the next bridge in the pipeline by manually dropping the reference in the probe error path and the remove function.

Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +0 -0
index 937d61c42b58d..a1434beef92ff 100644

[ ... ]

drivers/gpu/drm/bridge/synopsys/dw-hdmi.c struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev, · line 3591

Quoted 5 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +1 -0
@@ -3588,6 +3588,7 @@ struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev,
 	return hdmi;
 
 err_res:
+	drm_bridge_put(hdmi->bridge.next_bridge);

[Severity: Low]
Is this fix addressing a phantom issue? The commit message mentions fixing a leak in dw_hdmi_parse_dt(), but that function appears to have been removed in an earlier refactoring. The bridge lookup now happens dynamically in dw_hdmi_bridge_attach() using a local variable that manages refcounting.

Also, since hdmi->bridge.next_bridge is never actually populated anywhere in dw-hdmi.c (and is initialized to NULL by devm_drm_bridge_alloc), does this simply introduce dead code by calling drm_bridge_put(NULL)?

Furthermore, if the bridge were populated, wouldn't this manual put cause a double-put risk? According to the DRM bridge core lifecycle, next_bridge is automatically put when the bridge's refcount reaches zero and __drm_bridge_free() is invoked during probe failure cleanup.

drivers/gpu/drm/bridge/synopsys/dw-hdmi.c EXPORT_SYMBOL_GPL(dw_hdmi_probe); · line 3601

Quoted 8 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +1 -0
 	i2c_put_adapter(hdmi->ddc);
 
 	return ERR_PTR(ret);
@@ -3597,6 +3598,7 @@ EXPORT_SYMBOL_GPL(dw_hdmi_probe);
 void dw_hdmi_remove(struct dw_hdmi *hdmi)
 {
 	drm_bridge_remove(&hdmi->bridge);
+	drm_bridge_put(hdmi->bridge.next_bridge);

[Severity: Low]
Similar to the err_res path in dw_hdmi_probe(), isn't this manual put both dead code (acting on a NULL pointer) and a violation of the DRM bridge API?

If next_bridge were actually populated, the DRM core would intrinsically execute drm_bridge_put(bridge->next_bridge) during standard teardown when the refcount drops to zero. Calling it manually here risks a double-put during teardown.

Quoted 3 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +0 -0
 	if (hdmi->audio && !IS_ERR(hdmi->audio))
 		platform_device_unregister(hdmi->audio);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1