From nobody Mon Feb 9 23:39:52 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 899472F12CE for ; Fri, 9 Jan 2026 07:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767943955; cv=none; b=N9n6/2ab5XbFFMS5IDUtdsJH16/8rkiM9StomcMZLT2125LgjlB6/OSr4r1/JYsWIr/+KtNTmL4h8NsPcMzkStQp6oXe75jQFHnuAMDOgPx8PstICgIBaMwE3p0tbVXvRRuLnkPouy+5NpVk14qjIueRbQznrMR3XK/WazA8N/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767943955; c=relaxed/simple; bh=XzkXbCn59QgP9B7qVBSs5EAoHavS4pqXomKdIU7YJrs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=scI4LDnYeMGAoXQ1Fm1zmMMoss+8zH6eeRLanVdIFvetw9z1Pym5OSEdPlw1vIEAIEJGcS3u0mg2K378JewtIlu2jE9YYmrBWItLwq33DNY8p3MHYShSQGbsFwq5x/Hs6aphLFi9wkZPBAXuDKsQPRSmhHKTzCRx7uW+nlQTpPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=s5o6j5fP; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="s5o6j5fP" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 58CE91A272E; Fri, 9 Jan 2026 07:32:32 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2D19360734; Fri, 9 Jan 2026 07:32:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C1FEC103C8824; Fri, 9 Jan 2026 08:32:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1767943951; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=d9BhD/PZC1kxqwJeXLHP33WT7i5IxLGIjFxALfOr/gE=; b=s5o6j5fP4T/foYWtW4Uw4m4njZIpEH0ozWBO/b2efjL9bvHjFDDIctze0qRdssa1U0UTYs sZpGlMgEYhfruFllK8zx6bwqdNyJXgRoTiomC7S2DrfHeZROxJA6aMCgT/SfnZZKmebSm8 28hJ4ZLbka/uWjPOWcj5PHBaU0HE80z63rCEYmP23oVnAvwv3vArpXoU4axwp9wPlshlaZ jA2qcxCwlkcYACxsSeyFr4WPxkWmSD3Z4S69FkLVgKnCOV8OkPOhgaCNXsGVmOr5NroYUJ izCcPJkGm35gjctuq3qUhDh5toStD0hDjW9maICZy1MclLrltq9Eb08drAVfRg== From: Luca Ceresoli Date: Fri, 09 Jan 2026 08:31:43 +0100 Subject: [PATCH v2 12/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: convert to of_drm_find_and_get_bridge() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-12-8bad3ef90b9f@bootlin.com> References: <20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-0-8bad3ef90b9f@bootlin.com> In-Reply-To: <20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-0-8bad3ef90b9f@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Philippe Cornu , benjamin.gaignard@linaro.org, Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Adrien Grassein , Liu Ying , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki , Marek Szyprowski Cc: Hui Pu , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 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 --- 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 *bri= dge, { struct samsung_dsim *dsi =3D bridge_to_dsi(bridge); =20 - return drm_bridge_attach(encoder, dsi->out_bridge, bridge, + return drm_bridge_attach(encoder, dsi->bridge.next_bridge, bridge, flags); } =20 @@ -1886,7 +1886,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_h= ost *host, { struct samsung_dsim *dsi =3D host_to_dsi(host); const struct samsung_dsim_plat_data *pdata =3D dsi->plat_data; - struct drm_bridge *next_bridge; + struct drm_bridge *next_bridge __free(drm_bridge_put) =3D NULL; struct device *dev =3D dsi->dev; struct device_node *np =3D dev->of_node; struct device_node *remote; @@ -1926,10 +1926,14 @@ static int samsung_dsim_host_attach(struct mipi_dsi= _host *host, panel =3D of_drm_find_panel(remote); if (!IS_ERR(panel)) { next_bridge =3D devm_drm_panel_bridge_add(dev, panel); - if (IS_ERR(next_bridge)) + if (IS_ERR(next_bridge)) { ret =3D PTR_ERR(next_bridge); + next_bridge =3D NULL; // Inhibit the cleanup action on an ERR_PTR + } else { + drm_bridge_get(next_bridge); + } } else { - next_bridge =3D of_drm_find_bridge(remote); + next_bridge =3D of_drm_find_and_get_bridge(remote); if (!next_bridge) ret =3D -EINVAL; } @@ -1961,7 +1965,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_h= ost *host, } =20 // The next bridge can be used by host_ops->attach - dsi->out_bridge =3D next_bridge; + dsi->bridge.next_bridge =3D drm_bridge_get(next_bridge); =20 if (pdata->host_ops && pdata->host_ops->attach) { ret =3D pdata->host_ops->attach(dsi, device); @@ -1976,7 +1980,8 @@ static int samsung_dsim_host_attach(struct mipi_dsi_h= ost *host, return 0; =20 err_release_next_bridge: - dsi->out_bridge =3D NULL; + drm_bridge_put(dsi->bridge.next_bridge); + dsi->bridge.next_bridge =3D NULL; return ret; } =20 @@ -1997,7 +2002,8 @@ static int samsung_dsim_host_detach(struct mipi_dsi_h= ost *host, if (pdata->host_ops && pdata->host_ops->detach) pdata->host_ops->detach(dsi, device); =20 - dsi->out_bridge =3D NULL; + drm_bridge_put(dsi->bridge.next_bridge); + dsi->bridge.next_bridge =3D NULL; =20 samsung_dsim_unregister_te_irq(dsi); =20 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; =20 --=20 2.52.0