From nobody Tue Feb 10 10:03:58 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 BCC8A328241 for ; Wed, 7 Jan 2026 13:14:21 +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=1767791663; cv=none; b=aAgtbnBLUdK8gHED6UC1Ou+7NYulGvfmrkeWquAmGp0gtpXGfA+MRGx5gZq3hUxncSck5Zy5hr7vLUTQyR7PVgwTurjcRHl3KD8TnzPao5jk5GDcx20yPOLanbSnvl14viq6GAKbgDoyKR9g4DZCwFYOmdZ3p2eHZLdEEfwqweM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791663; c=relaxed/simple; bh=0zQVGQ/4vnMKUoATvjh9ov37C2kOf7XhFIToOSDaJxc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JTbvswJssqayVSu5cAFLLF/JozWkbUk2kXjbyLWlPP0gLDNK+fXugjZZsbVniaKZly6bo5r6x4sC/qucRf6LxuviRYWKTYMoEwhGRy2d17UfZyKMEAJjzjZ62H1Oz6bnMAASEw7r47mQrEfVFChvLaNihGhu5UwYfuJw+mEK+94= 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=VPL/1gSh; 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="VPL/1gSh" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 5B0BF1A26D8; Wed, 7 Jan 2026 13:14:20 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2DFA7606F8; Wed, 7 Jan 2026 13:14:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 40055103C821A; Wed, 7 Jan 2026 14:14:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1767791658; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=z8r3jhEkERM/j9025rqzIp7DIcuzLrYHrvr0V9IN768=; b=VPL/1gShHDsKx9jMEWgIqLrVVM7kCFpCsvxC4qNSIJb3iL6T3s56oIpAjStpykLoAUSHAS d7vvs+y0WliMB/fzjw+qOpFrV+zPFwUHp3YLtBXTfZ9Uts98xj6KWgMb7I8xU9Simjifig OIIx3UrO38SoY3MESGgwWiPhD5K9Ez9db6UGwyiVa80VMW0G4k9zN4SzdeEcZi6OROnUM7 434KVNJYaz8Ib/K303k1qdCQlKQ+YpXc54zgN5s2V/jDr1s5rp8tf2sGOWIso0oesLN2qo wb1ZtWfQKj3Iy2amidNZTo2v9ndsRzBt3FV80e+FsBD3rbXJMV7IRHP1E8eadw== From: Luca Ceresoli Date: Wed, 07 Jan 2026 14:13:03 +0100 Subject: [PATCH 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: <20260107-drm-bridge-alloc-getput-drm_of_find_bridge-2-v1-12-283d7bba061a@bootlin.com> References: <20260107-drm-bridge-alloc-getput-drm_of_find_bridge-2-v1-0-283d7bba061a@bootlin.com> In-Reply-To: <20260107-drm-bridge-alloc-getput-drm_of_find_bridge-2-v1-0-283d7bba061a@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 Acked-by: Maxime Ripard --- drivers/gpu/drm/bridge/samsung-dsim.c | 19 ++++++++++++------- include/drm/bridge/samsung-dsim.h | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge= /samsung-dsim.c index d6ef64e68623..e10c01672efd 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; } @@ -1969,7 +1973,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_h= ost *host, dsi->lanes =3D device->lanes; dsi->format =3D device->format; dsi->mode_flags =3D device->mode_flags; - dsi->out_bridge =3D next_bridge; + dsi->bridge.next_bridge =3D drm_bridge_get(next_bridge); =20 return 0; } @@ -1988,8 +1992,6 @@ static int samsung_dsim_host_detach(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; =20 - dsi->out_bridge =3D NULL; - if (pdata->host_ops && pdata->host_ops->detach) pdata->host_ops->detach(dsi, device); =20 @@ -1997,6 +1999,9 @@ static int samsung_dsim_host_detach(struct mipi_dsi_h= ost *host, =20 drm_bridge_remove(&dsi->bridge); =20 + drm_bridge_put(dsi->bridge.next_bridge); + dsi->bridge.next_bridge =3D NULL; + return 0; } =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