[PATCH v2 12/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: convert to of_drm_find_and_get_bridge()

Marek Szyprowski m.szyprowski at samsung.com
Fri Jan 9 00:50:09 PST 2026


On 09.01.2026 08:31, Luca Ceresoli wrote:
> 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.
>
> Signed-off-by: Luca Ceresoli <luca.ceresoli at bootlin.com>
Tested-by: Marek Szyprowski <m.szyprowski at samsung.com>
> ---
>
> Changes in v2:
> - updated after "pointer set too late" fix inprevious patch
> - *not* add Acked-by: Maxime as the patch has changed
> ---
>   drivers/gpu/drm/bridge/samsung-dsim.c | 20 +++++++++++++-------
>   include/drm/bridge/samsung-dsim.h     |  1 -
>   2 files changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c
> index afaa63c4d3f7..1d85e706c74b 100644
> --- a/drivers/gpu/drm/bridge/samsung-dsim.c
> +++ b/drivers/gpu/drm/bridge/samsung-dsim.c
> @@ -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 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
>   	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 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
>   	}
>   
>   	// 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 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
>   	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);
>   
> diff --git a/include/drm/bridge/samsung-dsim.h b/include/drm/bridge/samsung-dsim.h
> index 31d7ed589233..03005e474704 100644
> --- a/include/drm/bridge/samsung-dsim.h
> +++ b/include/drm/bridge/samsung-dsim.h
> @@ -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;
>   
>
Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland




More information about the linux-arm-kernel mailing list