[PATCH v2 0/2] drm/bridge: add drm_bridge_clear_and_put()

Luca Ceresoli posted 2 patches 3 weeks, 1 day ago
drivers/gpu/drm/bridge/samsung-dsim.c |  7 ++-----
drivers/gpu/drm/drm_bridge.c          | 34 ++++++++++++++++++++++++++++++++++
include/drm/drm_bridge.h              |  1 +
3 files changed, 37 insertions(+), 5 deletions(-)
[PATCH v2 0/2] drm/bridge: add drm_bridge_clear_and_put()
Posted by Luca Ceresoli 3 weeks, 1 day ago
This small series introduces drm_bridge_clear_and_put(), to give a easy and
safe way to put a bridge reference and clear the pointer without leaving a
possible use-after-free window.

This is part of the work to support hotplug of DRM bridges. The grand plan
was discussed in [0].

Here's the work breakdown (➜ marks the current series):

 1. … add refcounting to DRM bridges struct drm_bridge,
      based on devm_drm_bridge_alloc()
    A. ✔ add new alloc API and refcounting (v6.16)
    B. ✔ convert all bridge drivers to new API (v6.17)
    C. ✔ kunit tests (v6.17)
    D. ✔ add get/put to drm_bridge_add/remove() + attach/detach()
         and warn on old allocation pattern (v6.17)
    E. … add get/put on drm_bridge accessors
       1. ✔ drm_bridge_chain_get_first_bridge(), add cleanup action (v6.18)
       2. ✔ drm_bridge_get_prev_bridge() (v6.18)
       3. ✔ drm_bridge_get_next_bridge() (v6.19)
       4. ✔ drm_for_each_bridge_in_chain() (v6.19)
       5. ✔ drm_bridge_connector_init (v6.19)
       6. … protect encoder bridge chain with a mutex
       7. … of_drm_find_bridge
          a. ✔ add of_drm_get_bridge() (v7.0),
	       convert basic direct users (v7.0-v7.1)
	  b. ✔ convert direct of_drm_get_bridge() users, part 2 (v7.0)
	  c. ✔ convert direct of_drm_get_bridge() users, part 3 (v7.0)
	  d. ✔… convert direct of_drm_get_bridge() users, part 4
	        (some v7.1, some pending)
	  e.   convert bridge-only drm_of_find_panel_or_bridge() users
       8. drm_of_find_panel_or_bridge, *_of_get_bridge
       9. ✔ enforce drm_bridge_add before drm_bridge_attach (v6.19)
    F. ✔ debugfs improvements
       1. ✔ add top-level 'bridges' file (v6.16)
       2. ✔ show refcount and list lingering bridges (v6.19)
 2. ➜ handle gracefully atomic updates during bridge removal
    A. ✔ Add drm_dev_enter/exit() to protect device resources (v6.20?)
    B. … protect private_obj removal from list
    C. ➜ Add drm_bridge_clear_and_put()
 3. … DSI host-device driver interaction
 4. ✔ removing the need for the "always-disconnected" connector
 5. … Migrate i.MX LCDIF driver to bridge-connector
 6.   DRM bridge hotplug
    A.   Bridge hotplug management in the DRM core
    B.   Device tree description

[0] https://lore.kernel.org/lkml/20250206-hotplug-drm-bridge-v6-0-9d6f2c9c3058@bootlin.com/#t

Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v2:
- Rebased on current drm-misc-next fixing trivial conflict
- Link to v1: https://lore.kernel.org/r/20260206-drm-bridge-atomic-vs-remove-clear_and_put-v1-0-6f1a7d03c45f@bootlin.com

---
Luca Ceresoli (2):
      drm/bridge: add drm_bridge_clear_and_put()
      drm/bridge: samsung-dsim: use drm_bridge_clear_and_put() to put the next bridge

 drivers/gpu/drm/bridge/samsung-dsim.c |  7 ++-----
 drivers/gpu/drm/drm_bridge.c          | 34 ++++++++++++++++++++++++++++++++++
 include/drm/drm_bridge.h              |  1 +
 3 files changed, 37 insertions(+), 5 deletions(-)
---
base-commit: 08c6a9b501d2fdf161094a98e1febec41f566c8f
change-id: 20260206-drm-bridge-atomic-vs-remove-clear_and_put-a424c752a061

Best regards,
-- 
Luca Ceresoli <luca.ceresoli@bootlin.com>

Re: [PATCH v2 0/2] drm/bridge: add drm_bridge_clear_and_put()
Posted by Luca Ceresoli 1 week, 5 days ago
On Tue, 10 Mar 2026 13:13:22 +0100, Luca Ceresoli wrote:
> This small series introduces drm_bridge_clear_and_put(), to give a easy and
> safe way to put a bridge reference and clear the pointer without leaving a
> possible use-after-free window.
> 
> This is part of the work to support hotplug of DRM bridges. The grand plan
> was discussed in [0].
> 
> [...]

Applied, thanks!

[1/2] drm/bridge: add drm_bridge_clear_and_put()
      commit: 8f3c83720555ffa96799896f2a0bb985a03a89f4
[2/2] drm/bridge: samsung-dsim: use drm_bridge_clear_and_put() to put the next bridge
      commit: fbef867cf6614178bc6afd15ee15f85cddf19eab

Best regards,
-- 
Luca Ceresoli <luca.ceresoli@bootlin.com>
Re: [PATCH v2 0/2] drm/bridge: add drm_bridge_clear_and_put()
Posted by Maxime Ripard 3 weeks ago
On Tue, 10 Mar 2026 13:13:22 +0100, Luca Ceresoli wrote:
> This small series introduces drm_bridge_clear_and_put(), to give a easy and
> safe way to put a bridge reference and clear the pointer without leaving a
> possible use-after-free window.
> 
> This is part of the work to support hotplug of DRM bridges. The grand plan
> 
> [ ... ]

Acked-by: Maxime Ripard <mripard@kernel.org>

Thanks!
Maxime