[PATCH v2] drm/sti: hdmi: simplify probe with devm DDC and bridge

From: Osama Abdelkader

Date: Tue Apr 14 2026 - 14:17:47 EST


Use devm_add_action_or_reset() to release the DDC I2C adapter from
of_get_i2c_adapter_by_node(), eliminating the release_adapter goto path.

Switch to devm_drm_bridge_add() so the bridge is released on probe failure
without manual drm_bridge_remove() in remove().

v2: devm_add_action_or_reset for DDC + devm_drm_bridge_add (reviewer)

Signed-off-by: Osama Abdelkader <osama.abdelkader@xxxxxxxxx>
---
drivers/gpu/drm/sti/sti_hdmi.c | 48 ++++++++++++++--------------------
1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c
index 839c80a7d954..19beaede8501 100644
--- a/drivers/gpu/drm/sti/sti_hdmi.c
+++ b/drivers/gpu/drm/sti/sti_hdmi.c
@@ -1373,6 +1373,11 @@ static const struct of_device_id hdmi_of_match[] = {
};
MODULE_DEVICE_TABLE(of, hdmi_of_match);

+static void sti_hdmi_i2c_put(void *ptr)
+{
+ i2c_put_adapter(ptr);
+}
+
static int sti_hdmi_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -1393,14 +1398,15 @@ static int sti_hdmi_probe(struct platform_device *pdev)
of_node_put(ddc);
if (!hdmi->ddc_adapt)
return -EPROBE_DEFER;
+ ret = devm_add_action_or_reset(dev, sti_hdmi_i2c_put, hdmi->ddc_adapt);
+ if (ret)
+ return ret;
}

hdmi->dev = pdev->dev;
hdmi->regs = devm_platform_ioremap_resource_byname(pdev, "hdmi-reg");
- if (IS_ERR(hdmi->regs)) {
- ret = PTR_ERR(hdmi->regs);
- goto release_adapter;
- }
+ if (IS_ERR(hdmi->regs))
+ return PTR_ERR(hdmi->regs);

hdmi->phy_ops = (struct hdmi_phy_ops *)
of_match_node(hdmi_of_match, np)->data;
@@ -1409,29 +1415,25 @@ static int sti_hdmi_probe(struct platform_device *pdev)
hdmi->clk_pix = devm_clk_get(dev, "pix");
if (IS_ERR(hdmi->clk_pix)) {
DRM_ERROR("Cannot get hdmi_pix clock\n");
- ret = PTR_ERR(hdmi->clk_pix);
- goto release_adapter;
+ return PTR_ERR(hdmi->clk_pix);
}

hdmi->clk_tmds = devm_clk_get(dev, "tmds");
if (IS_ERR(hdmi->clk_tmds)) {
DRM_ERROR("Cannot get hdmi_tmds clock\n");
- ret = PTR_ERR(hdmi->clk_tmds);
- goto release_adapter;
+ return PTR_ERR(hdmi->clk_tmds);
}

hdmi->clk_phy = devm_clk_get(dev, "phy");
if (IS_ERR(hdmi->clk_phy)) {
DRM_ERROR("Cannot get hdmi_phy clock\n");
- ret = PTR_ERR(hdmi->clk_phy);
- goto release_adapter;
+ return PTR_ERR(hdmi->clk_phy);
}

hdmi->clk_audio = devm_clk_get(dev, "audio");
if (IS_ERR(hdmi->clk_audio)) {
DRM_ERROR("Cannot get hdmi_audio clock\n");
- ret = PTR_ERR(hdmi->clk_audio);
- goto release_adapter;
+ return PTR_ERR(hdmi->clk_audio);
}

hdmi->hpd = readl(hdmi->regs + HDMI_STA) & HDMI_STA_HOT_PLUG;
@@ -1441,15 +1443,14 @@ static int sti_hdmi_probe(struct platform_device *pdev)
hdmi->irq = platform_get_irq_byname(pdev, "irq");
if (hdmi->irq < 0) {
DRM_ERROR("Cannot get HDMI irq\n");
- ret = hdmi->irq;
- goto release_adapter;
+ return hdmi->irq;
}

ret = devm_request_threaded_irq(dev, hdmi->irq, hdmi_irq,
- hdmi_irq_thread, IRQF_ONESHOT, dev_name(dev), hdmi);
+ hdmi_irq_thread, IRQF_ONESHOT, dev_name(dev), hdmi);
if (ret) {
DRM_ERROR("Failed to register HDMI interrupt\n");
- goto release_adapter;
+ return ret;
}

hdmi->reset = devm_reset_control_get(dev, "hdmi");
@@ -1459,29 +1460,20 @@ static int sti_hdmi_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, hdmi);

- drm_bridge_add(&hdmi->bridge);
- ret = component_add(&pdev->dev, &sti_hdmi_ops);
+ ret = devm_drm_bridge_add(dev, &hdmi->bridge);
if (ret)
- goto remove_bridge;
- return 0;
-
- remove_bridge:
- drm_bridge_remove(&hdmi->bridge);
- release_adapter:
- i2c_put_adapter(hdmi->ddc_adapt);
+ return ret;

- return ret;
+ return component_add(&pdev->dev, &sti_hdmi_ops);
}

static void sti_hdmi_remove(struct platform_device *pdev)
{
struct sti_hdmi *hdmi = dev_get_drvdata(&pdev->dev);

- i2c_put_adapter(hdmi->ddc_adapt);
if (hdmi->audio_pdev)
platform_device_unregister(hdmi->audio_pdev);
component_del(&pdev->dev, &sti_hdmi_ops);
- drm_bridge_remove(&hdmi->bridge);
}

struct platform_driver sti_hdmi_driver = {
--
2.43.0