From nobody Mon Dec 1 22:37:17 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 E97A52D876C; Fri, 28 Nov 2025 16:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764348767; cv=none; b=TNUIwtDNV26UCKwesHXgPc5TUy7TpGlWd/cdPNV9MMJ/ESHlA1Hk7Cn+OrLViJrd1HIYKBZIlWSx7OOV1c+vNVwI+8X/+DNGoS7wgkl/hbm6PbaupIWAmeVpwvrJZAmgs8MG9MO9NkPJD2/IJEsQ5WmChzmEIJm3A/ho6C4SMSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764348767; c=relaxed/simple; bh=knINAi4rAp8THNDJbIaP/v2VffMuZMS6fjT3GUTXpXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MbBFhJx7eZyzAgA67RCFnrrl198asmkF7wLSINqVXZTyH8jnXSkkoBJSYIoYbgiZbR6edFTAVGlHLaJF8llrhkuGuKpJ7qJNNy6Z+4EWyHPdUO7i15d95eMhB2DY9cf6pGLW3izsW06OFNUF9eGlAzaNWlVHf0mVPUUF9WIyUWA= 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=D9SPrZQm; arc=none smtp.client-ip=185.171.202.116 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="D9SPrZQm" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 9D172C16A3C; Fri, 28 Nov 2025 16:52:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 87E9D60706; Fri, 28 Nov 2025 16:52:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1009910B02155; Fri, 28 Nov 2025 17:52:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764348762; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=xY2ofXoGQhkxcQSEXj3JcIw9s5fwbRbm+biYrRLlQeM=; b=D9SPrZQmQfsfSxVbGR+pwv3gviqhxSdWmav5IWju8BOBdF1lGyaPh4I68aJac3CHyvbmCR xC+BaiLIpef6bnSe4czCRlm6hOy4g1r6spxJmmnkSC71kqqeyVqbSXNNoyUHuhkwAnlnrq YiQ5mlF3oiU4W9y1EdpSgW0NZmUVZsnsLvREUscdwINbFYUQf8lVH/uDovhtQLDPK+UxrH 7ppyE5A3DM8VFejWx+CAdzSQCeY912uXF7DC2gvluWw94Xwewk2y/qw7uYsCyktC6XCtsb cDlXYTUTVJvHwZXYaAFIP6ApTsR118MyQ0obvDW7fqNBp3FxCkomcEwJpBF3FA== From: Luca Ceresoli Date: Fri, 28 Nov 2025 17:50:16 +0100 Subject: [PATCH v2 06/26] drm/bridge: add devm_of_drm_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: <20251128-drm-bridge-alloc-getput-drm_of_find_bridge-v2-6-88f8a107eca2@bootlin.com> References: <20251128-drm-bridge-alloc-getput-drm_of_find_bridge-v2-0-88f8a107eca2@bootlin.com> In-Reply-To: <20251128-drm-bridge-alloc-getput-drm_of_find_bridge-v2-0-88f8a107eca2@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Alexey Brodkin , Phong LE , Liu Ying , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Adrien Grassein , Laurent Pinchart , Tomi Valkeinen , Kieran Bingham , Geert Uytterhoeven , Magnus Damm , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Chun-Kuang Hu , Philipp Zabel , Matthias Brugger , AngeloGioacchino Del Regno , Anitha Chrisanthus , Inki Dae , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Alim Akhtar Cc: Hui Pu , Thomas Petazzoni , Louis Chauvet , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Luca Ceresoli X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 Several drivers (about 20) follow the same pattern: 1. get a pointer to a bridge (typically the next bridge in the chain) by calling of_drm_find_bridge() 2. store the returned pointer in the private driver data, keep it until driver .remove 3. dereference the pointer at attach time and possibly at other times of_drm_find_bridge() is now deprecated because it does not increment the refcount and should be replaced with of_drm_get_bridge() + drm_bridge_put(). However some of those drivers have a complex code flow and adding a drm_bridge_put() call in all the appropriate locations is error-prone, leads to ugly and more complex code, and can lead to errors over time with code flow changes. To handle all those drivers in a straightforward way, add a devm variant of of_drm_get_bridge() that adds a devm action to invoke drm_bridge_put() when the said driver is removed. This allows all those drivers to put the reference automatically and safely with a one line change: - priv->next_bridge =3D of_drm_find_bridge(remote_np); + priv->next_bridge =3D devm_of_drm_get_bridge(dev, remote_np); Signed-off-by: Luca Ceresoli --- Changes in v2: - fix return value: NULL on error, as documented, not an ERR_PTR --- drivers/gpu/drm/drm_bridge.c | 28 ++++++++++++++++++++++++++++ include/drm/drm_bridge.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 9b7e3f859973..59575a84eff6 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -1442,6 +1442,34 @@ struct drm_bridge *of_drm_get_bridge(struct device_n= ode *np) } EXPORT_SYMBOL(of_drm_get_bridge); =20 +/** + * devm_of_drm_get_bridge - find the bridge corresponding to the device + * node in the global bridge list and add a devm + * action to put it + * + * @dev: device requesting the bridge + * @np: device node + * + * On success the returned bridge refcount is incremented, and a devm + * action is added to call drm_bridge_put() when @dev is removed. So the + * caller does not have to put the returned bridge explicitly. + * + * RETURNS: + * drm_bridge control struct on success, NULL on failure + */ +struct drm_bridge *devm_of_drm_get_bridge(struct device *dev, struct devic= e_node *np) +{ + struct drm_bridge *bridge =3D of_drm_get_bridge(np); + + if (bridge) { + if (devm_add_action_or_reset(dev, drm_bridge_put_void, bridge)) + return NULL; + } + + return bridge; +} +EXPORT_SYMBOL(devm_of_drm_get_bridge); + /** * of_drm_find_bridge - find the bridge corresponding to the device node in * the global bridge list diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 0977eab78aac..da69cb252cad 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -1314,12 +1314,17 @@ int drm_bridge_attach(struct drm_encoder *encoder, = struct drm_bridge *bridge, =20 #ifdef CONFIG_OF struct drm_bridge *of_drm_get_bridge(struct device_node *np); +struct drm_bridge *devm_of_drm_get_bridge(struct device *dev, struct devic= e_node *np); struct drm_bridge *of_drm_find_bridge(struct device_node *np); #else static inline struct drm_bridge *of_drm_get_bridge(struct device_node *np) { return NULL; } +static inline struct drm_bridge *devm_of_drm_get_bridge(struct device *dev= , struct device_node *np) +{ + return NULL; +} static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np) { return NULL; --=20 2.51.1