]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/bridge: samsung-dsim: samsung_dsim_host_attach: convert to of_drm_find_and_get_br...
authorLuca Ceresoli <luca.ceresoli@bootlin.com>
Fri, 9 Jan 2026 07:31:43 +0000 (08:31 +0100)
committerLuca Ceresoli <luca.ceresoli@bootlin.com>
Tue, 20 Jan 2026 13:53:46 +0000 (14:53 +0100)
of_drm_find_bridge() is deprecated. Move to its replacement
of_drm_find_and_get_bridge() which gets a bridge reference, and ensure it
is put when done. Also switch to the drm_bridge::next_bridge pointer.

This needs to handle both cases: when of_drm_find_panel() succeeds and when
it fails.

In the 'else' case (i.e. when of_drm_find_panel() fails), just switch to
of_drm_find_and_get_bridge() to ensure the bridge is not freed while in use
in the function tail, when it is stored in dsi->bridge.next_bridge.

In the 'then' case (i.e. when of_drm_find_panel() succeeds),
devm_drm_panel_bridge_add() already increments the refcount using devres
which ties the bridge allocation lifetime to the device lifetime, so we
would not need to do anything. However to have the same behaviour in both
branches take an additional reference here, so that the bridge needs to be
put whichever branch is taken without more complicated logic. Ensure to
clear the bridge pointer however, to avoid calling drm_bridge_put() on an
ERR_PTR.

Acked-by: Maxime Ripard <mripard@kernel.org>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://patch.msgid.link/20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-12-8bad3ef90b9f@bootlin.com
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
drivers/gpu/drm/bridge/samsung-dsim.c
include/drm/bridge/samsung-dsim.h

index afaa63c4d3f730a829aeb78da90b7ed5026b4f2e..1d85e706c74b9ac3e3b8b5f8d27d9c0895f31860 100644 (file)
@@ -1828,7 +1828,7 @@ static int samsung_dsim_attach(struct drm_bridge *bridge,
 {
        struct samsung_dsim *dsi = bridge_to_dsi(bridge);
 
-       return drm_bridge_attach(encoder, dsi->out_bridge, bridge,
+       return drm_bridge_attach(encoder, dsi->bridge.next_bridge, bridge,
                                 flags);
 }
 
@@ -1886,7 +1886,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
 {
        struct samsung_dsim *dsi = host_to_dsi(host);
        const struct samsung_dsim_plat_data *pdata = dsi->plat_data;
-       struct drm_bridge *next_bridge;
+       struct drm_bridge *next_bridge __free(drm_bridge_put) = NULL;
        struct device *dev = dsi->dev;
        struct device_node *np = dev->of_node;
        struct device_node *remote;
@@ -1926,10 +1926,14 @@ of_find_panel_or_bridge:
        panel = of_drm_find_panel(remote);
        if (!IS_ERR(panel)) {
                next_bridge = devm_drm_panel_bridge_add(dev, panel);
-               if (IS_ERR(next_bridge))
+               if (IS_ERR(next_bridge)) {
                        ret = PTR_ERR(next_bridge);
+                       next_bridge = NULL; // Inhibit the cleanup action on an ERR_PTR
+               } else {
+                       drm_bridge_get(next_bridge);
+               }
        } else {
-               next_bridge = of_drm_find_bridge(remote);
+               next_bridge = of_drm_find_and_get_bridge(remote);
                if (!next_bridge)
                        ret = -EINVAL;
        }
@@ -1961,7 +1965,7 @@ of_find_panel_or_bridge:
        }
 
        // The next bridge can be used by host_ops->attach
-       dsi->out_bridge = next_bridge;
+       dsi->bridge.next_bridge = drm_bridge_get(next_bridge);
 
        if (pdata->host_ops && pdata->host_ops->attach) {
                ret = pdata->host_ops->attach(dsi, device);
@@ -1976,7 +1980,8 @@ of_find_panel_or_bridge:
        return 0;
 
 err_release_next_bridge:
-       dsi->out_bridge = NULL;
+       drm_bridge_put(dsi->bridge.next_bridge);
+       dsi->bridge.next_bridge = NULL;
        return ret;
 }
 
@@ -1997,7 +2002,8 @@ static int samsung_dsim_host_detach(struct mipi_dsi_host *host,
        if (pdata->host_ops && pdata->host_ops->detach)
                pdata->host_ops->detach(dsi, device);
 
-       dsi->out_bridge = NULL;
+       drm_bridge_put(dsi->bridge.next_bridge);
+       dsi->bridge.next_bridge = NULL;
 
        samsung_dsim_unregister_te_irq(dsi);
 
index 31d7ed589233ce560767afa1877f4cc885bf41f3..03005e474704b4e85520b148af92d2343c82994c 100644 (file)
@@ -100,7 +100,6 @@ struct samsung_dsim_plat_data {
 struct samsung_dsim {
        struct mipi_dsi_host dsi_host;
        struct drm_bridge bridge;
-       struct drm_bridge *out_bridge;
        struct device *dev;
        struct drm_display_mode mode;