mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: Luca Ceresoli <luca.ceresoli@bootlin.com>
To: Andrzej Hajda <andrzej.hajda@intel.com>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	Robert Foss <rfoss@kernel.org>,
	 Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	 Jonas Karlman <jonas@kwiboo.se>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	 David Airlie <airlied@gmail.com>,
	Simona Vetter <simona@ffwll.ch>,
	 Jonathan Corbet <corbet@lwn.net>,
	Alexey Brodkin <abrodkin@synopsys.com>,
	 Phong LE <ple@baylibre.com>, Liu Ying <victor.liu@nxp.com>,
	 Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	 Pengutronix Kernel Team <kernel@pengutronix.de>,
	 Fabio Estevam <festevam@gmail.com>,
	Kevin Hilman <khilman@baylibre.com>,
	 Jerome Brunet <jbrunet@baylibre.com>,
	 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: Hui Pu <Hui.Pu@gehealthcare.com>,
	 Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 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-amlogic@lists.infradead.org,
	 Luca Ceresoli <luca.ceresoli@bootlin.com>
Subject: [PATCH v3 02/22] drm/bridge: deprecate of_drm_find_bridge()
Date: Tue, 16 Dec 2025 18:58:35 +0100	[thread overview]
Message-ID: <20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-2-b5165fab8058@bootlin.com> (raw)
In-Reply-To: <20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-0-b5165fab8058@bootlin.com>

of_drm_find_bridge() does not increment the returned bridge
refcount. of_drm_find_and_get_bridge() is to be used as a replacement.

Suggested-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/dri-devel/20250319-stylish-lime-mongoose-0a18ad@houat/
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---

Changes in v3:
- update after of_drm_get_bridge() -> of_drm_find_and_get_bridge() rename

Changes in v2:
- expand comment to mention why this function is dangerous and what users
  should do about refcounting
---
 drivers/gpu/drm/drm_bridge.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 0dbc8b59c3be..f612d486cad0 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -361,7 +361,7 @@ EXPORT_SYMBOL(__devm_drm_bridge_alloc);
  * @bridge: bridge control structure
  *
  * Add the given bridge to the global list of bridges, where they can be
- * found by users via of_drm_find_bridge().
+ * found by users via of_drm_find_and_get_bridge().
  *
  * The bridge to be added must have been allocated by
  * devm_drm_bridge_alloc().
@@ -422,9 +422,9 @@ EXPORT_SYMBOL(devm_drm_bridge_add);
  * @bridge: bridge control structure
  *
  * Remove the given bridge from the global list of registered bridges, so
- * it won't be found by users via of_drm_find_bridge(), and add it to the
- * lingering bridge list, to keep track of it until its allocated memory is
- * eventually freed.
+ * it won't be found by users via of_drm_find_and_get_bridge(), and add it
+ * to the lingering bridge list, to keep track of it until its allocated
+ * memory is eventually freed.
  */
 void drm_bridge_remove(struct drm_bridge *bridge)
 {
@@ -1510,6 +1510,20 @@ EXPORT_SYMBOL(of_drm_find_and_get_bridge);
  *
  * @np: device node
  *
+ * This function is deprecated. Convert to of_drm_find_and_get_bridge()
+ * instead for proper refcounting.
+ *
+ * The bridge returned by this function is not refcounted. This is
+ * dangerous because the bridge might be deallocated even before the caller
+ * has a chance to use it. To use this function you have to do one of:
+ * - get a reference with drm_bridge_get() as soon as possible to
+ *   minimize the race window, and then drm_bridge_put() when no longer
+ *   using the pointer
+ * - not call drm_bridge_get() or drm_bridge_put() at all, which used to
+ *   be the correct practice before dynamic bridge lifetime was introduced
+ * - again, convert to of_drm_find_and_get_bridge(), which is the only safe
+ *   thing to do
+ *
  * RETURNS:
  * drm_bridge control struct on success, NULL on failure
  */

-- 
2.52.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  parent reply	other threads:[~2025-12-16 17:59 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-16 17:58 [PATCH v3 00/22] drm/bridge: add of_drm_find_and_get_bridge() and a managed *next_bridge, " Luca Ceresoli
2025-12-16 17:58 ` [PATCH v3 01/22] drm/bridge: add of_drm_find_and_get_bridge() Luca Ceresoli
2025-12-17 10:15   ` Maxime Ripard
2025-12-17 14:31     ` Luca Ceresoli
2025-12-18 12:50       ` Maxime Ripard
2025-12-18 14:23         ` Luca Ceresoli
2025-12-16 17:58 ` Luca Ceresoli [this message]
2025-12-16 17:58 ` [PATCH v3 03/22] drm/todo: add entry about converting to of_drm_find_and_get_bridge() Luca Ceresoli
2025-12-16 17:58 ` [PATCH v3 04/22] drm/bridge: make of_drm_find_bridge() a wrapper of of_drm_find_and_get_bridge() Luca Ceresoli
2025-12-17 10:16   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 05/22] drm/arcpgu: convert to of_drm_find_and_get_bridge() Luca Ceresoli
2025-12-17 10:16   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 06/22] drm/bridge: add next_bridge pointer to struct drm_bridge Luca Ceresoli
2025-12-17 10:17   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 07/22] drm/bridge: ite-it66121: get/put the next bridge Luca Ceresoli
2025-12-17 10:17   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 08/22] drm/bridge: imx8qxp-pixel-combiner: " Luca Ceresoli
2025-12-17 10:17   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 09/22] drm/bridge: simple-bridge: " Luca Ceresoli
2025-12-17 10:41   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 10/22] drm/meson: encoder_cvbs: " Luca Ceresoli
2025-12-17 10:17   ` Maxime Ripard
2025-12-21 21:50   ` Martin Blumenstingl
2025-12-16 17:58 ` [PATCH v3 11/22] drm/meson: encoder_dsi: " Luca Ceresoli
2025-12-17 10:18   ` Maxime Ripard
2025-12-21 21:50   ` Martin Blumenstingl
2025-12-16 17:58 ` [PATCH v3 12/22] drm/meson: encoder_hdmi: " Luca Ceresoli
2025-12-17 10:18   ` Maxime Ripard
2025-12-21 21:51   ` Martin Blumenstingl
2025-12-22  7:30     ` Luca Ceresoli
2025-12-22 10:38       ` Martin Blumenstingl
2025-12-16 17:58 ` [PATCH v3 13/22] drm/bridge: imx8qxp-pxl2dpi: simplify put of device_node pointers Luca Ceresoli
2025-12-17 10:18   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 14/22] drm/bridge: imx8qxp-pxl2dpi: remove excess error message Luca Ceresoli
2025-12-17 10:19   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 15/22] drm/bridge: imx8qxp-pxl2dpi: imx8qxp_pxl2dpi_find_next_bridge: return int, not ERR_PTR Luca Ceresoli
2025-12-17 10:20   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 16/22] drm/bridge: imx8qxp-pxl2dpi: get/put the next bridge Luca Ceresoli
2025-12-17 10:20   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 17/22] drm/bridge: imx8qxp-pxl2dpi: get/put the companion bridge Luca Ceresoli
2025-12-17 10:20   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 18/22] drm/bridge: imx8qxp-pixel-link: simplify logic to find next bridge Luca Ceresoli
2025-12-16 17:58 ` [PATCH v3 19/22] drm/bridge: imx8qxp-pixel-link: simplify freeing of the remote device_node Luca Ceresoli
2025-12-17 10:25   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 20/22] drm/bridge: imx8qxp-pixel-link: remove excess error message Luca Ceresoli
2025-12-17 10:20   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 21/22] drm/bridge: imx8qxp-pixel-link: imx8qxp_pixel_link_find_next_bridge: return int, not ERR_PTR Luca Ceresoli
2025-12-17 10:25   ` Maxime Ripard
2025-12-16 17:58 ` [PATCH v3 22/22] drm/bridge: imx8qxp-pixel-link: get/put the next bridge Luca Ceresoli
2025-12-17 10:25   ` Maxime Ripard
2025-12-30  9:17 ` [PATCH v3 00/22] drm/bridge: add of_drm_find_and_get_bridge() and a managed *next_bridge, deprecate of_drm_find_bridge() Luca Ceresoli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-2-b5165fab8058@bootlin.com \
    --to=luca.ceresoli@bootlin.com \
    --cc=Hui.Pu@gehealthcare.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=abrodkin@synopsys.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=corbet@lwn.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=jbrunet@baylibre.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=kernel@pengutronix.de \
    --cc=khilman@baylibre.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=ple@baylibre.com \
    --cc=rfoss@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tzimmermann@suse.de \
    --cc=victor.liu@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox