drm/bridge: add of_drm_find_and_get_bridge() and a managed *next_bridge, deprecate of_drm_find_bridge()
Subsystems (5)
Luca Ceresoli
reviewerPATCH v6 1/1 drm/bridge: add of_drm_find_and_get_bridge() and a managed *next_bridge, deprecate of_drm_find_bridge()
This is the leftover of the series that deprecated of_drm_find_bridge(), added a replacement which handles bridge refcounting, and converted some of the direct users. All patches have been applied except this.
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(), convert basic direct users
(v6.20?, one driver still pending)
b. ✔ convert direct of_drm_get_bridge() users, part 2 (v6.20?) c. ✔ convert direct of_drm_get_bridge() users, part 3 (v6.20?) d. … convert direct of_drm_get_bridge() users, part 4
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. DRM bridge hotplug
A. Bridge hotplug management in the DRM core
B. Device tree description
[0] https://lore.kernel.org/lkml/[email protected]/#t
---
Changes in v6:
- reworked for simplicity as discussed with Liu
- Link to v5: https://patch.msgid.link/20260203-drm-bridge-alloc-getput-drm_of_find_bridge-v5-0-66bda8d617b4@bootlin.com
Changes in v5:
- Changed the only remaining patch after Liu Ying's requests for code
readability
- Link to v4: https://lore.kernel.org/r/20260107-drm-bridge-alloc-getput-drm_of_find_bridge-v4-0-a62b4399a6bf@bootlin.com
Changes in v4:
- Added review trailers
- Link to v3: https://lore.kernel.org/r/20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-0-b5165fab8058@bootlin.com
Changes in v3:
- Completely rewrote using the __drm_bridge_free() idea to prevent
use-after-free of the next_bridge for the common cases
- Added needed cleanups to the imx8qxp-pixel-link and imx8qxp-pxl2dpi
drivers
- Removed various patches converting simple cases, to reduce the number of
e-mails sent; will be moved to the follow-up series
- Link to v2: https://lore.kernel.org/r/20251128-drm-bridge-alloc-getput-drm_of_find_bridge-v2-0-88f8a107eca2@bootlin.com
Changes in v2:
- All patches: renamed drm_of_find_bridge() -> of_drm_get_bridge()
- Various fixes and improvements to patches 1-6, see individual patches
changelog
- Removed bouncing recipient: Edmund Dea <[email protected]>
- Link to v1: https://lore.kernel.org/r/20251119-drm-bridge-alloc-getput-drm_of_find_bridge-v1-0-0db98a7fe474@bootlin.com
---
Luca Ceresoli (1):
drm/bridge: imx8qxp-pixel-link: get/put the next bridge
drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-)
---
base-commit: 4a0f7d0f51c0965a8a394a8c5d65be2d24e362df
change-id: 20251117-drm-bridge-alloc-getput-drm_of_find_bridge-74903367448d
Best regards,
Signature · 1 line
Luca Ceresoli <[email protected]>
Luca Ceresoli
reviewerPATCH v6 1/1 drm/bridge: imx8qxp-pixel-link: get/put the next bridge
This driver obtains a bridge pointer from of_drm_find_bridge() in the probe function and stores it until driver removal. of_drm_find_bridge() is deprecated, so move to of_drm_find_and_get_bridge() for the bridge to be refcounted and use bridge->next_bridge to put the reference on deallocation.
To keep the code as simple and reliable as possible remove the intermediate next_bridge and selected_bridge variables.
Get/put operations on the remaining pointer is pl->bridge.next_bridge, which is tied to the struct imx8qxp_pixel_link lifetime, are:
- get reference when assigned (by of_drm_find_and_get_bridge())
- put reference before reassignment if reassignment happens
- put reference when the struct imx8qxp_pixel_link embedding the struct drm_bridge is destroyed (struct drm_bridge::next_bridge)
---
Changes in v6:
- rewrite as suggested by Liu, removing the next_bridge pointer too and splitting the comment for maximum clarity
- adapt commit message accordingly
Changes in v5:
- rewrite commit message after Liu's review to clarify the per-pointer get/put idea
- split the if()s involved in selcting the bridge
- remove intermediate selected_bridge pointer
- removed Maxime's R-by, patch changed
--- drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c +13 -14
@@ -23,7 +23,6 @@struct imx8qxp_pixel_link {struct drm_bridge bridge; -struct drm_bridge *next_bridge;struct device *dev;struct imx_sc_ipc *ipc_handle;u8 stream_id;
@@ -140,7 +139,7 @@ static int imx8qxp_pixel_link_bridge_attach(struct drm_bridge *bridge, }return drm_bridge_attach (encoder, - pl->next_bridge, bridge, + pl->bridge.next_bridge, bridge,DRM_BRIDGE_ATTACH_NO_CONNECTOR ); }
@@ -260,7 +259,6 @@ static int imx8qxp_pixel_link_find_next_bridge(struct imx8qxp_pixel_link *pl) {struct device_node *np = pl->dev->of_node;struct device_node *port; -struct drm_bridge *selected_bridge =NULL ;u32 port_id;bool found_port = false;int reg;
@@ -297,20 +295,21 @@ static int imx8qxp_pixel_link_find_next_bridge(struct imx8qxp_pixel_link *pl)continue ; } -struct drm_bridge *next_bridge =of_drm_find_bridge (remote); -if (!next_bridge) -return -EPROBE_DEFER ; - -/* -* Select the next bridge with companion PXL2DPI if -* present, otherwise default to the first bridge -*/ -if (!selected_bridge ||of_property_present (remote,"fsl,companion-pxl2dpi" )) - selected_bridge = next_bridge; +if (!pl->bridge.next_bridge) { +/* Select the first bridge by default... */ + pl->bridge.next_bridge =of_drm_find_and_get_bridge (remote); +if (!pl->bridge.next_bridge) +return -EPROBE_DEFER ; + }else if (of_property_present (remote,"fsl,companion-pxl2dpi" )) { +/* ... but prefer the companion PXL2DPI if present */ +drm_bridge_put (pl->bridge.next_bridge); + pl->bridge.next_bridge =of_drm_find_and_get_bridge (remote); +if (!pl->bridge.next_bridge) +return -EPROBE_DEFER ; + } } pl->mst_addr = port_id -1 ; - pl->next_bridge = selected_bridge;return 0 ; }
Signature · 1 line
2.52.0
Re: [PATCH v6] drm/bridge: imx8qxp-pixel-link: get/put the next bridge
Quoted 31 lines · Luca Ceresoli
This driver obtains a bridge pointer from
of_drm_find_bridge()in the probe function and stores it until driver removal.of_drm_find_bridge()is deprecated, so move toof_drm_find_and_get_bridge()for the bridge to be refcounted and usebridge->next_bridgeto put the reference on deallocation.To keep the code as simple and reliable as possible remove the intermediate
next_bridgeandselected_bridgevariables.Get/put operations on the remaining pointer is
pl->bridge.next_bridge, which is tied to the structimx8qxp_pixel_linklifetime, are:
- get reference when assigned (byof_drm_find_and_get_bridge())
- put reference before reassignment if reassignment happens
- put reference when the structimx8qxp_pixel_linkembedding the structdrm_bridgeis destroyed (structdrm_bridge::next_bridge)Signed-off-by Luca Ceresoli <[email protected]>---
Changes in v6:
- rewrite as suggested by Liu, removing thenext_bridgepointer too and splitting the comment for maximum clarity
- adapt commit message accordinglyChanges in v5:
- rewrite commit message after Liu's review to clarify the per-pointer get/put idea
- split the if()s involved in selcting the bridge
- remove intermediateselected_bridgepointer
- removed Maxime's R-by, patch changed
Quoted 3 lines
--- drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-)
Thanks!
Signature · 2 lines
Regards, Liu Ying
Re: [PATCH v6] drm/bridge: imx8qxp-pixel-link: get/put the next bridge
In reply to Luca CeresoliQuoted 31 lines · Luca Ceresoli
This driver obtains a bridge pointer from
of_drm_find_bridge()in the probe function and stores it until driver removal.of_drm_find_bridge()is deprecated, so move toof_drm_find_and_get_bridge()for the bridge to be refcounted and usebridge->next_bridgeto put the reference on deallocation.To keep the code as simple and reliable as possible remove the intermediate
next_bridgeandselected_bridgevariables.Get/put operations on the remaining pointer is
pl->bridge.next_bridge, which is tied to the structimx8qxp_pixel_linklifetime, are:
- get reference when assigned (byof_drm_find_and_get_bridge())
- put reference before reassignment if reassignment happens
- put reference when the structimx8qxp_pixel_linkembedding the structdrm_bridgeis destroyed (structdrm_bridge::next_bridge)Signed-off-by Luca Ceresoli <[email protected]>---
Changes in v6:
- rewrite as suggested by Liu, removing thenext_bridgepointer too and splitting the comment for maximum clarity
- adapt commit message accordinglyChanges in v5:
- rewrite commit message after Liu's review to clarify the per-pointer get/put idea
- split the if()s involved in selcting the bridge
- remove intermediateselected_bridgepointer
- removed Maxime's R-by, patch changed
Quoted 3 lines
--- drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-)
Applied to misc/kernel.git (drm-misc-next). Thanks!
Signature · 2 lines
Regards, Liu Ying