drm bridge hotplug
Subsystems (6)
Luca Ceresoli
reviewercover drm bridge hotplug
Hello,
this series adds support for Linux-based devices with a DRM pipeline whose final components, including one or more bridges, can be hot-plugged and hot-unplugged.
TL;DR:
* This new approach is totally different from the one proposed in the past [0], and the code is an almost completely rewrite
* If you already know the use case, feel free to skip to the "Design" section below
Use case
========
This series targets as its first use case a professional product (GE SUNH) that is composed of a "main" part, with the main SoC and able to work autonomously with limited features, and an optional "add-on" that enables more features by adding more hardware peripherals.
The hotplug connector has a MIPI DSI bus. The addon has a DSI-to-LVDS bridge and an LVDS panel attached to it. Different addon models can have different components. As a consequence, a DRM bridge must be added and removed at runtime without tearing down the whole card. This is currently not possible, and this series enables it.
DRM already supports pipelines whose display can be removed, but all the components preceding it (all the display controller and any bridges) are assumed to be fixed and cannot be plugged, removed or modified at runtime. Additionally, dynamic drm_connectors are supported for DP MST.
This picture summarizes the DRM structure implemented by this series:
.------------------------.
| DISPLAY CONTROLLER |
| .---------. .------. |
| | ENCODER |<--| CRTC | |
| '---------' '------' |
'------|-----------------'
| MACHANICAL
|DSI HOTPLUG
V CONNECTOR
.---------. .--. .-. .---------. .-------.
| 0 to N | | _| _| | | 1 to N | | |
| BRIDGES |--DSI-->||_ |_ |--DSI-->| BRIDGES |--LVDS-->| PANEL |
| | | | | | | | | |
'---------' '--' '-' '---------' '-------'[--- fixed components --] [----------- removable add-on -----------]
The video bus is MIPI DSI in the example and in the implementation provided by this series, but the implementation is meant to allow generalization to other video busses without native hotplug support, such as parallel video and LVDS. Addons which terminate with a HDMI/DP connector are possible too.
== Design
The old approach [0] was based on a hotplug-bridge driver, connected between the last fixed bridge and the first removable bridge.
That approach has been rejected, and this new approach is based on a central place to handle DRM hotplug, not a specific driver.
The drm_bridge_connector is nowadays the recommended way to implement DRM connectors when a chain of bridges is used. It takes care of adding the drm_connector when the pipeline is composed by an arbitrarily long chain of bridges, which it scans to properly implement the drm_connector operations.
As such the drm_bridge_connector looked like the ideal component to implement DRM bridge hotplug.
This series augments the drm_bridge_connector code to be able to create and destroy the drm_connector reacting on hot(un)plug events.
== Series description
This series has many preparatory patches: to make the drm_bridge_connector code allocate the drm_connector dynamically and to prepare various other parts of the involved DRM code.
In current code the last bridge in the encoder chain is always assumed to complete the pipeline. There is no way for a bridge to tell "I'm currently the last bridge in the encoder chain, but I need an next bridge to work". This series has some patches to allow such a behaviour:
* bridges can now report whether they conclude the pipeline or not (I propose the "tail bridge" naming to tell this)
* returning -EPROBE_DEFER on bridge attach is not considered a hard error anymore, it's normal when the next bridge is needed but not yet present
Compared to the hotplug-bridge approach, now bridge drivers need a bit of adaptation in order to support that the following bridge is hotpluggable. So there are a few changes to the samsung-dsim bridge driver, which in the hardware I'm working on is the last fixed bridge.
Finally, as the current drm_bridge_connector API is unable to support hotplug, a new API is added to enable the new features. This makes existing drivers not affected by the changes. The last patch shows to changes needed to an encoder driver to switch to the new API enabling hotplug support.
== Series layout
1. Add a dynamic variant of drm_connector_hdmi_init()
(needed for the bridge-connector to allocate the connector dynamically)
* drm/connector: split drmm_connector_hdmi_init() in 3 parts
* drm/connector: add drm_connector_hdmi_dynamic_init()
2. bridge-connector: split the long drm_bridge_connector_init() in various parts in preparation to be called in different ways
* drm/display: bridge-connector: rename variable for consistency
* drm/display: bridge-connector: store the drm_device pointer
* drm/display: bridge-connector: split code creating the connector to a subfunction
* drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector
* drm/display: bridge-connector: extract drm_bridge_connector_get_bridges()
* drm/display: bridge-connector: return int from drm_bridge_connector_get_bridges()
* drm/display: bridge-connector: extract drm_bridge_connector_init_hdmi_audio_cec()
* drm/display: bridge-connector: return int from drm_bridge_connector_init_hdmi_audio_cec()
* drm/display: bridge-connector: return int from drm_bridge_connector_add_connector()
3. bridge-connector: create the drm_connector dynamically
* drm/display: bridge-connector: hoist error management to common code
* drm/display: bridge-connector: move drm_bridge_connector_put_bridges() definition eariler
* drm/display: bridge-connector: add non-drmm variant of drm_bridge_connector_put_bridges()
* drm/display: bridge-connector: allocate the connector dynamically
* drm/display: bridge-connector: move per-connector fields to the dynamic connector
* drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
4. samsung-dsim: prepare driver to work when the following bridge is hotpluggable
* drm/bridge: samsung-dsim: remove the panel_bridge on host_detach
* drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
* drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available
5. Misc preparation work
* drm/bridge: initialize chain_node list head on allocation
* drm/bridge: initialize chain_node list head on detach and attach errors
6. drm_bridge: stop pipeline when a bridge is removed
* drm/encoder: add drm_encoder_cleanup_from()
* drm/atomic: move drm_atomic_helper_disable_all() and drm_atomic_helper_shutdown() from drm_atomic_helper to drm_atomic
* drm/bridge: shutdown and cleanup on bridge unplug
7. Add notifier mechanism to let common code (the bridge-connector) take actions on hotplug events
* drm: event-notifier: add mechanism to notify about hotplug events
* drm/bridge: notify about detached bridges
* drm/mipi-dsi: turn DRM_MIPI_DSI into a tristate
* drm/mipi-dsi: notify about DSI attach
8. Allow common code to know when the pipeline is complete
* drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
* drm/bridge: panel: implement .is_tail
* drm/bridge: display-connector: implement .is_tail
* drm/bridge: samsung-dsim: implement .is_tail
* drm/bridge: ti-sn65dsi83: implement .is_tail
9. Allow probing incomplete pipelines
* drm/bridge: drm_bridge_attach(): don't fail on -EPROBE_DEFER
10. Implement bridge hotplug in bridge-connector, enable it in a driver
* drm/display: bridge-connector: handle bridge hotplug
* drm/mxsfb/lcdif: enable bridge hotplug
== Grand plan
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 (v7.2)
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 (v7.1-v7.2) e. ✔ bridge-only drm_of_find_panel_or_bridge() users (v7.2)
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_bridge_enter/exit() to protect device resources (v7.0) B. … protect private_obj removal from list
C. ✔ Add drm_bridge_clear_and_put() (v7.1)
3. … DSI host-device driver interaction
4. ✔ removing the need for the "always-disconnected" connector
5. ✔ Migrate i.MX LCDIF driver to bridge-connector (v7.2)
6. ➜ DRM bridge hotplug
A. ➜ Bridge hotplug management in the DRM core
1. ✔ bridge-connector: attach encoder to the connector (v7.2)
2. ➜ drm bridge hotplug
B. Device tree description
[0] https://lore.kernel.org/lkml/[email protected]/#t
== Dependencies
This series depends on:
* "drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal
from list"
- https://lore.kernel.org/lkml/20260324-drm-bridge-atomic-vs-remove-private_obj-v3-1-64deefe84044@bootlin.com/
- Reason: avoid sporadic deadlock
---
Luca Ceresoli (37):
drm/connector: split drmm_connector_hdmi_init() in 3 parts
drm/connector: add drm_connector_hdmi_dynamic_init()
drm/display: bridge-connector: rename variable for consistency
drm/display: bridge-connector: store the drm_device pointer
drm/display: bridge-connector: split code creating the connector to a subfunction
drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector drm/display: bridge-connector: extract drm_bridge_connector_get_bridges()
drm/display: bridge-connector: return int from drm_bridge_connector_get_bridges()
drm/display: bridge-connector: extract drm_bridge_connector_init_hdmi_audio_cec()
drm/display: bridge-connector: return int from drm_bridge_connector_init_hdmi_audio_cec() drm/display: bridge-connector: return int from drm_bridge_connector_add_connector()
drm/display: bridge-connector: hoist error management to common code
drm/display: bridge-connector: move drm_bridge_connector_put_bridges() definition eariler drm/display: bridge-connector: add non-drmm variant of drm_bridge_connector_put_bridges() drm/display: bridge-connector: allocate the connector dynamically
drm/display: bridge-connector: move per-connector fields to the dynamic connector
drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
drm/bridge: samsung-dsim: remove the panel_bridge on host_detach
drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available drm/bridge: initialize chain_node list head on allocation
drm/bridge: initialize chain_node list head on detach and attach errors
drm/encoder: add drm_encoder_cleanup_from()
drm/atomic: move drm_atomic_helper_disable_all() and drm_atomic_helper_shutdown() from drm_atomic_helper to drm_atomic drm/bridge: shutdown and cleanup on bridge unplug
drm: event-notifier: add mechanism to notify about hotplug events
drm/bridge: notify about detached bridges
drm/mipi-dsi: turn DRM_MIPI_DSI into a tristate
drm/mipi-dsi: notify about DSI attach
drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
drm/bridge: panel: implement .is_tail
drm/bridge: display-connector: implement .is_tail
drm/bridge: samsung-dsim: implement .is_tail
drm/bridge: ti-sn65dsi83: implement .is_tail
drm/bridge: drm_bridge_attach(): don't fail on -EPROBE_DEFER
drm/display: bridge-connector: handle bridge hotplug
drm/mxsfb/lcdif: enable bridge hotplug
drivers/gpu/drm/Kconfig | 7 +- drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/bridge/display-connector.c | 7 + drivers/gpu/drm/bridge/panel.c | 8 +- drivers/gpu/drm/bridge/samsung-dsim.c | 36 +- drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 + drivers/gpu/drm/display/drm_bridge_connector.c | 835 +++++++++++++++++-------- drivers/gpu/drm/drm_atomic.c | 115 ++++ drivers/gpu/drm/drm_atomic_helper.c | 76 +-- drivers/gpu/drm/drm_bridge.c | 47 +- drivers/gpu/drm/drm_connector.c | 155 +++-- drivers/gpu/drm/drm_encoder.c | 38 ++ drivers/gpu/drm/drm_event_notifier.c | 58 ++ drivers/gpu/drm/drm_mipi_dsi.c | 3 + drivers/gpu/drm/mxsfb/lcdif_drv.c | 8 +- include/drm/bridge/samsung-dsim.h | 2 + include/drm/drm_atomic.h | 3 + include/drm/drm_bridge.h | 19 + include/drm/drm_bridge_connector.h | 2 + include/drm/drm_connector.h | 9 + include/drm/drm_encoder.h | 1 + include/drm/drm_event_notifier.h | 36 ++ 22 files changed, 1078 insertions(+), 396 deletions(-)
---
base-commit: 289b9a790d52a6865db3006f07922a9191faa54e
change-id: 20260515-drm-bridge-hotplug-46265d3a2f85
Best regards,
Signature · 3 lines
Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Luca Ceresoli
reviewerPATCH 1/37 drm/connector: split drmm_connector_hdmi_init() in 3 parts
In preparation for adding a dynamic variant of drmm_connector_hdmi_init(), split reusable parts of the code to subfunctions.
drmm_connector_hdmi_init() currently has 3 sections:
1. sanity checks
2. call drmm_connector_init()
3. initialize HDMI-specific fields not initialized at step 2
Split 1 and 3 to new functions, reusable independently.
No functional changes. Just moving code around.
--- drivers/gpu/drm/drm_connector.c | 105 +++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 40 deletions(-)
drivers/gpu/drm/drm_connector.c +65 -40
@@ -542,44 +542,13 @@ int drmm_connector_init(struct drm_device *dev, }EXPORT_SYMBOL (drmm_connector_init); -/** -* drmm_connector_hdmi_init - Init a preallocated HDMI connector -* @dev: DRM device -* @connector: A pointer to the HDMI connector to init -* @vendor: HDMI Controller Vendor name -* @product: HDMI Controller Product name -* @funcs: callbacks for this connector -* @hdmi_funcs: HDMI-related callbacks for this connector -* @connector_type: user visible type of the connector -* @ddc: optional pointer to the associated ddc adapter -* @supported_formats: Bitmask of @drm_output_color_format listing supported output formats -* @max_bpc: Maximum bits per char the HDMI connector supports -* -* Initialises a preallocated HDMI connector. Connectors can be -* subclassed as part of driver connector objects. -* -* Cleanup is automatically handled with a call to -* drm_connector_cleanup() in a DRM-managed action. -* -* The connector structure should be allocated with drmm_kzalloc(). -* -* The @drm_connector_funcs.destroy hook must be NULL. -* -* Returns: -* Zero on success, error code on failure. -*/ -int drmm_connector_hdmi_init (struct drm_device *dev, -struct drm_connector *connector, -const char *vendor,const char *product, -const struct drm_connector_funcs *funcs, -const struct drm_connector_hdmi_funcs *hdmi_funcs, -int connector_type, -struct i2c_adapter *ddc, -unsigned long supported_formats, -unsigned int max_bpc) +static int drm_connector_hdmi_sanity_checks (struct drm_connector *connector, +const char *vendor,const char *product, +const struct drm_connector_hdmi_funcs *hdmi_funcs, +int connector_type, +unsigned long supported_formats, +unsigned int max_bpc) { -int ret; -if (!vendor || !product)return -EINVAL ;
@@ -606,10 +575,15 @@ int drmm_connector_hdmi_init(struct drm_device *dev, !hdmi_funcs->hdmi.write_infoframe)return -EINVAL ; - ret =drmm_connector_init (dev, connector, funcs, connector_type, ddc); -if (ret) -return ret; +return 0 ; +} +static void drm_connector_hdmi_init (struct drm_connector *connector, +const char *vendor,const char *product, +const struct drm_connector_hdmi_funcs *hdmi_funcs, +unsigned long supported_formats, +unsigned int max_bpc) +{ connector->hdmi.supported_formats = supported_formats;strtomem_pad (connector->hdmi.vendor, vendor,0 );strtomem_pad (connector->hdmi.product, product,0 );
@@ -628,6 +602,57 @@ int drmm_connector_hdmi_init(struct drm_device *dev,drm_connector_attach_hdr_output_metadata_property (connector); connector->hdmi.funcs = hdmi_funcs; +} + +/** +* drmm_connector_hdmi_init - Init a preallocated HDMI connector +* @dev: DRM device +* @connector: A pointer to the HDMI connector to init +* @vendor: HDMI Controller Vendor name +* @product: HDMI Controller Product name +* @funcs: callbacks for this connector +* @hdmi_funcs: HDMI-related callbacks for this connector +* @connector_type: user visible type of the connector +* @ddc: optional pointer to the associated ddc adapter +* @supported_formats: Bitmask of @drm_output_color_format listing supported output formats +* @max_bpc: Maximum bits per char the HDMI connector supports +* +* Initialises a preallocated HDMI connector. Connectors can be +* subclassed as part of driver connector objects. +* +* Cleanup is automatically handled with a call to +* drm_connector_cleanup() in a DRM-managed action. +* +* The connector structure should be allocated with drmm_kzalloc(). +* +* The @drm_connector_funcs.destroy hook must be NULL. +* +* Returns: +* Zero on success, error code on failure. +*/ +int drmm_connector_hdmi_init (struct drm_device *dev, +struct drm_connector *connector, +const char *vendor,const char *product, +const struct drm_connector_funcs *funcs, +const struct drm_connector_hdmi_funcs *hdmi_funcs, +int connector_type, +struct i2c_adapter *ddc, +unsigned long supported_formats, +unsigned int max_bpc) +{ +int ret; + + ret =drm_connector_hdmi_sanity_checks (connector, vendor, product, hdmi_funcs, + connector_type, supported_formats, max_bpc); +if (ret) +return ret; + + ret =drmm_connector_init (dev, connector, funcs, connector_type, ddc); +if (ret) +return ret; + +drm_connector_hdmi_init (connector, vendor, product, + hdmi_funcs, supported_formats, max_bpc);return 0 ; }
Signature · 1 line
2.54.0
Maxime Ripard
maintainerRe: [PATCH 01/37] drm/connector: split drmm_connector_hdmi_init() in 3 parts
Quoted 11 lines · Luca Ceresoli
In preparation for adding a dynamic variant of
drmm_connector_hdmi_init(), split reusable parts of the code to subfunctions.
drmm_connector_hdmi_init()currently has 3 sections:
1. sanity checks
2. calldrmm_connector_init()
3. initialize HDMI-specific fields not initialized at step 2Split 1 and 3 to new functions, reusable independently.
No functional changes. Just moving code around.
Explaining what you need later on, and why these three functions help in particular, would be nice.
Maxime
Luca Ceresoli
reviewerPATCH 2/37 drm/connector: add drm_connector_hdmi_dynamic_init()
In reply to Luca CeresoliIn preparation for adding hotpluggable bridges into the drm_bridge_connector, we need connectors to be created dynamically, both regular connectors and HDMI ones. drm_connector_init() already has a dynamic variant, add one for HDMI connectors too.
--- drivers/gpu/drm/drm_connector.c | 50 +++++++++++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 9 ++++++++ 2 files changed, 59 insertions(+)
drivers/gpu/drm/drm_connector.c +50 -0
@@ -658,6 +658,56 @@ int drmm_connector_hdmi_init(struct drm_device *dev, }EXPORT_SYMBOL (drmm_connector_hdmi_init); +/** +* drm_connector_hdmi_dynamic_init - Init a preallocated dynamic HDMI connector +* @dev: DRM device +* @connector: A pointer to the HDMI connector to init +* @vendor: HDMI Controller Vendor name +* @product: HDMI Controller Product name +* @funcs: callbacks for this connector +* @hdmi_funcs: HDMI-related callbacks for this connector +* @connector_type: user visible type of the connector +* @ddc: optional pointer to the associated ddc adapter +* @supported_formats: Bitmask of @hdmi_colorspace listing supported output formats +* @max_bpc: Maximum bits per char the HDMI connector supports +* +* Initialises a preallocated dynamic HDMI connector. Connectors can be +* subclassed as part of driver connector objects. +* +* See drm_connector_dynamic_init(), the same constraints apply here. This +* is just the HDMI version. +* +* Returns: +* Zero on success, error code on failure. +*/ +int drm_connector_hdmi_dynamic_init (struct drm_device *dev, +struct drm_connector *connector, +const char *vendor,const char *product, +const struct drm_connector_funcs *funcs, +const struct drm_connector_hdmi_funcs *hdmi_funcs, +int connector_type, +struct i2c_adapter *ddc, +unsigned long supported_formats, +unsigned int max_bpc) +{ +int ret; + + ret =drm_connector_hdmi_sanity_checks (connector, vendor, product, hdmi_funcs, + connector_type, supported_formats, max_bpc); +if (ret) +return ret; + + ret =drm_connector_dynamic_init (dev, connector, funcs, connector_type, ddc); +if (ret) +return ret; + +drm_connector_hdmi_init (connector, vendor, product, + hdmi_funcs, supported_formats, max_bpc); + +return 0 ; +} +EXPORT_SYMBOL (drm_connector_hdmi_dynamic_init); +/** * drm_connector_attach_edid_property - attach edid property. * @connector: the connector
include/drm/drm_connector.h +9 -0
@@ -2442,6 +2442,15 @@ int drmm_connector_hdmi_init(struct drm_device *dev,struct i2c_adapter *ddc, unsigned long supported_formats, unsigned int max_bpc); +int drm_connector_hdmi_dynamic_init (struct drm_device *dev, +struct drm_connector *connector, +const char *vendor,const char *product, +const struct drm_connector_funcs *funcs, +const struct drm_connector_hdmi_funcs *hdmi_funcs, +int connector_type, +struct i2c_adapter *ddc, +unsigned long supported_formats, +unsigned int max_bpc);void drm_connector_attach_edid_property (struct drm_connector *connector);int drm_connector_register (struct drm_connector *connector);int drm_connector_dynamic_register (struct drm_connector *connector);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 02/37] drm/connector: add drm_connector_hdmi_dynamic_init()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unconditional dereference of connector->state if the reset callback fails to allocate memory. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditional dereference of connector->state if the reset callback fails to allocate memory. --
commit 7cc84b3b3fd13ae7b12a391a46d924249c29ae3d
Author: Luca Ceresoli <[email protected]>
drm/connector: add drm_connector_hdmi_dynamic_init()
This commit introduces a dynamic initialization variant for HDMI connectors to support hotpluggable bridges.
Quoted 4 lines
drivers/gpu/drm/drm_connector.c +0
-0
[ ... ]
Quoted 14 lines
drivers/gpu/drm/drm_connector.c +13
-0@@ -658,6 +658,56 @@ int drmm_connector_hdmi_init(struct drm_device *dev, +int drm_connector_hdmi_dynamic_init (struct drm_device *dev, +struct drm_connector *connector, +const char *vendor,const char *product, +const struct drm_connector_funcs *funcs, +const struct drm_connector_hdmi_funcs *hdmi_funcs, +int connector_type, +struct i2c_adapter *ddc, +unsigned long supported_formats, +unsigned int max_bpc) +{ +int ret; + + ret = drm_connector_hdmi_sanity_checks(connector, vendor, product, hdmi_funcs,
drivers/gpu/drm/drm_connector.c int drmm_connector_hdmi_init(struct drm_device *dev, · line 680
Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10
-0+ connector_type, supported_formats, max_bpc); +if (ret) +return ret; + + ret =drm_connector_dynamic_init (dev, connector, funcs, connector_type, ddc); +if (ret) +return ret; + +drm_connector_hdmi_init (connector, vendor, product, + hdmi_funcs, supported_formats, max_bpc);
Could this lead to a NULL pointer dereference under memory pressure? I realize this behavior pre-exists in drmm_connector_hdmi_init(), but the new dynamic variant exposes the same pattern.
Looking at drm_connector_hdmi_init():
static void drm_connector_hdmi_init(...)
{
...
if (connector->funcs->reset)
connector->funcs->reset(connector);
drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
}For atomic drivers, the reset callback allocates connector->state, but since it returns void, allocation failures are silent and connector->state remains NULL.
The subsequent call to drm_connector_attach_max_bpc_property() then unconditionally dereferences it:
connector->state->max_requested_bpc = max;
Would it be safer to verify connector->state is allocated after the reset callback before continuing?
Quoted 4 lines
drivers/gpu/drm/drm_connector.c +4
-0+ +return 0 ; +} +EXPORT_SYMBOL (drm_connector_hdmi_dynamic_init);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Luca Ceresoli
reviewerPATCH 3/37 drm/display: bridge-connector: rename variable for consistency
In reply to Luca CeresoliAll struct drm_bridge_connector pointers are called bridge_connector except this one. Rename it for consistency.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -2
@@ -153,10 +153,10 @@ static void drm_bridge_connector_hpd_notify(struct drm_connector *connector, } } -static void drm_bridge_connector_handle_hpd (struct drm_bridge_connector *drm_bridge_connector, +static void drm_bridge_connector_handle_hpd (struct drm_bridge_connector *bridge_connector,enum drm_connector_status status) { -struct drm_connector *connector = &drm_bridge_connector->base; +struct drm_connector *connector = &bridge_connector->base;struct drm_device *dev = connector->dev;mutex_lock (&dev->mode_config.mutex);
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 4/37 drm/display: bridge-connector: store the drm_device pointer
In reply to Luca CeresoliCurrently the struct drm_device pointer is only needed during the initial drm_bridge_connector_init() and in drm_bridge_connector_handle_hpd() which gets it from the struct drm_connector.
This will be insufficient when introducing bridge hotplugging, because:
* some of the actions in drm_bridge_connector_init() will have to be performed later on, when a bridge is hot(un)plugged
* the connector will be removed and re-added based on hotplug events, so the drm_connector might just not exist or its content be cleared
Store the drm_device pointer in struct drm_bridge_connector for any later needs. Also convert drm_bridge_connector_handle_hpd() to use the newly stored value.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_bridge_connector.c +6 -1
@@ -60,6 +60,10 @@ struct drm_bridge_connector {* @base: The base DRM connector */ struct drm_connector base; +/** +* @drm: The DRM device we belong to +*/ +struct drm_device *drm;/** * @encoder: *
@@ -157,7 +161,7 @@ static void drm_bridge_connector_handle_hpd(struct drm_bridge_connector *bridge_ enum drm_connector_status status) {struct drm_connector *connector = &bridge_connector->base; -struct drm_device *dev = connector->dev; +struct drm_device *dev = bridge_connector->drm;mutex_lock (&dev->mode_config.mutex); connector->status = status;
@@ -806,6 +810,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (ret)return ERR_PTR (ret); + bridge_connector->drm = drm; bridge_connector->encoder = encoder;/*
Signature · 1 line
2.54.0
Maxime Ripard
maintainerRe: [PATCH 04/37] drm/display: bridge-connector: store the drm_device pointer
Hi,
Quoted 11 lines · Luca Ceresoli
Currently the struct
drm_devicepointer is only needed during the initialdrm_bridge_connector_init()and indrm_bridge_connector_handle_hpd()which gets it from the structdrm_connector.This will be insufficient when introducing bridge hotplugging, because:
* some of the actions in
drm_bridge_connector_init()will have to be performed later on, when a bridge is hot(un)plugged
* the connector will be removed and re-added based on hotplug events, so thedrm_connectormight just not exist or its content be cleared
Quoted 5 lines
Store the
drm_devicepointer in structdrm_bridge_connectorfor any later needs. Also convertdrm_bridge_connector_handle_hpd()to use the newly stored value.Signed-off-by Luca Ceresoli <[email protected]>
This is already accessible as drm_connector->dev and drm_bridge->dev. I think it would be great to list why this is different, and how it is different (ie, when it's set, unset).
Maxime
Luca Ceresoli
reviewerRe: [PATCH 04/37] drm/display: bridge-connector: store the drm_device pointer
Quoted 18 lines · Maxime Ripard
Hi,
Quoted 15 lines · Luca Ceresoli
Currently the struct
drm_devicepointer is only needed during the initialdrm_bridge_connector_init()and indrm_bridge_connector_handle_hpd()which gets it from the structdrm_connector.This will be insufficient when introducing bridge hotplugging, because:
* some of the actions in
drm_bridge_connector_init()will have to be performed later on, when a bridge is hot(un)plugged
* the connector will be removed and re-added based on hotplug events, so thedrm_connectormight just not exist or its content be clearedStore the
drm_devicepointer in structdrm_bridge_connectorfor any later needs. Also convertdrm_bridge_connector_handle_hpd()to use the newly stored value.
Quoted 5 lines
Quoted 1 line
Signed-off-by Luca Ceresoli <[email protected]>This is already accessible as
drm_connector->devanddrm_bridge->dev. I think it would be great to list why this is different, and how it is different (ie, when it's set, unset).
With hotplug the drm_connector will be created dynamically, so it cannot be used.
The drm_bridge->dev maybe.
But we have a pointer to the encoder, which is supposed to be always present, so I'll try using next for v2.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 5/37 drm/display: bridge-connector: split code creating the connector to a subfunction
In reply to Luca CeresoliIn preparation to introduce bridge hotplug, split out from drm_bridge_connector_init() the code adding the drm_connector into a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.
No functional changes. Just moving code around.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 81 ++++++++++++++++---------- 1 file changed, 50 insertions(+), 31 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +50 -31
@@ -773,26 +773,19 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data) }/** -* drm_bridge_connector_init - Initialise a connector for a chain of bridges -* @drm: the DRM device -* @encoder: the encoder where the bridge chain starts -* -* Create a new &drm_bridge_connector for the @drm device. The connector is -* allocated, initialised, registered with the @drm device and attached to -* @encoder. +* drm_bridge_connector_add_connector - add the drm_connector +* @bridge_connector: drm_bridge_connector to add the drm_connector to * -* The connector is associated with a chain of bridges that starts at -* the @encoder. All bridges in the chain shall report bridge operation flags -* (&drm_bridge->ops) and bridge output type (&drm_bridge->type), and none of -* them may create a DRM connector directly. +* Preconditions: the drm_bridge_connector is initialized (the +* @bridge_connector->drm and @bridge_connector->encoder fields are +* assigned at least) * -* Returns a pointer to the new connector on success, or a negative error -* pointer otherwise. +* Returns a pointer to the new drm_connector on success, or a negative +* error pointer otherwise. */ -struct drm_connector *drm_bridge_connector_init (struct drm_device *drm, -struct drm_encoder *encoder) +static struct drm_connector * +drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) { -struct drm_bridge_connector *bridge_connector;struct drm_connector *connector;struct i2c_adapter *ddc =NULL ; struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL;
@@ -802,17 +795,6 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,int connector_type;int ret; - bridge_connector =drmm_kzalloc (drm,sizeof (*bridge_connector),GFP_KERNEL ); -if (!bridge_connector) -return ERR_PTR (-ENOMEM ); - - ret =drmm_add_action (drm, drm_bridge_connector_put_bridges, bridge_connector); -if (ret) -return ERR_PTR (ret); - - bridge_connector->drm = drm; - bridge_connector->encoder = encoder; -/* * TODO: Handle doublescan_allowed and stereo_allowed. */
@@ -828,7 +810,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,* detection are available, we don't support hotplug detection at all. */ connector_type = DRM_MODE_CONNECTOR_Unknown; -drm_for_each_bridge_in_chain_scoped (encoder, bridge) { +drm_for_each_bridge_in_chain_scoped (bridge_connector->encoder, bridge) {if (!bridge->interlace_allowed) connector->interlace_allowed = false;if (!bridge->ycbcr_420_allowed)
@@ -984,7 +966,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, bridge_connector->hdmi_funcs.spd = drm_bridge_connector_hdmi_spd_infoframe; - ret = drmm_connector_hdmi_init(drm, connector, + ret = drmm_connector_hdmi_init(bridge_connector->drm, connector, bridge_connector->bridge_hdmi->vendor, bridge_connector->bridge_hdmi->product, &drm_bridge_connector_funcs,
@@ -995,7 +977,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (ret)return ERR_PTR (ret); }else { - ret =drmm_connector_init (drm, connector, + ret =drmm_connector_init (bridge_connector->drm, connector, &drm_bridge_connector_funcs, connector_type, ddc);if (ret)
@@ -1063,10 +1045,47 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, IS_ENABLED(CONFIG_DRM_DISPLAY_HDCP_HELPER))drm_connector_attach_content_protection_property (connector, true); - ret =drm_connector_attach_encoder (connector, encoder); + ret =drm_connector_attach_encoder (connector, bridge_connector->encoder);if (ret)return ERR_PTR (ret);return connector; } + +/** +* drm_bridge_connector_init - Initialise a connector for a chain of bridges +* @drm: the DRM device +* @encoder: the encoder where the bridge chain starts +* +* Create a new &drm_bridge_connector for the @drm device. The connector is +* allocated, initialised, registered with the @drm device and attached to +* @encoder. +* +* The connector is associated with a chain of bridges that starts at +* the @encoder. All bridges in the chain shall report bridge operation flags +* (&drm_bridge->ops) and bridge output type (&drm_bridge->type), and none of +* them may create a DRM connector directly. +* +* Returns a pointer to the new connector on success, or a negative error +* pointer otherwise. +*/ +struct drm_connector *drm_bridge_connector_init (struct drm_device *drm, +struct drm_encoder *encoder) +{ +struct drm_bridge_connector *bridge_connector; +int ret; + + bridge_connector =drmm_kzalloc (drm,sizeof (*bridge_connector),GFP_KERNEL ); +if (!bridge_connector) +return ERR_PTR (-ENOMEM ); + + ret =drmm_add_action (drm, drm_bridge_connector_put_bridges, bridge_connector); +if (ret) +return ERR_PTR (ret); + + bridge_connector->drm = drm; + bridge_connector->encoder = encoder; + +return drm_bridge_connector_add_connector (bridge_connector); +}EXPORT_SYMBOL_GPL (drm_bridge_connector_init);
Signature · 1 line
2.54.0
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.
Same story here, explaining what you need later on that calls for that change would be nice.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently drm_bridge_connector_init() does two things:
* allocate and initialize the drm_bridge_connector (which embeds a drm_connector)
* initialize and register the embedded drm_connector
For bridge hotplug we need to separate these two actions:
* the drm_connector needs to be added and removed at any time based on hotplug events
* the drm_bridge_connector is designated to create and remove the drm_connector, so it must be persistent for the card lifetime
As the lifetimes of drm_bridge_connector and drm_connector become different, we need to create them in different moments.
In preparation to support that, split out from drm_bridge_connector_init() the code adding the drm_connector into a dedicated function. No functional changes, just moving code around for now. A future commit will make the drm_connector be created based on hotplug events.
Looks good?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.
Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect drm_bridge_connector to stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?
Maxime
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?
In your example, the HDMI drm_connector would be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDS drm_connector will be created and registered.
Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?
As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED) [patch 36]
-> drm_bridge_connector_dynconn_release() [patch 15]
Does this solve your concern?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 60 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
Quoted 6 lines
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Does this solve your concern?
Not really, I'm talking about drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact that drm_bridge_connector sticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector, drm_bridge_connector doesn't have a reason to exist anymore, unless it's drm_bridge_hotplug in a trench coat :)
Maxime
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Hi Maxime,
Quoted 66 lines · Maxime Ripard
Quoted 65 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]
Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)
It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "a drm_bridge is either a bridge or something else". :)
But let's leave names aside for a moment. If just looking at the current code, the drm_bridge_connector is "a handler, owned by the card/encoder and having the same lifetime, which takes care of drm_connector creation/destruction at card probe/removal".
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Now, the reason I chose to extend the drm_bridge_connector to achieve the above is what I tried to motivate in the cover letter:
Quoted 11 lines
The
drm_bridge_connectoris nowadays the recommended way to implement DRM connectors when a chain of bridges is used. It takes care of adding thedrm_connectorwhen the pipeline is composed by an arbitrarily long chain of bridges, which it scans to properly implement thedrm_connectoroperations.As such the
drm_bridge_connectorlooked like the ideal component to implement DRM bridge hotplug.This series augments the
drm_bridge_connectorcode to be able to create and destroy thedrm_connectorreacting on hot(un)plug events.
Before taking that approach I considered some options:
1. Create a new component, which is a "a handler, owned by the card/encoder and having the same lifetime, which takes care of drm_connector creation/destruction at card probe/removal and on hotplug events", and wait for drivers to migrate from the drm_bridge_connector to this new thing
2. Create a new component, which is a "handler, owned by the card/encoder and having the same lifetime, which reacts to hotplug events by creating/destroying a drm_bridge_connector (slightly modified to be non-drmm), which in turn takes care of drm_connector creation/destruction", and wait for drivers to migrate to this new thing
3. Extend the dm_bridge_connector to:
- behave as before if using the current API
- behave as before + hotplug if using a new API (the migration in most cases is as simple as patch 37)
All 3 options require changes in card drivers to use a new API (and a new object type for cases 1 and 2).
To me options 1 and 2 involve more redundant code and/or more complexity.
Your thoughts?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 91 lines · Luca Ceresoli
Hi Maxime,
Quoted 66 lines · Maxime Ripard
Quoted 65 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".
Quoted 5 lines
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name. drm_bridge_connector for something that is neither a bridge or a connector is not great.
But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not. Use that property in attach to either create a drm_bridge_connector instance if you're last, or attach the next bridge if you aren't.
And when a bridge is removed, drop everything after it in the chain, drm_bridge_connector instance included.
And the encoder can take care of handling bridge remove and tearing down the bridge chain itself.
Maximex
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 92 lines · Maxime Ripard
Quoted 91 lines · Luca Ceresoli
Hi Maxime,
Quoted 66 lines · Maxime Ripard
Quoted 65 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".
Quoted 7 lines
Quoted 5 lines
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name.
drm_connector_manager?drm_bridge_connector_manager?
Quoted 8 lines
drm_bridge_connectorfor something that is neither a bridge or a connector is not great.But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not. Use that property in attach to either create a
drm_bridge_connectorinstance if you're last, or attach the next bridge if you aren't.
What? o_O
Several encoder drivers have been painfully converted to create a drm_bridge_connector. Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the drm_bridge_connector from there?
I must be missing something. Can you elaborate on this?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Laurent Pinchart
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 91 lines · Luca Ceresoli
Quoted 90 lines · Maxime Ripard
Quoted 89 lines · Luca Ceresoli
Quoted 64 lines · Maxime Ripard
Quoted 63 lines · Luca Ceresoli
Quoted 37 lines · Maxime Ripard
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".What we need now is just the same plug " and on hotplug events" appended.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name.
drm_connector_manager?drm_bridge_connector_manager?
I'm fine with a rename. When developing drm_bridge_connector I've always envisioned it as code that manages the creation of a connector for a chain of bridges. In particular, the drm_bridge_connector object is *not* and has never been a bridge.
Ideally all this should move to the DRM core and be transparent to drivers. Drivers could set a flag somewhere to opt-in for connectors managed by the DRM core.
Quoted 6 lines
Quoted 6 lines
drm_bridge_connectorfor something that is neither a bridge or a connector is not great.But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not.
I don't think bridges should be aware of whether or not they're the last one in the chain.
Quoted 12 lines
Quoted 3 lines
Use that property in attach to either create a
drm_bridge_connectorinstance if you're last, or attach the next bridge if you aren't.What?
o_OSeveral encoder drivers have been painfully converted to create a
drm_bridge_connector. Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all thedrm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
Signature · 3 lines
Regards, Laurent Pinchart
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 98 lines · Laurent Pinchart
Quoted 97 lines · Luca Ceresoli
Quoted 95 lines · Maxime Ripard
Quoted 87 lines · Luca Ceresoli
Quoted 64 lines · Maxime Ripard
Quoted 63 lines · Luca Ceresoli
Quoted 37 lines · Maxime Ripard
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".Quoted 5 lines
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name.
Quoted 7 lines
Quoted 2 lines
drm_connector_manager?drm_bridge_connector_manager?I'm fine with a rename. When developing
drm_bridge_connectorI've always envisioned it as code that manages the creation of a connector for a chain of bridges. In particular, thedrm_bridge_connectorobject is *not* and has never been a bridge.
That's my understanding of the drm_bridge_connector too.
Quoted 3 lines
Ideally all this should move to the DRM core and be transparent to drivers. Drivers could set a flag somewhere to opt-in for connectors managed by the DRM core.
Not sure I got what you mean.
Currently drivers "opt-in" by:
1. passing DRM_BRIDGE_ATTACH_NO_CONNECTOR to drm_bridge_attach()
2. instantiating a drm_bridge_connector via drm_bridge_connector_init()
Do you suggest changing that, so 1 and 2 are done transparently if the driver sets a new flag?
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
drm_bridge_connectorfor something that is neither a bridge or a connector is not great.But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not.
I don't think bridges should be aware of whether or not they're the last one in the chain.
I proposed that, not because I "want" that but because for hotplug we need a way to know whether a DRM video pipeline is complete in the hardware or not. This is used in patch 36:
/* Add the connector if the pipeline is now complete */ if (drm_bridge_connector_pipeline_is_complete(bridge_connector)) drm_bridge_connector_add_connector(bridge_connector);
In other words, on a hotplug event (some new hardware was added), check whether the card is now complete _in the hardware_, and if it is create a drm_connector.
In this series I proposed implementing it via a new .is_tail callback, that has been rejected during Dispaly Next Hackfest [0].
The idea that popped up there was that bridge drivers could expose the fwnode handler to the port@<N>/endpoint pointing to the next bridge. I liked the idea but then I realized it would hardly fly in complex cases like bridges with dual-LVDS-or-two-single-LVDS output, e.g. SN65DSI84.
So Maxime proposed [1]:
) Thanks for the notes, I think I largely agree with the discussion. ) Reading through it, I thought it would be nice for a new callback called ) get_next_bridge or something that would return either an error, NULL or a ) (refcounted) pointer to the next bridge in the chain. And have some kind ) of special error (ENODEV?) when the bridge should be there but isn't ) (and thus the chain isn't complete).
To me, "Making bridges aware if they are the last in the chain or not" is not a goal. It is just a technique to implement drm_bridge_connector_pipeline_is_complete(). I'm happy to implementing it in a different way if you have better ideas, but I haven't.
[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/20260624-vagabond-neon-gorilla-cd6487@houat/
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
In reply to Luca CeresoliQuoted 113 lines · Luca Ceresoli
Quoted 92 lines · Maxime Ripard
Quoted 91 lines · Luca Ceresoli
Hi Maxime,
Quoted 66 lines · Maxime Ripard
Quoted 65 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".Quoted 7 lines
Quoted 5 lines
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name.
drm_connector_manager?drm_bridge_connector_manager?Quoted 8 lines
drm_bridge_connectorfor something that is neither a bridge or a connector is not great.But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not. Use that property in attach to either create a
drm_bridge_connectorinstance if you're last, or attach the next bridge if you aren't.
Quoted 4 lines
What?
o_OSeveral encoder drivers have been painfully converted to create a
drm_bridge_connector.
I mean, it was done at a time where bridge hotplug wasn't a thing and the assumption was that the bridge chain is static. You're now breaking that assumption, it shouldn't come as a surprise that it might break other things.
And I know that you have experienced it already, which makes your reaction even more surprising to me :)
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
drm_bridge_connectors bring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.
What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the drm_bridge_connector when the chain is complete, and remove it when it's no longer the case.
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Maxime
Laurent Pinchart
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 131 lines · Maxime Ripard
Quoted 111 lines · Luca Ceresoli
Quoted 90 lines · Maxime Ripard
Quoted 89 lines · Luca Ceresoli
Quoted 66 lines · Maxime Ripard
Quoted 65 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".Quoted 7 lines
Quoted 5 lines
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name.
drm_connector_manager?drm_bridge_connector_manager?Quoted 8 lines
drm_bridge_connectorfor something that is neither a bridge or a connector is not great.But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not. Use that property in attach to either create a
drm_bridge_connectorinstance if you're last, or attach the next bridge if you aren't.Quoted 4 lines
What?
o_OSeveral encoder drivers have been painfully converted to create a
drm_bridge_connector.I mean, it was done at a time where bridge hotplug wasn't a thing and the assumption was that the bridge chain is static. You're now breaking that assumption, it shouldn't come as a surprise that it might break other things.
And I know that you have experienced it already, which makes your reaction even more surprising to me :)
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
Quoted 8 lines
drm_bridge_connectorsbring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the
drm_bridge_connectorwhen the chain is complete, and remove it when it's no longer the case.
That's an interesting option. We don't have to keep drm_bridge_connector in its current form, but I don't think we should go back to individual bridge driver creating connectors, especially now that we have bridge chains where the connector ops are implemented collectively by multiple bridges.
Quoted 2 lines
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Signature · 3 lines
Regards, Laurent Pinchart
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Hi Maxime, Laurent,
Quoted 115 lines · Laurent Pinchart
Quoted 114 lines · Maxime Ripard
Quoted 113 lines · Luca Ceresoli
Quoted 90 lines · Maxime Ripard
Quoted 89 lines · Luca Ceresoli
Quoted 66 lines · Maxime Ripard
Quoted 65 lines · Luca Ceresoli
Quoted 39 lines · Maxime Ripard
Hi,x
Quoted 28 lines · Luca Ceresoli
Quoted 8 lines · Maxime Ripard
Quoted 4 lines · Luca Ceresoli
In preparation to introduce bridge hotplug, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. This will be needed to be able to add (and re-add) the connector from different code paths.Same story here, explaining what you need later on that calls for that change would be nice.
Here's a more verbose version:
Currently
drm_bridge_connector_init()does two things:* allocate and initialize the
drm_bridge_connector(which embeds adrm_connector)
* initialize and register the embeddeddrm_connectorFor bridge hotplug we need to separate these two actions:
* the
drm_connectorneeds to be added and removed at any time based on hotplug events
* thedrm_bridge_connectoris designated to create and remove thedrm_connector, so it must be persistent for the card lifetimeAs the lifetimes of
drm_bridge_connectoranddrm_connectorbecome different, we need to create them in different moments.Quoted 7 lines
In preparation to support that, split out from
drm_bridge_connector_init()the code adding thedrm_connectorinto a dedicated function. No functional changes, just moving code around for now. A future commit will make thedrm_connectorbe created based on hotplug events.Looks good?
Quoted 8 lines
The message itself, yes, thanks.
However, I have questions now :)
Do we really expect
drm_bridge_connectorto stick around when a bridge gets unplugged? If so, how does it cope with having, say, an HDMI connector, and then swapping out the hotplugged part for an LVDS one? Does the HDMI connector sticks around indefinitely?In your example, the HDMI
drm_connectorwould be unregistered and put on hotunplug. Its allocation will stick around until the last put but that's quite irrelevant. Then, on plugging the LVDS addon, a new LVDSdrm_connectorwill be created and registered.Quoted 2 lines
*Especially* if we're using overlays for this, I'd expect everything
after the first hotplugged bridge to be destroyed, no?As said, it would be unregistered immediately but might be freed later on if still refcounted.
This is visible in patches 36+15, the path to follow is:
drm_bridge_connector_handle_event(event = DRM_BRIDGE_DETACHED)[patch 36]
->drm_bridge_connector_dynconn_release()[patch 15]Quoted 8 lines
Quoted 1 line
Does this solve your concern?
Not really, I'm talking about
drm_bridge_connector. The fact that bridges are destroyed make sense to me. The fact thatdrm_bridge_connectorsticks around doesn't. It's supposed to be a connector for bridges. If you don't have bridges because they got destroyed, and connector,drm_bridge_connectordoesn't have a reason to exist anymore, unless it'sdrm_bridge_hotplugin a trench coat :)It is not a hotplug-bridge in a trench coat, no :) The code is clear about this.
I'd say with this series a "
drm_bridge_connector" is just becoming something more (perhaps something else too). Somewhat as "adrm_bridgeis either a bridge or something else". :)But let's leave names aside for a moment. If just looking at the current code, the
drm_bridge_connectoris "a handler, owned by the card/encoder and having the same lifetime, which takes care ofdrm_connectorcreation/destruction at card probe/removal".Quoted 7 lines
Quoted 5 lines
What we need now is just the same plug " and on hotplug events" appended.
So in both cases there needs to be "a handler persitent with the card".
Do we agree so far?
Ish. If we go for that, then we need to update the name.
drm_connector_manager?drm_bridge_connector_manager?Quoted 8 lines
drm_bridge_connectorfor something that is neither a bridge or a connector is not great.But even then, I'm not even sure why we need to have that "manager" in the first place. You want to make bridges be aware if they are the last in the chain or not. Use that property in attach to either create a
drm_bridge_connectorinstance if you're last, or attach the next bridge if you aren't.What?
o_O
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Several encoder drivers have been painfully converted to create a
drm_bridge_connector.I mean, it was done at a time where bridge hotplug wasn't a thing and the assumption was that the bridge chain is static. You're now breaking that assumption, it shouldn't come as a surprise that it might break other things.
Sure adding a new requirement (hotplug) breaks the existing design. Still, this can be solved either by adding a new software component or by extending the existing software component (drm_bridge_connector) as this series proposes. None of the two ideas is wrong, so let's discuss which is best.
Quoted 2 lines
Quoted 2 lines
And I know that you have experienced it already, which makes your reaction even more surprising to me :)
Sure, the drm_bridge allocation was not refcounted and needed to be. And we didn't ditch the drm_bridge to create a new thing, we instead extended the existing software component (drm_bridge) to also be refcounted.
Quoted 15 lines
Quoted 6 lines
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
Quoted 8 lines
drm_bridge_connectorsbring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the
drm_bridge_connectorwhen the chain is complete, and remove it when it's no longer the case.
Quoted 5 lines
That's an interesting option. We don't have to keep
drm_bridge_connectorin its current form, but I don't think we should go back to individual bridge driver creating connectors, especially now that we have bridge chains where the connector ops are implemented collectively by multiple bridges.
I definitely agree we don't want to add burden back on the encoder.
Quoted 2 lines
Quoted 2 lines
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Bottom line, I roughly see three ideas mentioned:
1. (this series) extend the drm_bridge_connector to create the drm_connector based on bridge hotplug events [+rename it]
2. - keep the drm_bridge_connector (mostly) as is
- let each encoder driver add/remove it based on bridge hotplug events => more burden on encoder drivers -> no
3. - keep the drm_bridge_connector (mostly) as is
- add a new component (what name?) that will receive bridge hotplug events and react to them by adding/creating a drm_bridge_connector
- modify encoder drivers to create this new object instead of the drm_bridge_connector
In principle option 3 is the same as option 1, except it is split in two components.
I _think_ you both are discussing option 3. Correct?
If that's correct: any name suggested for the new component? drm_hotplug_manager? drm_connector_manager? drm_bridge_connector_manager?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 15 lines · Luca Ceresoli
Quoted 15 lines
Quoted 14 lines
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
drm_bridge_connectorsbring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the
drm_bridge_connectorwhen the chain is complete, and remove it when it's no longer the case.
Quoted 7 lines
Quoted 5 lines
That's an interesting option. We don't have to keep
drm_bridge_connectorin its current form, but I don't think we should go back to individual bridge driver creating connectors, especially now that we have bridge chains where the connector ops are implemented collectively by multiple bridges.I definitely agree we don't want to add burden back on the encoder.
I don't think Laurent mentioned the encoder anywhere.
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Bottom line, I roughly see three ideas mentioned:
1. (this series) extend the
drm_bridge_connectorto create thedrm_connectorbased on bridge hotplug events [+rename it]
2. - keep thedrm_bridge_connector(mostly) as is
- let each encoder driver add/remove it based on bridge hotplug events => more burden on encoder drivers -> no
Can you motivate that with *any* reason? Because I really feel like it's the best solution going forward.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Hi Maxime,
Quoted 22 lines · Maxime Ripard
Quoted 21 lines · Luca Ceresoli
Quoted 20 lines
Quoted 6 lines
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
Quoted 8 lines
drm_bridge_connectorsbring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the
drm_bridge_connectorwhen the chain is complete, and remove it when it's no longer the case.That's an interesting option. We don't have to keep
drm_bridge_connectorin its current form, but I don't think we should go back to individual bridge driver creating connectors, especially now that we have bridge chains where the connector ops are implemented collectively by multiple bridges.
Quoted 3 lines
Quoted 1 line
I definitely agree we don't want to add burden back on the encoder.
I don't think Laurent mentioned the encoder anywhere.
Ah, indeed, sorry! However, I think both the bridges and the encoder drivers should equally have the minimum burden on them.
Right now the recommended practice is:
- bridges do not create connectors (thanks to DRM_BRIDGE_ATTACH_NO_CONNECTOR)
- encoders just call drm_bridge_connector_init(), which does all the common operations to populate a suitable drm_connector
So all common operations involved in connector creation and bridge chain analysis are implemented in common code, not per-bridge or per-encoder. That's good.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Bottom line, I roughly see three ideas mentioned:
Quoted 8 lines
Quoted 5 lines
1. (this series) extend the
drm_bridge_connectorto create thedrm_connectorbased on bridge hotplug events [+rename it]
2. - keep thedrm_bridge_connector(mostly) as is
- let each encoder driver add/remove it based on bridge hotplug events => more burden on encoder drivers -> noCan you motivate that with *any* reason? Because I really feel like it's the best solution going forward.
My understanding of your idea (maybe a bit overstressed just to ensure it's clear) is that:
- the drm_bridge_connector should stay (almost) unmodified
- there should be no new "manager" component (not sure this is actually your opinion, can you comment on this specifically?)
- every encoder driver would have to:
- register to receive hotplug events
- when receiving one such event, find out whether the hardware is complete or not (by calling drm_bridge_connector_pipeline_is_complete() or so)
- create/destroy a drm_bridge_connector based on hotplug events
Is this somewhat close to what you have in mind?
To me the best solution to add hotplug support is that encoder drivers replace the single drm_bridge_connector_init() call with a single call to something new (let's call it a hotplug manager), which takes care of all the common aspects: registering to receive bridge hotplug events, finding out whether the hardware pipeline is complete or not, and add/remove the drm_connector based on that.
In other words, the changes on encoder drivers would be similar to patch
37. In a nutshell:
- connector = drm_bridge_connector_init(lcdif->drm, encoder); + drm_hotplug_manager = drm_hotplug_manager_init(lcdif->drm, encoder);
All the hotplug logic would be in common code, and any maintenance and future improvements to it would stay in a single place, benefitting all encoders at once.
What do you think about this?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Quoted 34 lines · Luca Ceresoli
Hi Maxime,
Quoted 22 lines · Maxime Ripard
Quoted 21 lines · Luca Ceresoli
Quoted 20 lines
Quoted 6 lines
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
Quoted 8 lines
drm_bridge_connectorsbring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the
drm_bridge_connectorwhen the chain is complete, and remove it when it's no longer the case.That's an interesting option. We don't have to keep
drm_bridge_connectorin its current form, but I don't think we should go back to individual bridge driver creating connectors, especially now that we have bridge chains where the connector ops are implemented collectively by multiple bridges.Quoted 3 lines
Quoted 1 line
I definitely agree we don't want to add burden back on the encoder.
I don't think Laurent mentioned the encoder anywhere.
Ah, indeed, sorry! However, I think both the bridges and the encoder drivers should equally have the minimum burden on them.
Right now the recommended practice is:
Quoted 7 lines
- bridges do not create connectors (thanks to
DRM_BRIDGE_ATTACH_NO_CONNECTOR)
- encoders just calldrm_bridge_connector_init(), which does all the common operations to populate a suitabledrm_connectorSo all common operations involved in connector creation and bridge chain analysis are implemented in common code, not per-bridge or per-encoder. That's good.
I agree, but another way to phrase it is: bridges aren't aware of how the chain is setup, the encoder ties it all together.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Bottom line, I roughly see three ideas mentioned:
1. (this series) extend the
drm_bridge_connectorto create thedrm_connectorbased on bridge hotplug events [+rename it]
2. - keep thedrm_bridge_connector(mostly) as is
- let each encoder driver add/remove it based on bridge hotplug events => more burden on encoder drivers -> no
Quoted 7 lines
Quoted 2 lines
Can you motivate that with *any* reason? Because I really feel like it's the best solution going forward.
My understanding of your idea (maybe a bit overstressed just to ensure it's clear) is that:
- the
drm_bridge_connectorshould stay (almost) unmodified
Yes, and bridges should ideally remain as lightly affected as possible. We have probably around 100 bridge drivers at the moment, having some kind of opt-in to enable hotplug would mean that we can't expect hotplug to work on a new platform, which should be a last resort.
Quoted 10 lines
- there should be no new "manager" component (not sure this is actually your opinion, can you comment on this specifically?)
- every encoder driver would have to:
- register to receive hotplug events
- when receiving one such event, find out whether the hardware is complete or not (by callingdrm_bridge_connector_pipeline_is_complete()or so)
- create/destroy adrm_bridge_connectorbased on hotplug eventsIs this somewhat close to what you have in mind?
Yes. To make things a bit more precise, we need two things: the encoder to put the chain together, and "something" (that you used to call manager) to react to hotplug events and handle the bridge detach/destruction, connector creation/destruction, etc and should stick around when we enable hotplug.
What I'm suggesting is that, since the encoder already owns and creates the chain in the first place, and is there forever, it's only natural for the encoder to be that "something", and we don't necessarily mean creating a new entity or piece of code. A bunch of helpers and hooks a probably going to be enough.
This is where the opt-in part should be, and I'd like, if possible, for hotplug-enabled encoders to work with any bridge.
Quoted 10 lines
To me the best solution to add hotplug support is that encoder drivers replace the single
drm_bridge_connector_init()call with a single call to something new (let's call it a hotplug manager), which takes care of all the common aspects: registering to receive bridge hotplug events, finding out whether the hardware pipeline is complete or not, and add/remove thedrm_connectorbased on that.In other words, the changes on encoder drivers would be similar to patch
37. In a nutshell:
Quoted 8 lines
- connector = drm_bridge_connector_init(lcdif->drm, encoder); + drm_hotplug_manager = drm_hotplug_manager_init(lcdif->drm, encoder);All the hotplug logic would be in common code, and any maintenance and future improvements to it would stay in a single place, benefitting all encoders at once.
What do you think about this?
From a high level point-of-view, I think we mostly agree. We can argue on the name, and if we should merge it with something else (drm_encoder_init, drm_bridge_attach, something else?) but that's the path forward I think.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction
Hi Maxime,
Quoted 60 lines · Maxime Ripard
Quoted 34 lines · Luca Ceresoli
Hi Maxime,
Quoted 22 lines · Maxime Ripard
Quoted 21 lines · Luca Ceresoli
Quoted 20 lines
Quoted 6 lines
Quoted 5 lines
Now if the bridges start doing it themselves we should go back to those encoder drivers and ditch all the
drm_bridge_connectorfrom there?I must be missing something. Can you elaborate on this?
Quoted 8 lines
drm_bridge_connectorsbring together a (complete) bridge chain and a connector. If you don't have either anymore, then we shouldn't keep it around.What I was suggesting before was only a suggestion. I guess we could also make the encoder own the hotplug handling code and create the
drm_bridge_connectorwhen the chain is complete, and remove it when it's no longer the case.That's an interesting option. We don't have to keep
drm_bridge_connectorin its current form, but I don't think we should go back to individual bridge driver creating connectors, especially now that we have bridge chains where the connector ops are implemented collectively by multiple bridges.Quoted 3 lines
Quoted 1 line
I definitely agree we don't want to add burden back on the encoder.
I don't think Laurent mentioned the encoder anywhere.
Ah, indeed, sorry! However, I think both the bridges and the encoder drivers should equally have the minimum burden on them.
Right now the recommended practice is:
Quoted 7 lines
- bridges do not create connectors (thanks to
DRM_BRIDGE_ATTACH_NO_CONNECTOR)
- encoders just calldrm_bridge_connector_init(), which does all the common operations to populate a suitabledrm_connectorSo all common operations involved in connector creation and bridge chain analysis are implemented in common code, not per-bridge or per-encoder. That's good.
I agree, but another way to phrase it is: bridges aren't aware of how the chain is setup, the encoder ties it all together.
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
We can discuss alternatives too. But either way, we shouldn't have it stick around.
Bottom line, I roughly see three ideas mentioned:
1. (this series) extend the
drm_bridge_connectorto create thedrm_connectorbased on bridge hotplug events [+rename it]
2. - keep thedrm_bridge_connector(mostly) as is
- let each encoder driver add/remove it based on bridge hotplug events => more burden on encoder drivers -> noCan you motivate that with *any* reason? Because I really feel like it's the best solution going forward.
Quoted 6 lines
Quoted 4 lines
My understanding of your idea (maybe a bit overstressed just to ensure it's clear) is that:
- the
drm_bridge_connectorshould stay (almost) unmodifiedYes, and bridges should ideally remain as lightly affected as possible.
I fully agree.
Quoted 3 lines
We have probably around 100 bridge drivers at the moment, having some kind of opt-in to enable hotplug would mean that we can't expect hotplug to work on a new platform, which should be a last resort.
A few changes to each bridge wanting to support hotplug will unavoidably be needed. The .get_next_bridge callback we mentioned in the discussion for patch 30 at least. I'm keeping any other changes, if any, to a minimum.
Quoted 17 lines
Quoted 10 lines
- there should be no new "manager" component (not sure this is actually your opinion, can you comment on this specifically?)
- every encoder driver would have to:
- register to receive hotplug events
- when receiving one such event, find out whether the hardware is complete or not (by callingdrm_bridge_connector_pipeline_is_complete()or so)
- create/destroy adrm_bridge_connectorbased on hotplug eventsIs this somewhat close to what you have in mind?
Yes. To make things a bit more precise, we need two things: the encoder to put the chain together, and "something" (that you used to call manager) to react to hotplug events and handle the bridge detach/destruction, connector creation/destruction, etc and should stick around when we enable hotplug.
Quoted 5 lines
What I'm suggesting is that, since the encoder already owns and creates the chain in the first place, and is there forever, it's only natural for the encoder to be that "something", and we don't necessarily mean creating a new entity or piece of code. A bunch of helpers and hooks a probably going to be enough.
That's the idea I had reached too, yes. Except the "bunch of helpers and hooks" could be perhaps as small as one single helper function or little more.
Quoted 16 lines
This is where the opt-in part should be, and I'd like, if possible, for hotplug-enabled encoders to work with any bridge.
Quoted 13 lines
To me the best solution to add hotplug support is that encoder drivers replace the single
drm_bridge_connector_init()call with a single call to something new (let's call it a hotplug manager), which takes care of all the common aspects: registering to receive bridge hotplug events, finding out whether the hardware pipeline is complete or not, and add/remove thedrm_connectorbased on that.In other words, the changes on encoder drivers would be similar to patch
37. In a nutshell:- connector = drm_bridge_connector_init(lcdif->drm, encoder); + drm_hotplug_manager = drm_hotplug_manager_init(lcdif->drm, encoder);
Quoted 7 lines
Quoted 5 lines
All the hotplug logic would be in common code, and any maintenance and future improvements to it would stay in a single place, benefitting all encoders at once.
What do you think about this?
From a high level point-of-view, I think we mostly agree.
Good.
Quoted 4 lines
We can argue
on the name, and if we should merge it with something else (drm_encoder_init,drm_bridge_attach, something else?) but that's the path forward I think.
OK, let's see what I can come up with in v2.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 6/37 drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector
In reply to Luca CeresoliCurrently drm_bridge_connector_init() always returns the added connector or errors out. When adding bridge hotplug the bridge-connector can be successfully initialized without creating a connector, which can be added later when the pipeline will be complete.
For this the internal function drm_bridge_connector_add_connector() must be able to return a valid drm_bridge_connector even without any drm_connector.
In preparation to support bridge hotplug, change its return value to be the same drm_bridge_connector pointer it gets as input, or a PTR_ERR.
No functional changes, just changing an internal API.
Note the return value could now become an int (0 or negative error) because returning the same value received as input does not carry any added value. However this would be change a lot of lines, so leave such change as a future cleanup.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +9 -5
@@ -780,10 +780,10 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)* @bridge_connector->drm and @bridge_connector->encoder fields are * assigned at least) * -* Returns a pointer to the new drm_connector on success, or a negative -* error pointer otherwise. +* Returns a pointer to @bridge_connector on success, or a negative error +* pointer otherwise. */ -static struct drm_connector * +static struct drm_bridge_connector *drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) {struct drm_connector *connector;
@@ -1049,7 +1049,7 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connectorif (ret)return ERR_PTR (ret); -return connector; +return bridge_connector; }/**
@@ -1086,6 +1086,10 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, bridge_connector->drm = drm; bridge_connector->encoder = encoder; -return drm_bridge_connector_add_connector (bridge_connector); + bridge_connector =drm_bridge_connector_add_connector (bridge_connector); +if (IS_ERR (bridge_connector)) +return ERR_CAST (bridge_connector); + +return &bridge_connector->base; }EXPORT_SYMBOL_GPL (drm_bridge_connector_init);
Signature · 1 line
2.54.0
Maxime Ripard
maintainerRe: [PATCH 06/37] drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector
Quoted 11 lines · Luca Ceresoli
Currently
drm_bridge_connector_init()always returns the added connector or errors out. When adding bridge hotplug the bridge-connector can be successfully initialized without creating a connector, which can be added later when the pipeline will be complete.For this the internal function
drm_bridge_connector_add_connector()must be able to return a validdrm_bridge_connectoreven without anydrm_connector.In preparation to support bridge hotplug, change its return value to be the same
drm_bridge_connectorpointer it gets as input, or aPTR_ERR.
Quoted 6 lines
No functional changes, just changing an internal API.
Note the return value could now become an int (0 or negative error) because returning the same value received as input does not carry any added value. However this would be change a lot of lines, so leave such change as a future cleanup.
You just created that function and changed "a lot of lines" already, so I'm not sure that argument holds.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 06/37] drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector
Quoted 14 lines · Maxime Ripard
Quoted 13 lines · Luca Ceresoli
Currently
drm_bridge_connector_init()always returns the added connector or errors out. When adding bridge hotplug the bridge-connector can be successfully initialized without creating a connector, which can be added later when the pipeline will be complete.For this the internal function
drm_bridge_connector_add_connector()must be able to return a validdrm_bridge_connectoreven without anydrm_connector.In preparation to support bridge hotplug, change its return value to be the same
drm_bridge_connectorpointer it gets as input, or aPTR_ERR.No functional changes, just changing an internal API.
Quoted 7 lines
Quoted 4 lines
Note the return value could now become an int (0 or negative error) because returning the same value received as input does not carry any added value. However this would be change a lot of lines, so leave such change as a future cleanup.
You just created that function and changed "a lot of lines" already, so I'm not sure that argument holds.
Do you refer to the previous patch?
My comment is more about the following patches. It means I separated changes moving code to a subfunction from changes to the the return value in separate patches, so that each patch is trivial to review for correctness.
Makes sense?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 06/37] drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector
Quoted 23 lines · Luca Ceresoli
Quoted 14 lines · Maxime Ripard
Quoted 13 lines · Luca Ceresoli
Currently
drm_bridge_connector_init()always returns the added connector or errors out. When adding bridge hotplug the bridge-connector can be successfully initialized without creating a connector, which can be added later when the pipeline will be complete.For this the internal function
drm_bridge_connector_add_connector()must be able to return a validdrm_bridge_connectoreven without anydrm_connector.In preparation to support bridge hotplug, change its return value to be the same
drm_bridge_connectorpointer it gets as input, or aPTR_ERR.No functional changes, just changing an internal API.
Quoted 7 lines
Quoted 4 lines
Note the return value could now become an int (0 or negative error) because returning the same value received as input does not carry any added value. However this would be change a lot of lines, so leave such change as a future cleanup.
You just created that function and changed "a lot of lines" already, so I'm not sure that argument holds.
Quoted 8 lines
Do you refer to the previous patch?
My comment is more about the following patches. It means I separated changes moving code to a subfunction from changes to the the return value in separate patches, so that each patch is trivial to review for correctness.
Makes sense?
What confused me is that I took it as "I'm not going to do that work (yet?)". If you do it later on, I'd drop the "future cleanup" part, or rephrase it.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 06/37] drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector
Quoted 31 lines · Maxime Ripard
Quoted 30 lines · Luca Ceresoli
Quoted 14 lines · Maxime Ripard
Quoted 13 lines · Luca Ceresoli
Currently
drm_bridge_connector_init()always returns the added connector or errors out. When adding bridge hotplug the bridge-connector can be successfully initialized without creating a connector, which can be added later when the pipeline will be complete.For this the internal function
drm_bridge_connector_add_connector()must be able to return a validdrm_bridge_connectoreven without anydrm_connector.In preparation to support bridge hotplug, change its return value to be the same
drm_bridge_connectorpointer it gets as input, or aPTR_ERR.No functional changes, just changing an internal API.
Quoted 7 lines
Quoted 4 lines
Note the return value could now become an int (0 or negative error) because returning the same value received as input does not carry any added value. However this would be change a lot of lines, so leave such change as a future cleanup.
You just created that function and changed "a lot of lines" already, so I'm not sure that argument holds.
Do you refer to the previous patch?
My comment is more about the following patches. It means I separated changes moving code to a subfunction from changes to the the return value in separate patches, so that each patch is trivial to review for correctness.
Quoted 5 lines
Quoted 1 line
Makes sense?
What confused me is that I took it as "I'm not going to do that work (yet?)". If you do it later on, I'd drop the "future cleanup" part, or rephrase it.
Ah, I see the issue. I really meant "this change [returning int] is done in a following commit".
I guess I'll just drop the whole paragraph.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 7/37 drm/display: bridge-connector: extract drm_bridge_connector_get_bridges()
In reply to Luca CeresoliTo support bridge hotplug we will need better control over the steps involved in the crm_connector creation, especially in terms of error management. This will be complicated by the length and amount of return points in this function. In preparation, split the code to grab the various bridge pointers out to a separate function.
No functional changes. Just moving code around.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 86 +++++++++++++++----------- 1 file changed, 50 insertions(+), 36 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +50 -36
@@ -772,44 +772,24 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)drm_bridge_put (bridge_connector->bridge_hdmi_cec); } -/** -* drm_bridge_connector_add_connector - add the drm_connector -* @bridge_connector: drm_bridge_connector to add the drm_connector to -* -* Preconditions: the drm_bridge_connector is initialized (the -* @bridge_connector->drm and @bridge_connector->encoder fields are -* assigned at least) -* -* Returns a pointer to @bridge_connector on success, or a negative error -* pointer otherwise. -*/ static struct drm_bridge_connector * -drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) +drm_bridge_connector_get_bridges (struct drm_bridge_connector *bridge_connector, +int *connector_type, +unsigned int *supported_formats, +unsigned int *max_bpc, +struct i2c_adapter **ddc, +struct drm_bridge **panel_bridge, +bool *support_hdcp) { -struct drm_connector *connector; -struct i2c_adapter *ddc =NULL ; - struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL; -unsigned int supported_formats =BIT (DRM_OUTPUT_COLOR_FORMAT_RGB444 ); -unsigned int max_bpc =8 ; -bool support_hdcp = false; -int connector_type; -int ret; +struct drm_connector *connector = &bridge_connector->base;/* * TODO: Handle doublescan_allowed and stereo_allowed. */ - connector = &bridge_connector->base; connector->interlace_allowed = true; connector->ycbcr_420_allowed = true; + *connector_type = DRM_MODE_CONNECTOR_Unknown; -/* -* Initialise connector status handling. First locate the furthest -* bridges in the pipeline that support HPD and output detection. Then -* initialise the connector polling mode, using HPD if available and -* falling back to polling if supported. If neither HPD nor output -* detection are available, we don't support hotplug detection at all. -*/ - connector_type = DRM_MODE_CONNECTOR_Unknown;drm_for_each_bridge_in_chain_scoped (bridge_connector->encoder, bridge) {if (!bridge->interlace_allowed) connector->interlace_allowed = false;
@@ -865,9 +845,9 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector bridge_connector->bridge_hdmi =drm_bridge_get (bridge);if (bridge->supported_formats) - supported_formats = bridge->supported_formats; + *supported_formats = bridge->supported_formats;if (bridge->max_bpc) - max_bpc = bridge->max_bpc; + *max_bpc = bridge->max_bpc; }if (bridge->ops &DRM_BRIDGE_OP_HDMI_AUDIO ) {
@@ -926,7 +906,7 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector }if (drm_bridge_is_last (bridge)) - connector_type = bridge->type; + *connector_type = bridge->type;#ifdef CONFIG_OF if (drm_bridge_is_last (bridge) && bridge->of_node)
@@ -934,20 +914,54 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector#endif if (bridge->ddc) - ddc = bridge->ddc; + *ddc = bridge->ddc;if (drm_bridge_is_panel (bridge)) { -drm_bridge_put (panel_bridge); - panel_bridge =drm_bridge_get (bridge); +drm_bridge_put (*panel_bridge); + *panel_bridge =drm_bridge_get (bridge); }if (bridge->support_hdcp) - support_hdcp = true; + *support_hdcp = true; }if (connector_type == DRM_MODE_CONNECTOR_Unknown)return ERR_PTR (-EINVAL ); +return bridge_connector; +} + +/** +* drm_bridge_connector_add_connector - add the drm_connector +* @bridge_connector: drm_bridge_connector to add the drm_connector to +* +* Preconditions: the drm_bridge_connector is initialized (the +* @bridge_connector->drm and @bridge_connector->encoder fields are +* assigned at least) +* +* Returns a pointer to @bridge_connector on success, or a negative error +* pointer otherwise. +*/ +static struct drm_bridge_connector * +drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) +{ +struct drm_connector *connector; +struct i2c_adapter *ddc =NULL ; + struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL; +unsigned int supported_formats =BIT (DRM_OUTPUT_COLOR_FORMAT_RGB444 ); +unsigned int max_bpc =8 ; +bool support_hdcp = false; +int connector_type; +int ret; + + connector = &bridge_connector->base; + + bridge_connector =drm_bridge_connector_get_bridges (bridge_connector, &connector_type, + &supported_formats, &max_bpc, &ddc, + &panel_bridge, &support_hdcp); +if (IS_ERR (bridge_connector)) +return bridge_connector; +if (bridge_connector->bridge_hdmi) {if (!connector->ycbcr_420_allowed) supported_formats &= ~BIT (DRM_OUTPUT_COLOR_FORMAT_YCBCR420 );
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 07/37] drm/display: bridge-connector: extract drm_bridge_connector_get_bridges()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing pointer dereference when validating `connector_type`, causing the error check to be…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing pointer dereference when validating connector_type, causing the error check to be bypassed. --
commit 5a4cd30beb768eaba2369b4630833475535f79bf
Author: Luca Ceresoli <[email protected]>
drm/display: bridge-connector: extract drm_bridge_connector_get_bridges()
This commit splits out the code that gathers bridge pointers into a separate function to prepare for better bridge hotplug support.
Quoted 3 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0
[ ... ]
Quoted 11 lines
drivers/gpu/drm/display/drm_bridge_connector.c +7
-1@@ -772,44 +772,24 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)static struct drm_bridge_connector * -drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) +drm_bridge_connector_get_bridges (struct drm_bridge_connector *bridge_connector, +int *connector_type, +unsigned int *supported_formats, +unsigned int *max_bpc, +struct i2c_adapter **ddc, +struct drm_bridge **panel_bridge, +bool *support_hdcp) {
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector · line 929
Quoted 7 lines
drivers/gpu/drm/display/drm_bridge_connector.c +1
-1if (bridge->support_hdcp) - support_hdcp = true; + *support_hdcp = true; }if (connector_type == DRM_MODE_CONNECTOR_Unknown)return ERR_PTR (-EINVAL );
Is there a missing dereference on connector_type here?
Since connector_type is now an int pointer and DRM_MODE_CONNECTOR_Unknown is 0, this evaluates as a NULL pointer check rather than checking the value.
Because the address of a stack variable is passed to the function, the pointer is never NULL, so this check will always fail and bypass the error return.
Should this be checking *connector_type instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Luca Ceresoli
reviewerPATCH 8/37 drm/display: bridge-connector: return int from drm_bridge_connector_get_bridges()
In reply to Luca CeresoliThis function returns a struct drm_bridge_connector * because this was the case in the origin of its code. In current code it does not make sense
anymore: it can only return either the same pointer it received as input or a negative ERR_PTR.
Simplify up error management by just returning an int (0 or negative error).
No functional changes.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +30 -31
@@ -772,14 +772,13 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)drm_bridge_put (bridge_connector->bridge_hdmi_cec); } -static struct drm_bridge_connector * -drm_bridge_connector_get_bridges (struct drm_bridge_connector *bridge_connector, -int *connector_type, -unsigned int *supported_formats, -unsigned int *max_bpc, -struct i2c_adapter **ddc, -struct drm_bridge **panel_bridge, -bool *support_hdcp) +static int drm_bridge_connector_get_bridges (struct drm_bridge_connector *bridge_connector, +int *connector_type, +unsigned int *supported_formats, +unsigned int *max_bpc, +struct i2c_adapter **ddc, +struct drm_bridge **panel_bridge, +bool *support_hdcp) {struct drm_connector *connector = &bridge_connector->base;
@@ -820,27 +819,27 @@ drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector, }if (bridge->ops &DRM_BRIDGE_OP_HDMI ) {if (bridge_connector->bridge_hdmi) -return ERR_PTR (-EBUSY ); +return -EBUSY ;if (!bridge->funcs->hdmi_write_avi_infoframe || !bridge->funcs->hdmi_clear_avi_infoframe || !bridge->funcs->hdmi_write_hdmi_infoframe || !bridge->funcs->hdmi_clear_hdmi_infoframe) -return ERR_PTR (-EINVAL ); +return -EINVAL ;if (bridge->ops &DRM_BRIDGE_OP_HDMI_AUDIO && (!bridge->funcs->hdmi_write_audio_infoframe || !bridge->funcs->hdmi_clear_audio_infoframe)) -return ERR_PTR (-EINVAL ); +return -EINVAL ;if (bridge->ops &DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME && (!bridge->funcs->hdmi_write_hdr_drm_infoframe || !bridge->funcs->hdmi_clear_hdr_drm_infoframe)) -return ERR_PTR (-EINVAL ); +return -EINVAL ;if (bridge->ops &DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME && (!bridge->funcs->hdmi_write_spd_infoframe || !bridge->funcs->hdmi_clear_spd_infoframe)) -return ERR_PTR (-EINVAL ); +return -EINVAL ; bridge_connector->bridge_hdmi =drm_bridge_get (bridge);
@@ -852,57 +851,57 @@ drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector,if (bridge->ops &DRM_BRIDGE_OP_HDMI_AUDIO ) {if (bridge_connector->bridge_hdmi_audio) -return ERR_PTR (-EBUSY ); +return -EBUSY ;if (bridge_connector->bridge_dp_audio) -return ERR_PTR (-EBUSY ); +return -EBUSY ;if (!bridge->hdmi_audio_max_i2s_playback_channels && !bridge->hdmi_audio_spdif_playback) -return ERR_PTR (-EINVAL ); +return -EINVAL ;if (!bridge->funcs->hdmi_audio_prepare || !bridge->funcs->hdmi_audio_shutdown) -return ERR_PTR (-EINVAL ); +return -EINVAL ; bridge_connector->bridge_hdmi_audio =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_DP_AUDIO ) {if (bridge_connector->bridge_dp_audio) -return ERR_PTR (-EBUSY ); +return -EBUSY ;if (bridge_connector->bridge_hdmi_audio) -return ERR_PTR (-EBUSY ); +return -EBUSY ;if (!bridge->hdmi_audio_max_i2s_playback_channels && !bridge->hdmi_audio_spdif_playback) -return ERR_PTR (-EINVAL ); +return -EINVAL ;if (!bridge->funcs->dp_audio_prepare || !bridge->funcs->dp_audio_shutdown) -return ERR_PTR (-EINVAL ); +return -EINVAL ; bridge_connector->bridge_dp_audio =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER ) {if (bridge_connector->bridge_hdmi_cec) -return ERR_PTR (-EBUSY ); +return -EBUSY ; bridge_connector->bridge_hdmi_cec =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_HDMI_CEC_ADAPTER ) {if (bridge_connector->bridge_hdmi_cec) -return ERR_PTR (-EBUSY ); +return -EBUSY ; bridge_connector->bridge_hdmi_cec =drm_bridge_get (bridge);if (!bridge->funcs->hdmi_cec_enable || !bridge->funcs->hdmi_cec_log_addr || !bridge->funcs->hdmi_cec_transmit) -return ERR_PTR (-EINVAL ); +return -EINVAL ; }if (drm_bridge_is_last (bridge))
@@ -926,9 +925,9 @@ drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector, }if (connector_type == DRM_MODE_CONNECTOR_Unknown) -return ERR_PTR (-EINVAL ); +return -EINVAL ; -return bridge_connector; +return 0 ; }/**
@@ -956,11 +955,11 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector connector = &bridge_connector->base; - bridge_connector =drm_bridge_connector_get_bridges (bridge_connector, &connector_type, - &supported_formats, &max_bpc, &ddc, - &panel_bridge, &support_hdcp); -if (IS_ERR (bridge_connector)) -return bridge_connector; + ret =drm_bridge_connector_get_bridges (bridge_connector, &connector_type, + &supported_formats, &max_bpc, &ddc, + &panel_bridge, &support_hdcp); +if (ret) +return ERR_PTR (ret);if (bridge_connector->bridge_hdmi) {if (!connector->ycbcr_420_allowed)
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 08/37] drm/display: bridge-connector: return int from drm_bridge_connector_get_bridges()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The check `connector_type == DRM_MODE_CONNECTOR_Unknown` incorrectly compares a pointer to an…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The check connector_type == DRM_MODE_CONNECTOR_Unknown incorrectly compares a pointer to an integer constant (0) instead of dereferencing the pointer. --
commit c54583277f834cc9c4092e1b01aee8c02b7a7b4b
Author: Luca Ceresoli <[email protected]>
drm/display: bridge-connector: return int from drm_bridge_connector_get_bridges()
This commit simplifies the return value of drm_bridge_connector_get_bridges() to return a standard integer (0 or negative error code) instead of returning a struct drm_bridge_connector pointer or an error pointer.
Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector, · line 927
Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0@@ -926,9 +925,9 @@ drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector, }if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Does this condition check the value or the pointer?
Since connector_type is passed as an int * and DRM_MODE_CONNECTOR_Unknown evaluates to 0, this acts as a NULL check on the pointer itself rather than checking the integer value.
Because the caller passes the address of a local stack variable (&connector_type), this condition will always evaluate to false, meaning the unknown connector type validation is dead code.
Should this be checking *connector_type instead?
While this logic error wasn't introduced by this specific patch, it was likely exposed during the recent refactoring that extracted this function. Since this patch modifies the return statement immediately below the condition, it might be a good opportunity to fix the check.
Quoted 6 lines
drivers/gpu/drm/display/drm_bridge_connector.c +2
-2-return ERR_PTR (-EINVAL ); +return -EINVAL ; -return bridge_connector; +return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Luca Ceresoli
reviewerPATCH 9/37 drm/display: bridge-connector: extract drm_bridge_connector_init_hdmi_audio_cec()
In reply to Luca CeresoliTo support bridge hotplug we will need better control over the steps involved in the crm_connector creation, especially in terms of error management. This will be complicated by the length and amount of return points in this function. In preparation, split the code to initialize HDMI audio and CEC fields out to a separate function.
No functional changes. Just moving code around.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 102 ++++++++++++++----------- 1 file changed, 57 insertions(+), 45 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +57 -45
@@ -930,6 +930,60 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_return 0 ; } +static struct drm_bridge_connector * +drm_bridge_connector_init_hdmi_audio_cec (struct drm_bridge_connector *bridge_connector) +{ +int ret; + +if (bridge_connector->bridge_hdmi_audio || + bridge_connector->bridge_dp_audio) { +struct device *dev; +struct drm_bridge *bridge; + +if (bridge_connector->bridge_hdmi_audio) + bridge = bridge_connector->bridge_hdmi_audio; +else + bridge = bridge_connector->bridge_dp_audio; + + dev = bridge->hdmi_audio_dev; + + ret =drm_connector_hdmi_audio_init (&bridge_connector->base, dev, + &drm_bridge_connector_hdmi_audio_funcs, + bridge->hdmi_audio_max_i2s_playback_channels, + bridge->hdmi_audio_i2s_formats, + bridge->hdmi_audio_spdif_playback, + bridge->hdmi_audio_dai_port); +if (ret) +return ERR_PTR (ret); + } + +if (bridge_connector->bridge_hdmi_cec && + bridge_connector->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER ) { +struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; + + ret =drmm_connector_hdmi_cec_notifier_register (&bridge_connector->base, +NULL , + bridge->hdmi_cec_dev); +if (ret) +return ERR_PTR (ret); + } + +if (bridge_connector->bridge_hdmi_cec && + bridge_connector->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_ADAPTER ) { +struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; + + ret =drmm_connector_hdmi_cec_register (&bridge_connector->base, + &drm_bridge_connector_hdmi_cec_funcs, + bridge->hdmi_cec_adapter_name, + bridge->hdmi_cec_available_las, + bridge->hdmi_cec_dev); +if (ret) +return ERR_PTR (ret); + } + +return bridge_connector; +} +/** * drm_bridge_connector_add_connector - add the drm_connector * @bridge_connector: drm_bridge_connector to add the drm_connector to
@@ -997,51 +1051,9 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connectorreturn ERR_PTR (ret); } -if (bridge_connector->bridge_hdmi_audio || - bridge_connector->bridge_dp_audio) { -struct device *dev; -struct drm_bridge *bridge; - -if (bridge_connector->bridge_hdmi_audio) - bridge = bridge_connector->bridge_hdmi_audio; -else - bridge = bridge_connector->bridge_dp_audio; - - dev = bridge->hdmi_audio_dev; - - ret =drm_connector_hdmi_audio_init (connector, dev, - &drm_bridge_connector_hdmi_audio_funcs, - bridge->hdmi_audio_max_i2s_playback_channels, - bridge->hdmi_audio_i2s_formats, - bridge->hdmi_audio_spdif_playback, - bridge->hdmi_audio_dai_port); -if (ret) -return ERR_PTR (ret); - } - -if (bridge_connector->bridge_hdmi_cec && - bridge_connector->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER ) { -struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; - - ret =drmm_connector_hdmi_cec_notifier_register (connector, -NULL , - bridge->hdmi_cec_dev); -if (ret) -return ERR_PTR (ret); - } - -if (bridge_connector->bridge_hdmi_cec && - bridge_connector->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_ADAPTER ) { -struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; - - ret =drmm_connector_hdmi_cec_register (connector, - &drm_bridge_connector_hdmi_cec_funcs, - bridge->hdmi_cec_adapter_name, - bridge->hdmi_cec_available_las, - bridge->hdmi_cec_dev); -if (ret) -return ERR_PTR (ret); - } + bridge_connector =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector); +if (IS_ERR (bridge_connector)) +return bridge_connector;drm_connector_helper_add (connector, &drm_bridge_connector_helper_funcs);
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 10/37 drm/display: bridge-connector: return int from drm_bridge_connector_init_hdmi_audio_cec()
In reply to Luca CeresoliThis function returns a struct drm_bridge_connector * because this was the case in the origin of its code. In current code it does not make sense
anymore: it can only return either the same pointer it received as input or a negative ERR_PTR.
Simplify up error management by just returning an int (0 or negative error).
No functional changes.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +8 -9
@@ -930,8 +930,7 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_return 0 ; } -static struct drm_bridge_connector * -drm_bridge_connector_init_hdmi_audio_cec (struct drm_bridge_connector *bridge_connector) +static int drm_bridge_connector_init_hdmi_audio_cec (struct drm_bridge_connector *bridge_connector) {int ret;
@@ -954,7 +953,7 @@ drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector *bridge_con bridge->hdmi_audio_spdif_playback, bridge->hdmi_audio_dai_port);if (ret) -return ERR_PTR (ret); +return ret; } if (bridge_connector->bridge_hdmi_cec &&
@@ -965,7 +964,7 @@ drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector *bridge_conNULL , bridge->hdmi_cec_dev);if (ret) -return ERR_PTR (ret); +return ret; } if (bridge_connector->bridge_hdmi_cec &&
@@ -978,10 +977,10 @@ drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector *bridge_con bridge->hdmi_cec_available_las, bridge->hdmi_cec_dev);if (ret) -return ERR_PTR (ret); +return ret; } -return bridge_connector; +return 0 ; }/**
@@ -1051,9 +1050,9 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connectorreturn ERR_PTR (ret); } - bridge_connector =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector); -if (IS_ERR (bridge_connector)) -return bridge_connector; + ret =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector); +if (ret) +return ERR_PTR (ret);drm_connector_helper_add (connector, &drm_bridge_connector_helper_funcs);
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 11/37 drm/display: bridge-connector: return int from drm_bridge_connector_add_connector()
In reply to Luca CeresoliThis function returns a struct drm_bridge_connector * because this was the case in the origin of its code. In current code it does not make sense: it can only return either the same pointer it received as input or a negative ERR_PTR.
This forces users to an unnecessarily complex error management code.
Clean up error management by just returning an int (0 or negative error).
--- drivers/gpu/drm/display/drm_bridge_connector.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +11 -13
@@ -991,11 +991,9 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector* @bridge_connector->drm and @bridge_connector->encoder fields are * assigned at least) * -* Returns a pointer to @bridge_connector on success, or a negative error -* pointer otherwise. +* Returns 0 on success or a negative error otherwise. */ -static struct drm_bridge_connector * -drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) +static int drm_bridge_connector_add_connector (struct drm_bridge_connector *bridge_connector) {struct drm_connector *connector;struct i2c_adapter *ddc =NULL ;
@@ -1012,7 +1010,7 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector &supported_formats, &max_bpc, &ddc, &panel_bridge, &support_hdcp);if (ret) -return ERR_PTR (ret); +return ret;if (bridge_connector->bridge_hdmi) {if (!connector->ycbcr_420_allowed)
@@ -1041,18 +1039,18 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector supported_formats, max_bpc);if (ret) -return ERR_PTR (ret); +return ret; }else { ret =drmm_connector_init (bridge_connector->drm, connector, &drm_bridge_connector_funcs, connector_type, ddc);if (ret) -return ERR_PTR (ret); +return ret; } ret =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector);if (ret) -return ERR_PTR (ret); +return ret;drm_connector_helper_add (connector, &drm_bridge_connector_helper_funcs);
@@ -1071,9 +1069,9 @@ drm_bridge_connector_add_connector(struct drm_bridge_connector *bridge_connector ret =drm_connector_attach_encoder (connector, bridge_connector->encoder);if (ret) -return ERR_PTR (ret); +return ret; -return bridge_connector; +return 0 ; }/**
@@ -1110,9 +1108,9 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, bridge_connector->drm = drm; bridge_connector->encoder = encoder; - bridge_connector =drm_bridge_connector_add_connector (bridge_connector); -if (IS_ERR (bridge_connector)) -return ERR_CAST (bridge_connector); + ret =drm_bridge_connector_add_connector (bridge_connector); +if (ret) +return ERR_PTR (ret);return &bridge_connector->base; }
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 12/37 drm/display: bridge-connector: hoist error management to common code
In reply to Luca CeresoliIn prepataion to add more error management code common to the HDMI and non-HDMI branches, move error management to be common to both cases.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -4
@@ -1038,15 +1038,13 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg connector_type, ddc, supported_formats, max_bpc); -if (ret) -return ret; }else { ret =drmm_connector_init (bridge_connector->drm, connector, &drm_bridge_connector_funcs, connector_type, ddc); -if (ret) -return ret; } +if (ret) +return ret; ret =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector);if (ret)
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 13/37 drm/display: bridge-connector: move drm_bridge_connector_put_bridges() definition eariler
In reply to Luca Ceresolidrm_bridge_connector_put_bridges() will have to be called in other places to support bridge hot-plugging.
In preparation for bridge hotplug support, move it near the top of the file.
No functional changes. Just moving code around.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +14 -14
@@ -140,6 +140,20 @@ struct drm_bridge_connector {#define to_drm_bridge_connector (x) \ container_of(x, struct drm_bridge_connector, base) +static void drm_bridge_connector_put_bridges (struct drm_device *dev,void *data) +{ +struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)data; + +drm_bridge_put (bridge_connector->bridge_edid); +drm_bridge_put (bridge_connector->bridge_hpd); +drm_bridge_put (bridge_connector->bridge_detect); +drm_bridge_put (bridge_connector->bridge_modes); +drm_bridge_put (bridge_connector->bridge_hdmi); +drm_bridge_put (bridge_connector->bridge_hdmi_audio); +drm_bridge_put (bridge_connector->bridge_dp_audio); +drm_bridge_put (bridge_connector->bridge_hdmi_cec); +} +/* ----------------------------------------------------------------------------- * Bridge Connector Hot-Plug Handling */
@@ -758,20 +772,6 @@ static const struct drm_connector_hdmi_cec_funcs drm_bridge_connector_hdmi_cec_f* Bridge Connector Initialisation */ -static void drm_bridge_connector_put_bridges (struct drm_device *dev,void *data) -{ -struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)data; - -drm_bridge_put (bridge_connector->bridge_edid); -drm_bridge_put (bridge_connector->bridge_hpd); -drm_bridge_put (bridge_connector->bridge_detect); -drm_bridge_put (bridge_connector->bridge_modes); -drm_bridge_put (bridge_connector->bridge_hdmi); -drm_bridge_put (bridge_connector->bridge_hdmi_audio); -drm_bridge_put (bridge_connector->bridge_dp_audio); -drm_bridge_put (bridge_connector->bridge_hdmi_cec); -} - static int drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector, int *connector_type, unsigned int *supported_formats,
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 14/37 drm/display: bridge-connector: add non-drmm variant of drm_bridge_connector_put_bridges()
In reply to Luca Ceresolidrm_bridge_connector_put_bridges() is currently meant as a drmm cleanup action. In preparation for bridge hotplug add a non-drmm action, so it can be called more simply in non-drmm context.
To do this split drm_bridge_connector_put_bridges() in two variants, both doing the same actions and only differing in the name and arguments:
* drm_bridge_connector_put_bridges() (same name as before) to be called directly by the drm_bridge_connector code with a drm_bridge_connector pointer as the only parameter
* drmm_bridge_connector_put_bridges() (same name + drmm prefix) providing the same drmm calling convention as before
Update the only call site accordingly.
No functional changes.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +9 -4
@@ -140,10 +140,8 @@ struct drm_bridge_connector {#define to_drm_bridge_connector (x) \ container_of(x, struct drm_bridge_connector, base) -static void drm_bridge_connector_put_bridges (struct drm_device *dev,void *data) +static void drm_bridge_connector_put_bridges (struct drm_bridge_connector *bridge_connector) { -struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)data; -drm_bridge_put (bridge_connector->bridge_edid);drm_bridge_put (bridge_connector->bridge_hpd);drm_bridge_put (bridge_connector->bridge_detect);
@@ -154,6 +152,13 @@ static void drm_bridge_connector_put_bridges(struct drm_device *dev, void *data)drm_bridge_put (bridge_connector->bridge_hdmi_cec); } +static void drmm_bridge_connector_put_bridges (struct drm_device *dev,void *data) +{ +struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)data; + +drm_bridge_connector_put_bridges (bridge_connector); +} +/* ----------------------------------------------------------------------------- * Bridge Connector Hot-Plug Handling */
@@ -1099,7 +1104,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (!bridge_connector)return ERR_PTR (-ENOMEM ); - ret =drmm_add_action (drm, drm_bridge_connector_put_bridges, bridge_connector); + ret =drmm_add_action (drm, drmm_bridge_connector_put_bridges, bridge_connector);if (ret)return ERR_PTR (ret);
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 15/37 drm/display: bridge-connector: allocate the connector dynamically
In reply to Luca CeresoliCurrently the drm_bridge_connector has an embedded drm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while the drm_bridge_connector is persistent.
Moreover the drm_connector is exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.
In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single drm_bridge_connector lifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freed
This commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 156 ++++++++++++++++++------- 1 file changed, 114 insertions(+), 42 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +114 -42
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2019 Laurent Pinchart <[email protected]> +* Copyright (C) 2026 GE HealthCare +* Author: Luca Ceresoli <[email protected]> */ #include <linux/export.h>
@@ -53,13 +55,24 @@*/ /** -* struct drm_bridge_connector - A connector backed by a chain of bridges +* drm_bridge_connector_dynconn - wrapper struct for the dynamically +* created drm_connector */ -struct drm_bridge_connector { +struct drm_bridge_connector_dynconn {/** -* @base: The base DRM connector +* @bridge_connector: the owning bridge connector */ -struct drm_connector base; +struct drm_bridge_connector *bridge_connector; +/** +* @connector: the drm_connector exposed to user space +*/ +struct drm_connector connector; +}; + +/** +* struct drm_bridge_connector - A connector backed by a chain of bridges +*/ +struct drm_bridge_connector {/** * @drm: The DRM device we belong to */
@@ -70,6 +83,10 @@ struct drm_bridge_connector {* The encoder at the start of the bridges chain. */ struct drm_encoder *encoder; +/** +* @dynconn: The DRM connector added by the drm_bridge_connector +*/ +struct drm_bridge_connector_dynconn *dynconn;/** * @bridge_edid: *
@@ -137,8 +154,13 @@ struct drm_bridge_connector {struct drm_connector_hdmi_funcs hdmi_funcs; }; -#define to_drm_bridge_connector (x) \ - container_of(x, struct drm_bridge_connector, base) +static struct drm_bridge_connector *to_drm_bridge_connector (const struct drm_connector *connector) +{ +const struct drm_bridge_connector_dynconn *dynconn = + container_of(connector, struct drm_bridge_connector_dynconn, connector); + +return dynconn->bridge_connector; +}static void drm_bridge_connector_put_bridges (struct drm_bridge_connector *bridge_connector) {
@@ -152,13 +174,6 @@ static void drm_bridge_connector_put_bridges(struct drm_bridge_connector *bridgedrm_bridge_put (bridge_connector->bridge_hdmi_cec); } -static void drmm_bridge_connector_put_bridges (struct drm_device *dev,void *data) -{ -struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)data; - -drm_bridge_connector_put_bridges (bridge_connector); -} -/* ----------------------------------------------------------------------------- * Bridge Connector Hot-Plug Handling */
@@ -179,7 +194,7 @@ static void drm_bridge_connector_hpd_notify(struct drm_connector *connector,static void drm_bridge_connector_handle_hpd (struct drm_bridge_connector *bridge_connector,enum drm_connector_status status) { -struct drm_connector *connector = &bridge_connector->base; +struct drm_connector *connector = &bridge_connector->dynconn->connector;struct drm_device *dev = bridge_connector->drm;mutex_lock (&dev->mode_config.mutex);
@@ -299,6 +314,16 @@ static void drm_bridge_connector_reset(struct drm_connector *connector) connector->state); } +static void drm_bridge_connector_dynconn_destroy (struct drm_connector *connector) +{ +struct drm_bridge_connector_dynconn *dynconn = + container_of(connector, struct drm_bridge_connector_dynconn, connector); + +drm_connector_cleanup (connector); +drm_bridge_connector_put_bridges (dynconn->bridge_connector); +kfree (dynconn); +} +static const struct drm_connector_funcs drm_bridge_connector_funcs = { .reset = drm_bridge_connector_reset, .detect = drm_bridge_connector_detect,
@@ -308,6 +333,7 @@ static const struct drm_connector_funcs drm_bridge_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, .debugfs_init = drm_bridge_connector_debugfs_init, .oob_hotplug_event = drm_bridge_connector_oob_hotplug_event, + .destroy = drm_bridge_connector_dynconn_destroy, };/* -----------------------------------------------------------------------------
@@ -777,7 +803,17 @@ static const struct drm_connector_hdmi_cec_funcs drm_bridge_connector_hdmi_cec_f* Bridge Connector Initialisation */ -static int drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_connector, +static void drm_bridge_connector_dynconn_release (struct drm_bridge_connector *bridge_connector) +{ +if (!bridge_connector->dynconn) +return ; + +drm_connector_unregister (&bridge_connector->dynconn->connector); +drm_connector_put (&bridge_connector->dynconn->connector); + bridge_connector->dynconn =NULL ; +} + +static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn *dynconn, int *connector_type, unsigned int *supported_formats, unsigned int *max_bpc,
@@ -785,7 +821,8 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_struct drm_bridge **panel_bridge, bool *support_hdcp) { - struct drm_connector *connector = &bridge_connector->base; + struct drm_bridge_connector *bridge_connector = dynconn->bridge_connector; +struct drm_connector *connector = &dynconn->connector;/* * TODO: Handle doublescan_allowed and stereo_allowed.
@@ -937,6 +974,7 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector *bridge_static int drm_bridge_connector_init_hdmi_audio_cec (struct drm_bridge_connector *bridge_connector) { +struct drm_connector *connector = &bridge_connector->dynconn->connector;int ret; if (bridge_connector->bridge_hdmi_audio ||
@@ -951,7 +989,7 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector dev = bridge->hdmi_audio_dev; - ret = drm_connector_hdmi_audio_init(&bridge_connector->base, dev, + ret = drm_connector_hdmi_audio_init(connector, dev, &drm_bridge_connector_hdmi_audio_funcs, bridge->hdmi_audio_max_i2s_playback_channels, bridge->hdmi_audio_i2s_formats,
@@ -965,8 +1003,7 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector bridge_connector->bridge_hdmi_cec->ops & DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER) {struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; - ret =drmm_connector_hdmi_cec_notifier_register (&bridge_connector->base, -NULL , + ret =drmm_connector_hdmi_cec_notifier_register (connector,NULL , bridge->hdmi_cec_dev);if (ret)return ret;
@@ -976,7 +1013,7 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector bridge_connector->bridge_hdmi_cec->ops & DRM_BRIDGE_OP_HDMI_CEC_ADAPTER) {struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; - ret = drmm_connector_hdmi_cec_register(&bridge_connector->base, + ret = drmm_connector_hdmi_cec_register(connector, &drm_bridge_connector_hdmi_cec_funcs, bridge->hdmi_cec_adapter_name, bridge->hdmi_cec_available_las,
@@ -1009,13 +1046,20 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgint connector_type;int ret; - connector = &bridge_connector->base; +struct drm_bridge_connector_dynconn *dynconn =kzalloc_obj (*dynconn); +if (!dynconn) +return -ENOMEM ; - ret =drm_bridge_connector_get_bridges (bridge_connector, &connector_type, + dynconn->bridge_connector = bridge_connector; + connector = &dynconn->connector; + + ret =drm_bridge_connector_get_bridges (dynconn, &connector_type, &supported_formats, &max_bpc, &ddc, &panel_bridge, &support_hdcp); -if (ret) +if (ret) { +kfree (dynconn);return ret; + }if (bridge_connector->bridge_hdmi) {if (!connector->ycbcr_420_allowed)
@@ -1035,25 +1079,34 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg bridge_connector->hdmi_funcs.spd = drm_bridge_connector_hdmi_spd_infoframe; - ret =drmm_connector_hdmi_init (bridge_connector->drm, connector, - bridge_connector->bridge_hdmi->vendor, - bridge_connector->bridge_hdmi->product, - &drm_bridge_connector_funcs, - &bridge_connector->hdmi_funcs, - connector_type, ddc, - supported_formats, - max_bpc); + ret =drm_connector_hdmi_dynamic_init (bridge_connector->drm, connector, + bridge_connector->bridge_hdmi->vendor, + bridge_connector->bridge_hdmi->product, + &drm_bridge_connector_funcs, + &bridge_connector->hdmi_funcs, + connector_type, ddc, + supported_formats, + max_bpc); }else { - ret =drmm_connector_init (bridge_connector->drm, connector, - &drm_bridge_connector_funcs, - connector_type, ddc); + ret =drm_connector_dynamic_init (bridge_connector->drm, connector, + &drm_bridge_connector_funcs, + connector_type, ddc); } -if (ret) +if (ret) { +drm_bridge_connector_put_bridges (dynconn->bridge_connector); +kfree (dynconn);return ret; + } + +/* From now on the connector is referenced and has to be put, not kfreed */ + + bridge_connector->dynconn = dynconn; + +drm_bridge_connector_reset (connector); ret =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector);if (ret) -return ret; + goto err_put;drm_connector_helper_add (connector, &drm_bridge_connector_helper_funcs);
@@ -1072,9 +1125,25 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg ret =drm_connector_attach_encoder (connector, bridge_connector->encoder);if (ret) -return ret; + goto err_put; + + ret =drm_connector_dynamic_register (connector); +if (ret) + goto err_put;return 0 ; + +err_put: +drm_connector_put (connector); + bridge_connector->dynconn =NULL ; +return ret; +} + +static void drm_bridge_connector_fini (struct drm_device *dev,void *res) +{ +struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)res; + +drm_bridge_connector_dynconn_release (bridge_connector); }/**
@@ -1104,10 +1173,6 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (!bridge_connector)return ERR_PTR (-ENOMEM ); - ret =drmm_add_action (drm, drmm_bridge_connector_put_bridges, bridge_connector); -if (ret) -return ERR_PTR (ret); - bridge_connector->drm = drm; bridge_connector->encoder = encoder;
@@ -1115,6 +1180,13 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (ret)return ERR_PTR (ret); -return &bridge_connector->base; + ret =drmm_add_action_or_reset (drm, drm_bridge_connector_fini, bridge_connector); +if (ret) +return ERR_PTR (ret); + +if (!bridge_connector->dynconn) +return ERR_PTR (-EINVAL ); + +return &bridge_connector->dynconn->connector; }EXPORT_SYMBOL_GPL (drm_bridge_connector_init);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Dynamic connector is passed to `drmm_` CEC cleanup actions, leading to a Use-After-Free if…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Dynamic connector is passed to drmm_ CEC cleanup actions, leading to a Use-After-Free if initialization fails.
- [High] Unconditional dereference of dynconn in the HPD handler causes a potential NULL pointer dereference.
- [Medium] Bridge references acquired during connector initialization are leaked on error paths.
--
commit b1940f18716e1942290e7aa7cf6a8cdaa0380840
Author: Luca Ceresoli <[email protected]>
drm/display: bridge-connector: allocate the connector dynamically
This commit changes drm_bridge_connector to allocate its drm_connector dynamically instead of embedding it. This allows recreating the connector during hotplug events while the bridge connector object remains persistent.
Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c static void drm_bridge_connector_hpd_notify(struct drm_connector *connector, · line 197
Quoted 6 lines
drivers/gpu/drm/display/drm_bridge_connector.c +1
-1@@ -179,7 +194,7 @@ static void drm_bridge_connector_hpd_notify(struct drm_connector *connector,static void drm_bridge_connector_handle_hpd (struct drm_bridge_connector *bridge_connector,enum drm_connector_status status) { -struct drm_connector *connector = &bridge_connector->base; +struct drm_connector *connector = &bridge_connector->dynconn->connector;
Since the connector is now allocated dynamically, is it possible for a hotplug event to trigger when bridge_connector->dynconn is NULL? If so, will dereferencing dynconn here cause a NULL pointer dereference?
[ ... ]
Quoted 1 line
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0@@ -1009,13 +1046,20 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1062
Quoted 9 lines
drivers/gpu/drm/display/drm_bridge_connector.c +4
-2- ret =drm_bridge_connector_get_bridges (bridge_connector, &connector_type, + ret =drm_bridge_connector_get_bridges (dynconn, &connector_type, &supported_formats, &max_bpc, &ddc, &panel_bridge, &support_hdcp); -if (ret) +if (ret) { +kfree (dynconn);return ret; + }
If drm_bridge_connector_get_bridges() encounters an error and returns early, it may have already acquired some bridge references. Are those references leaked here since drm_bridge_connector_put_bridges() isn't called before returning?
[ ... ]
Quoted 8 lines
drivers/gpu/drm/display/drm_bridge_connector.c +3
-1@@ -1072,9 +1125,25 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg ret =drm_connector_attach_encoder (connector, bridge_connector->encoder);if (ret) -return ret; + goto err_put; + + ret =drm_connector_dynamic_register (connector);
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1140
Quoted 10 lines
drivers/gpu/drm/display/drm_bridge_connector.c +8
-0+if (ret) + goto err_put;return 0 ; + +err_put: +drm_connector_put (connector); + bridge_connector->dynconn =NULL ; +return ret; +}
If drm_connector_dynamic_register() fails, the code goes to err_put and calls drm_connector_put(connector), which will drop the refcount and free dynconn.
However, drm_bridge_connector_init_hdmi_audio_cec() registers cleanup actions tied to the drm_device using drmm_connector_hdmi_cec_register() and drmm_connector_hdmi_cec_notifier_register().
Will those drmm actions cause a use-after-free when the drm_device is eventually released, since they will attempt to dereference the already freed connector?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Maxime Ripard
maintainerRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
In reply to Luca CeresoliQuoted 19 lines · Luca Ceresoli
Currently the
drm_bridge_connectorhas an embeddeddrm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while thedrm_bridge_connectoris persistent.Moreover the
drm_connectoris exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single
drm_bridge_connectorlifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freed
Quoted 5 lines
This commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
Signed-off-by Luca Ceresoli <[email protected]>
I think this patch should be split in half, with the switch to using destroy first, and then the actual move to the dynamically allocated connector API.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
Quoted 24 lines · Maxime Ripard
Quoted 23 lines · Luca Ceresoli
Currently the
drm_bridge_connectorhas an embeddeddrm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while thedrm_bridge_connectoris persistent.Moreover the
drm_connectoris exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single
drm_bridge_connectorlifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freedThis commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
Quoted 5 lines
Quoted 1 line
Signed-off-by Luca Ceresoli <[email protected]>I think this patch should be split in half, with the switch to using destroy first, and then the actual move to the dynamically allocated connector API.
Is it doable? drm_connector_dynamic_init() mandates a .destroy callback, drm_connector_init() forbids it.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
Quoted 25 lines · Luca Ceresoli
Quoted 24 lines · Maxime Ripard
Quoted 23 lines · Luca Ceresoli
Currently the
drm_bridge_connectorhas an embeddeddrm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while thedrm_bridge_connectoris persistent.Moreover the
drm_connectoris exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single
drm_bridge_connectorlifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freedThis commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Luca Ceresoli <[email protected]>I think this patch should be split in half, with the switch to using destroy first, and then the actual move to the dynamically allocated connector API.
Is it doable?
drm_connector_dynamic_init()mandates a .destroy callback,drm_connector_init()forbids it.
drmm_connector_init forbids it. drm_connector_init mandates it.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
Hi Maxime,
thanks for the feedback.
Quoted 28 lines · Maxime Ripard
Quoted 27 lines · Luca Ceresoli
Quoted 26 lines · Maxime Ripard
Quoted 24 lines · Luca Ceresoli
Currently the
drm_bridge_connectorhas an embeddeddrm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while thedrm_bridge_connectoris persistent.Moreover the
drm_connectoris exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single
drm_bridge_connectorlifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freedThis commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
Signed-off-by Luca Ceresoli <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I think this patch should be split in half, with the switch to using destroy first, and then the actual move to the dynamically allocated connector API.
Is it doable?
drm_connector_dynamic_init()mandates a .destroy callback,drm_connector_init()forbids it.
drmm_connector_initforbids it.drm_connector_initmandates it.
Something bogus in my reply, sorry. :)
So you mean splitting in:
* first patch: move from drmm_connector[_hdmi]_init() to drm_connector[_hdmi]_init() and add a .destroy
* second patch: move from drm_connector[_hdmi]_init() to drm_connector[_hdmi]_dynamic_init() + drm_connector_dynamic_register/unregister()
?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
Quoted 44 lines · Luca Ceresoli
Hi Maxime,
thanks for the feedback.
Quoted 28 lines · Maxime Ripard
Quoted 27 lines · Luca Ceresoli
Quoted 26 lines · Maxime Ripard
Quoted 24 lines · Luca Ceresoli
Currently the
drm_bridge_connectorhas an embeddeddrm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while thedrm_bridge_connectoris persistent.Moreover the
drm_connectoris exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single
drm_bridge_connectorlifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freedThis commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
Signed-off-by Luca Ceresoli <[email protected]>Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I think this patch should be split in half, with the switch to using destroy first, and then the actual move to the dynamically allocated connector API.
Is it doable?
drm_connector_dynamic_init()mandates a .destroy callback,drm_connector_init()forbids it.
drmm_connector_initforbids it.drm_connector_initmandates it.Something bogus in my reply, sorry. :)
Quoted 7 lines
So you mean splitting in:
* first patch: move from drmm_connector[_hdmi]_init() to drm_connector[_hdmi]_init() and add a .destroy
* second patch: move from drm_connector[_hdmi]_init() to drm_connector[_hdmi]_dynamic_init() + drm_connector_dynamic_register/unregister()
Ah, no, there's an annoyance here. drm_connector_hdmi_init() does not exist, so it'd have to be created just for the sake of splitting this patch, sitting unused after the second patch.
I don't think it's worth implementing (and maybe deleting) it just for that, so I'm leaving this patch as is unless you have counteraguments.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically
Quoted 53 lines · Luca Ceresoli
Quoted 44 lines · Luca Ceresoli
Hi Maxime,
thanks for the feedback.
Quoted 28 lines · Maxime Ripard
Quoted 27 lines · Luca Ceresoli
Quoted 26 lines · Maxime Ripard
Quoted 24 lines · Luca Ceresoli
Currently the
drm_bridge_connectorhas an embeddeddrm_connector, so their allocation lifetimes are tied to each other. This is insufficient to support DRM bridge hotplugging, which requires the connector to be added and removed dynamically at runtime multiple times based on hotplug/unplug events while thedrm_bridge_connectoris persistent.Moreover the
drm_connectoris exposed to user space and thus an ongoing operation (e.g. an ioctl) might last for an arbitrarily long time even after the hardware gets removed. This means a new connector might have to be added when the previous one is still referenced by user space.In preparation to handle hotplug, allocate the drm-connector dynamically, to allow:
* creating and destroying a connector multiple times during a single
drm_bridge_connectorlifetime
* creating a new connector even though the previous one is still in use and thus still refcounted and not yet freedThis commit does not introduce the actions in the two bullets (it will happen in a later commit), it only moves to dynamic APIs for connector allocation and init.
Signed-off-by Luca Ceresoli <[email protected]>Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I think this patch should be split in half, with the switch to using destroy first, and then the actual move to the dynamically allocated connector API.
Is it doable?
drm_connector_dynamic_init()mandates a .destroy callback,drm_connector_init()forbids it.
drmm_connector_initforbids it.drm_connector_initmandates it.Something bogus in my reply, sorry. :)
Quoted 7 lines
So you mean splitting in:
* first patch: move from drmm_connector[_hdmi]_init() to drm_connector[_hdmi]_init() and add a .destroy
* second patch: move from drm_connector[_hdmi]_init() to drm_connector[_hdmi]_dynamic_init() + drm_connector_dynamic_register/unregister()
Quoted 6 lines
Ah, no, there's an annoyance here.
drm_connector_hdmi_init()does not exist, so it'd have to be created just for the sake of splitting this patch, sitting unused after the second patch.I don't think it's worth implementing (and maybe deleting) it just for that, so I'm leaving this patch as is unless you have counteraguments.
If it's just to ease the transition, you can have two different set of drm_connector_funcs for HDMI vs !HDMI, one with destroy and the other using drmm while you rework the init function
Maxime
Luca Ceresoli
reviewerPATCH 16/37 drm/display: bridge-connector: move per-connector fields to the dynamic connector
In reply to Luca CeresoliThe various bridge pointers and the hdmi_funcs pointer are per-connector specific. In other words, when introducing bridge hotplug and the dynamically-created connector, they will have to be set per each created connector, possibly with different values from any previously created connector.
Those pointers are currently in struct drm_bridge_connector, which will persist across multiple connector creations and destructions. This means when a dynamic connector is created before the previous one is destroyed, these fields would be overwritten by the new connector but the old one will still reference them. This would lead to possible put of incorrect briges, resulting in use-after-free and leaks.
In preparation for bridge hotplug, move all those fields from struct drm_bridge_connector to struct drm_bridge_connector_dynconn, so they have the same allocation and lifetime of the connector they refer to.
Update the many locations where these fields are used.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 370 +++++++++++++------------ 1 file changed, 187 insertions(+), 183 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +187 -183
@@ -67,26 +67,6 @@ struct drm_bridge_connector_dynconn {* @connector: the drm_connector exposed to user space */ struct drm_connector connector; -}; - -/** -* struct drm_bridge_connector - A connector backed by a chain of bridges -*/ -struct drm_bridge_connector { -/** -* @drm: The DRM device we belong to -*/ -struct drm_device *drm; -/** -* @encoder: -* -* The encoder at the start of the bridges chain. -*/ -struct drm_encoder *encoder; -/** -* @dynconn: The DRM connector added by the drm_bridge_connector -*/ -struct drm_bridge_connector_dynconn *dynconn;/** * @bridge_edid: *
@@ -154,24 +134,47 @@ struct drm_bridge_connector {struct drm_connector_hdmi_funcs hdmi_funcs; }; -static struct drm_bridge_connector *to_drm_bridge_connector (const struct drm_connector *connector) +/** +* struct drm_bridge_connector - A connector backed by a chain of bridges +*/ +struct drm_bridge_connector { +/** +* @drm: The DRM device we belong to +*/ +struct drm_device *drm; +/** +* @encoder: +* +* The encoder at the start of the bridges chain. +*/ +struct drm_encoder *encoder; +/** +* @dynconn: The DRM connector added by the drm_bridge_connector +*/ +struct drm_bridge_connector_dynconn *dynconn; +}; + +static struct drm_bridge_connector_dynconn * +to_drm_bridge_connector_dynconn (const struct drm_connector *connector) { -const struct drm_bridge_connector_dynconn *dynconn = - container_of(connector, struct drm_bridge_connector_dynconn, connector); + return container_of(connector, struct drm_bridge_connector_dynconn, connector); +} -return dynconn->bridge_connector; +static struct drm_bridge_connector *to_drm_bridge_connector (const struct drm_connector *connector) +{ +return to_drm_bridge_connector_dynconn (connector)->bridge_connector; } -static void drm_bridge_connector_put_bridges (struct drm_bridge_connector *bridge_connector) +static void drm_bridge_connector_put_bridges (struct drm_bridge_connector_dynconn *dynconn) { -drm_bridge_put (bridge_connector->bridge_edid); -drm_bridge_put (bridge_connector->bridge_hpd); -drm_bridge_put (bridge_connector->bridge_detect); -drm_bridge_put (bridge_connector->bridge_modes); -drm_bridge_put (bridge_connector->bridge_hdmi); -drm_bridge_put (bridge_connector->bridge_hdmi_audio); -drm_bridge_put (bridge_connector->bridge_dp_audio); -drm_bridge_put (bridge_connector->bridge_hdmi_cec); +drm_bridge_put (dynconn->bridge_edid); +drm_bridge_put (dynconn->bridge_hpd); +drm_bridge_put (dynconn->bridge_detect); +drm_bridge_put (dynconn->bridge_modes); +drm_bridge_put (dynconn->bridge_hdmi); +drm_bridge_put (dynconn->bridge_hdmi_audio); +drm_bridge_put (dynconn->bridge_dp_audio); +drm_bridge_put (dynconn->bridge_hdmi_cec); }/* -----------------------------------------------------------------------------
@@ -225,7 +228,9 @@ static void drm_bridge_connector_enable_hpd(struct drm_connector *connector) {struct drm_bridge_connector *bridge_connector =to_drm_bridge_connector (connector); -struct drm_bridge *hpd = bridge_connector->bridge_hpd; +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); +struct drm_bridge *hpd = dynconn->bridge_hpd;if (hpd) drm_bridge_hpd_enable(hpd, drm_bridge_connector_hpd_cb,
@@ -234,9 +239,9 @@ static void drm_bridge_connector_enable_hpd(struct drm_connector *connector)static void drm_bridge_connector_disable_hpd (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); -struct drm_bridge *hpd = bridge_connector->bridge_hpd; +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); +struct drm_bridge *hpd = dynconn->bridge_hpd;if (hpd)drm_bridge_hpd_disable (hpd);
@@ -249,10 +254,10 @@ static void drm_bridge_connector_disable_hpd(struct drm_connector *connector)static enum drm_connector_status drm_bridge_connector_detect (struct drm_connector *connector,bool force) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); -struct drm_bridge *detect = bridge_connector->bridge_detect; -struct drm_bridge *hdmi = bridge_connector->bridge_hdmi; +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); +struct drm_bridge *detect = dynconn->bridge_detect; +struct drm_bridge *hdmi = dynconn->bridge_hdmi;enum drm_connector_status status;if (detect) {
@@ -281,9 +286,9 @@ drm_bridge_connector_detect(struct drm_connector *connector, bool force)static void drm_bridge_connector_force (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); -struct drm_bridge *hdmi = bridge_connector->bridge_hdmi; +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); +struct drm_bridge *hdmi = dynconn->bridge_hdmi;if (hdmi)drm_atomic_helper_connector_hdmi_force (connector);
@@ -305,11 +310,11 @@ static void drm_bridge_connector_debugfs_init(struct drm_connector *connector,static void drm_bridge_connector_reset (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);drm_atomic_helper_connector_reset (connector); -if (bridge_connector->bridge_hdmi) +if (dynconn->bridge_hdmi)__drm_atomic_helper_connector_hdmi_reset (connector, connector->state); }
@@ -320,7 +325,7 @@ static void drm_bridge_connector_dynconn_destroy(struct drm_connector *connector container_of(connector, struct drm_bridge_connector_dynconn, connector);drm_connector_cleanup (connector); -drm_bridge_connector_put_bridges (dynconn->bridge_connector); +drm_bridge_connector_put_bridges (dynconn);kfree (dynconn); }
@@ -370,15 +375,15 @@ static int drm_bridge_connector_get_modes_edid(struct drm_connector *connector,static int drm_bridge_connector_get_modes (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge;/* * If there is a HDMI bridge, EDID has been updated as a part of * the .detect(). Just update the modes here. */ - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (bridge)return drm_edid_connector_add_modes (connector);
@@ -386,7 +391,7 @@ static int drm_bridge_connector_get_modes(struct drm_connector *connector)* If display exposes EDID, then we parse that in the normal way to * build table of supported modes. */ - bridge = bridge_connector->bridge_edid; + bridge = dynconn->bridge_edid;if (bridge)return drm_bridge_connector_get_modes_edid (connector, bridge);
@@ -394,7 +399,7 @@ static int drm_bridge_connector_get_modes(struct drm_connector *connector)* Otherwise if the display pipeline reports modes (e.g. with a fixed * resolution panel or an analog TV output), query it. */ - bridge = bridge_connector->bridge_modes; + bridge = dynconn->bridge_modes;if (bridge)return bridge->funcs->get_modes (bridge, connector);
@@ -410,10 +415,10 @@ static enum drm_mode_status drm_bridge_connector_mode_valid(struct drm_connector *connector, const struct drm_display_mode *mode) { - struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); + struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); -if (bridge_connector->bridge_hdmi) +if (dynconn->bridge_hdmi)return drm_hdmi_connector_mode_valid (connector, mode);return MODE_OK ;
@@ -422,10 +427,10 @@ drm_bridge_connector_mode_valid(struct drm_connector *connector,static int drm_bridge_connector_atomic_check (struct drm_connector *connector,struct drm_atomic_commit *state) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); -if (bridge_connector->bridge_hdmi) +if (dynconn->bridge_hdmi)return drm_atomic_helper_connector_hdmi_check (connector, state);return 0 ;
@@ -444,11 +449,11 @@ drm_bridge_connector_tmds_char_rate_valid(const struct drm_connector *connector,const struct drm_display_mode *mode, unsigned long long tmds_rate) { - struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); + struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return MODE_ERROR ;
@@ -460,11 +465,11 @@ drm_bridge_connector_tmds_char_rate_valid(const struct drm_connector *connector,static int drm_bridge_connector_clear_avi_infoframe (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -474,11 +479,11 @@ static int drm_bridge_connector_clear_avi_infoframe(struct drm_connector *connecstatic int drm_bridge_connector_write_avi_infoframe (struct drm_connector *connector,const u8 *buffer,size_t len) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -487,11 +492,11 @@ static int drm_bridge_connector_write_avi_infoframe(struct drm_connector *connecstatic int drm_bridge_connector_clear_hdmi_infoframe (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -501,11 +506,11 @@ static int drm_bridge_connector_clear_hdmi_infoframe(struct drm_connector *connestatic int drm_bridge_connector_write_hdmi_infoframe (struct drm_connector *connector,const u8 *buffer,size_t len) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -514,11 +519,11 @@ static int drm_bridge_connector_write_hdmi_infoframe(struct drm_connector *connestatic int drm_bridge_connector_clear_audio_infoframe (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -528,11 +533,11 @@ static int drm_bridge_connector_clear_audio_infoframe(struct drm_connector *connstatic int drm_bridge_connector_write_audio_infoframe (struct drm_connector *connector,const u8 *buffer,size_t len) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -541,11 +546,11 @@ static int drm_bridge_connector_write_audio_infoframe(struct drm_connector *connstatic int drm_bridge_connector_clear_hdr_drm_infoframe (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -555,11 +560,11 @@ static int drm_bridge_connector_clear_hdr_drm_infoframe(struct drm_connector *costatic int drm_bridge_connector_write_hdr_drm_infoframe (struct drm_connector *connector,const u8 *buffer,size_t len) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -568,11 +573,11 @@ static int drm_bridge_connector_write_hdr_drm_infoframe(struct drm_connector *costatic int drm_bridge_connector_clear_spd_infoframe (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -582,11 +587,11 @@ static int drm_bridge_connector_clear_spd_infoframe(struct drm_connector *connecstatic int drm_bridge_connector_write_spd_infoframe (struct drm_connector *connector,const u8 *buffer,size_t len) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi; + bridge = dynconn->bridge_hdmi;if (!bridge)return -EINVAL ;
@@ -596,11 +601,11 @@ static int drm_bridge_connector_write_spd_infoframe(struct drm_connector *connecstatic const struct drm_edid *drm_bridge_connector_read_edid (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_edid; + bridge = dynconn->bridge_edid;if (!bridge)return NULL ;
@@ -638,12 +643,12 @@ static const struct drm_connector_infoframe_funcs drm_bridge_connector_hdmi_spd_static int drm_bridge_connector_audio_startup (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; -if (bridge_connector->bridge_hdmi_audio) { - bridge = bridge_connector->bridge_hdmi_audio; +if (dynconn->bridge_hdmi_audio) { + bridge = dynconn->bridge_hdmi_audio;if (!bridge->funcs->hdmi_audio_startup)return 0 ;
@@ -651,8 +656,8 @@ static int drm_bridge_connector_audio_startup(struct drm_connector *connector)return bridge->funcs->hdmi_audio_startup (bridge, connector); } -if (bridge_connector->bridge_dp_audio) { - bridge = bridge_connector->bridge_dp_audio; +if (dynconn->bridge_dp_audio) { + bridge = dynconn->bridge_dp_audio;if (!bridge->funcs->dp_audio_startup)return 0 ;
@@ -667,18 +672,18 @@ static int drm_bridge_connector_audio_prepare(struct drm_connector *connector,struct hdmi_codec_daifmt *fmt, struct hdmi_codec_params *hparms) { - struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); + struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; -if (bridge_connector->bridge_hdmi_audio) { - bridge = bridge_connector->bridge_hdmi_audio; +if (dynconn->bridge_hdmi_audio) { + bridge = dynconn->bridge_hdmi_audio;return bridge->funcs->hdmi_audio_prepare (bridge, connector, fmt, hparms); } -if (bridge_connector->bridge_dp_audio) { - bridge = bridge_connector->bridge_dp_audio; +if (dynconn->bridge_dp_audio) { + bridge = dynconn->bridge_dp_audio;return bridge->funcs->dp_audio_prepare (bridge, connector, fmt, hparms); }
@@ -688,17 +693,17 @@ static int drm_bridge_connector_audio_prepare(struct drm_connector *connector,static void drm_bridge_connector_audio_shutdown (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; -if (bridge_connector->bridge_hdmi_audio) { - bridge = bridge_connector->bridge_hdmi_audio; +if (dynconn->bridge_hdmi_audio) { + bridge = dynconn->bridge_hdmi_audio; bridge->funcs->hdmi_audio_shutdown (bridge, connector); } -if (bridge_connector->bridge_dp_audio) { - bridge = bridge_connector->bridge_dp_audio; +if (dynconn->bridge_dp_audio) { + bridge = dynconn->bridge_dp_audio; bridge->funcs->dp_audio_shutdown (bridge, connector); } }
@@ -706,12 +711,12 @@ static void drm_bridge_connector_audio_shutdown(struct drm_connector *connector)static int drm_bridge_connector_audio_mute_stream (struct drm_connector *connector,bool enable,int direction) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; -if (bridge_connector->bridge_hdmi_audio) { - bridge = bridge_connector->bridge_hdmi_audio; +if (dynconn->bridge_hdmi_audio) { + bridge = dynconn->bridge_hdmi_audio;if (!bridge->funcs->hdmi_audio_mute_stream)return -ENOTSUPP ;
@@ -720,8 +725,8 @@ static int drm_bridge_connector_audio_mute_stream(struct drm_connector *connecto enable, direction); } -if (bridge_connector->bridge_dp_audio) { - bridge = bridge_connector->bridge_dp_audio; +if (dynconn->bridge_dp_audio) { + bridge = dynconn->bridge_dp_audio;if (!bridge->funcs->dp_audio_mute_stream)return -ENOTSUPP ;
@@ -742,22 +747,22 @@ static const struct drm_connector_hdmi_audio_funcs drm_bridge_connector_hdmi_audstatic int drm_bridge_connector_hdmi_cec_enable (struct drm_connector *connector,bool enable) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi_cec; + bridge = dynconn->bridge_hdmi_cec;return bridge->funcs->hdmi_cec_enable (bridge, enable); }static int drm_bridge_connector_hdmi_cec_log_addr (struct drm_connector *connector,u8 logical_addr) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi_cec; + bridge = dynconn->bridge_hdmi_cec;return bridge->funcs->hdmi_cec_log_addr (bridge, logical_addr); }
@@ -767,11 +772,11 @@ static int drm_bridge_connector_hdmi_cec_transmit(struct drm_connector *connectou32 signal_free_time, struct cec_msg *msg) { - struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); + struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi_cec; + bridge = dynconn->bridge_hdmi_cec; return bridge->funcs->hdmi_cec_transmit(bridge, attempts, signal_free_time,
@@ -780,11 +785,11 @@ static int drm_bridge_connector_hdmi_cec_transmit(struct drm_connector *connectostatic int drm_bridge_connector_hdmi_cec_init (struct drm_connector *connector) { -struct drm_bridge_connector *bridge_connector = -to_drm_bridge_connector (connector); +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector);struct drm_bridge *bridge; - bridge = bridge_connector->bridge_hdmi_cec; + bridge = dynconn->bridge_hdmi_cec;if (!bridge->funcs->hdmi_cec_init)return 0 ;
@@ -821,7 +826,6 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconnstruct drm_bridge **panel_bridge, bool *support_hdcp) { - struct drm_bridge_connector *bridge_connector = dynconn->bridge_connector; struct drm_connector *connector = &dynconn->connector;/*
@@ -831,7 +835,7 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn connector->ycbcr_420_allowed = true; *connector_type = DRM_MODE_CONNECTOR_Unknown; -drm_for_each_bridge_in_chain_scoped (bridge_connector->encoder, bridge) { +drm_for_each_bridge_in_chain_scoped (dynconn->bridge_connector->encoder, bridge) {if (!bridge->interlace_allowed) connector->interlace_allowed = false;if (!bridge->ycbcr_420_allowed)
@@ -841,26 +845,26 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn* Ensure the last bridge declares OP_EDID or OP_MODES or both. */ if (bridge->ops &DRM_BRIDGE_OP_EDID || bridge->ops &DRM_BRIDGE_OP_MODES ) { -drm_bridge_put (bridge_connector->bridge_edid); - bridge_connector->bridge_edid =NULL ; -drm_bridge_put (bridge_connector->bridge_modes); - bridge_connector->bridge_modes =NULL ; +drm_bridge_put (dynconn->bridge_edid); + dynconn->bridge_edid =NULL ; +drm_bridge_put (dynconn->bridge_modes); + dynconn->bridge_modes =NULL ;if (bridge->ops &DRM_BRIDGE_OP_EDID ) - bridge_connector->bridge_edid =drm_bridge_get (bridge); + dynconn->bridge_edid =drm_bridge_get (bridge);if (bridge->ops &DRM_BRIDGE_OP_MODES ) - bridge_connector->bridge_modes =drm_bridge_get (bridge); + dynconn->bridge_modes =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_HPD ) { -drm_bridge_put (bridge_connector->bridge_hpd); - bridge_connector->bridge_hpd =drm_bridge_get (bridge); +drm_bridge_put (dynconn->bridge_hpd); + dynconn->bridge_hpd =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_DETECT ) { -drm_bridge_put (bridge_connector->bridge_detect); - bridge_connector->bridge_detect =drm_bridge_get (bridge); +drm_bridge_put (dynconn->bridge_detect); + dynconn->bridge_detect =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_HDMI ) { -if (bridge_connector->bridge_hdmi) +if (dynconn->bridge_hdmi)return -EBUSY ; if (!bridge->funcs->hdmi_write_avi_infoframe || !bridge->funcs->hdmi_clear_avi_infoframe ||
@@ -883,7 +887,7 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn !bridge->funcs->hdmi_clear_spd_infoframe))return -EINVAL ; - bridge_connector->bridge_hdmi =drm_bridge_get (bridge); + dynconn->bridge_hdmi =drm_bridge_get (bridge);if (bridge->supported_formats) *supported_formats = bridge->supported_formats;
@@ -892,10 +896,10 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn }if (bridge->ops &DRM_BRIDGE_OP_HDMI_AUDIO ) { -if (bridge_connector->bridge_hdmi_audio) +if (dynconn->bridge_hdmi_audio)return -EBUSY ; -if (bridge_connector->bridge_dp_audio) +if (dynconn->bridge_dp_audio)return -EBUSY ; if (!bridge->hdmi_audio_max_i2s_playback_channels &&
@@ -906,14 +910,14 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn !bridge->funcs->hdmi_audio_shutdown)return -EINVAL ; - bridge_connector->bridge_hdmi_audio =drm_bridge_get (bridge); + dynconn->bridge_hdmi_audio =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_DP_AUDIO ) { -if (bridge_connector->bridge_dp_audio) +if (dynconn->bridge_dp_audio)return -EBUSY ; -if (bridge_connector->bridge_hdmi_audio) +if (dynconn->bridge_hdmi_audio)return -EBUSY ; if (!bridge->hdmi_audio_max_i2s_playback_channels &&
@@ -924,21 +928,21 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn !bridge->funcs->dp_audio_shutdown)return -EINVAL ; - bridge_connector->bridge_dp_audio =drm_bridge_get (bridge); + dynconn->bridge_dp_audio =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER ) { -if (bridge_connector->bridge_hdmi_cec) +if (dynconn->bridge_hdmi_cec)return -EBUSY ; - bridge_connector->bridge_hdmi_cec =drm_bridge_get (bridge); + dynconn->bridge_hdmi_cec =drm_bridge_get (bridge); }if (bridge->ops &DRM_BRIDGE_OP_HDMI_CEC_ADAPTER ) { -if (bridge_connector->bridge_hdmi_cec) +if (dynconn->bridge_hdmi_cec)return -EBUSY ; - bridge_connector->bridge_hdmi_cec =drm_bridge_get (bridge); + dynconn->bridge_hdmi_cec =drm_bridge_get (bridge); if (!bridge->funcs->hdmi_cec_enable || !bridge->funcs->hdmi_cec_log_addr ||
@@ -972,20 +976,20 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconnreturn 0 ; } -static int drm_bridge_connector_init_hdmi_audio_cec (struct drm_bridge_connector *bridge_connector) +static int drm_bridge_connector_init_hdmi_audio_cec (struct drm_bridge_connector_dynconn *dynconn) { -struct drm_connector *connector = &bridge_connector->dynconn->connector; +struct drm_connector *connector = &dynconn->connector;int ret; -if (bridge_connector->bridge_hdmi_audio || - bridge_connector->bridge_dp_audio) { +if (dynconn->bridge_hdmi_audio || + dynconn->bridge_dp_audio) {struct device *dev;struct drm_bridge *bridge; -if (bridge_connector->bridge_hdmi_audio) - bridge = bridge_connector->bridge_hdmi_audio; +if (dynconn->bridge_hdmi_audio) + bridge = dynconn->bridge_hdmi_audio;else - bridge = bridge_connector->bridge_dp_audio; + bridge = dynconn->bridge_dp_audio; dev = bridge->hdmi_audio_dev;
@@ -999,9 +1003,9 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connectorreturn ret; } -if (bridge_connector->bridge_hdmi_cec && - bridge_connector->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER ) { -struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; +if (dynconn->bridge_hdmi_cec && + dynconn->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER ) { +struct drm_bridge *bridge = dynconn->bridge_hdmi_cec; ret =drmm_connector_hdmi_cec_notifier_register (connector,NULL , bridge->hdmi_cec_dev);
@@ -1009,9 +1013,9 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connectorreturn ret; } -if (bridge_connector->bridge_hdmi_cec && - bridge_connector->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_ADAPTER ) { -struct drm_bridge *bridge = bridge_connector->bridge_hdmi_cec; +if (dynconn->bridge_hdmi_cec && + dynconn->bridge_hdmi_cec->ops &DRM_BRIDGE_OP_HDMI_CEC_ADAPTER ) { +struct drm_bridge *bridge = dynconn->bridge_hdmi_cec; ret = drmm_connector_hdmi_cec_register(connector, &drm_bridge_connector_hdmi_cec_funcs,
@@ -1061,29 +1065,29 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgreturn ret; } -if (bridge_connector->bridge_hdmi) { +if (dynconn->bridge_hdmi) {if (!connector->ycbcr_420_allowed) supported_formats &= ~BIT (DRM_OUTPUT_COLOR_FORMAT_YCBCR420 ); - bridge_connector->hdmi_funcs = drm_bridge_connector_hdmi_funcs; + dynconn->hdmi_funcs = drm_bridge_connector_hdmi_funcs; -if (bridge_connector->bridge_hdmi->ops &DRM_BRIDGE_OP_HDMI_AUDIO ) - bridge_connector->hdmi_funcs.audio = +if (dynconn->bridge_hdmi->ops &DRM_BRIDGE_OP_HDMI_AUDIO ) + dynconn->hdmi_funcs.audio = drm_bridge_connector_hdmi_audio_infoframe; -if (bridge_connector->bridge_hdmi->ops &DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME ) - bridge_connector->hdmi_funcs.hdr_drm = +if (dynconn->bridge_hdmi->ops &DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME ) + dynconn->hdmi_funcs.hdr_drm = drm_bridge_connector_hdmi_hdr_drm_infoframe; -if (bridge_connector->bridge_hdmi->ops &DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME ) - bridge_connector->hdmi_funcs.spd = +if (dynconn->bridge_hdmi->ops &DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME ) + dynconn->hdmi_funcs.spd = drm_bridge_connector_hdmi_spd_infoframe; ret =drm_connector_hdmi_dynamic_init (bridge_connector->drm, connector, - bridge_connector->bridge_hdmi->vendor, - bridge_connector->bridge_hdmi->product, + dynconn->bridge_hdmi->vendor, + dynconn->bridge_hdmi->product, &drm_bridge_connector_funcs, - &bridge_connector->hdmi_funcs, + &dynconn->hdmi_funcs, connector_type, ddc, supported_formats, max_bpc);
@@ -1093,7 +1097,7 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg connector_type, ddc); }if (ret) { -drm_bridge_connector_put_bridges (dynconn->bridge_connector); +drm_bridge_connector_put_bridges (dynconn);kfree (dynconn);return ret; }
@@ -1104,15 +1108,15 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgdrm_bridge_connector_reset (connector); - ret =drm_bridge_connector_init_hdmi_audio_cec (bridge_connector); + ret =drm_bridge_connector_init_hdmi_audio_cec (dynconn);if (ret) goto err_put;drm_connector_helper_add (connector, &drm_bridge_connector_helper_funcs); -if (bridge_connector->bridge_hpd) +if (dynconn->bridge_hpd) connector->polled =DRM_CONNECTOR_POLL_HPD ; -else if (bridge_connector->bridge_detect) +else if (dynconn->bridge_detect) connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 16/37] drm/display: bridge-connector: move per-connector fields to the dynamic connector
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] HPD and OOB hotplug events are misrouted to the newest dynamic connector and can cause a NULL…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] HPD and OOB hotplug events are misrouted to the newest dynamic connector and can cause a NULL pointer dereference.
- [High] Use-After-Free due to drmm_ CEC registration for dynamically freed connectors.
- [Medium] Memory leak of bridge references on error path in drm_bridge_connector_add_connector().
--
commit 2da47a06a9f55cba5481389b325a75953c4b3912
Author: Luca Ceresoli <[email protected]>
drm/display: bridge-connector: move per-connector fields to the dynamic connector
This commit moves various bridge pointers and the hdmi_funcs pointer from struct drm_bridge_connector to struct drm_bridge_connector_dynconn. This ensures these fields share the same allocation and lifetime as the dynamically-created connector they reference, in preparation for bridge hotplugging support.
Quoted 13 lines
drivers/gpu/drm/display/drm_bridge_connector.c +3
-1@@ -225,7 +228,9 @@ static void drm_bridge_connector_enable_hpd(struct drm_connector *connector) {struct drm_bridge_connector *bridge_connector =to_drm_bridge_connector (connector); -struct drm_bridge *hpd = bridge_connector->bridge_hpd; +struct drm_bridge_connector_dynconn *dynconn = +to_drm_bridge_connector_dynconn (connector); +struct drm_bridge *hpd = dynconn->bridge_hpd;if (hpd) drm_bridge_hpd_enable(hpd, drm_bridge_connector_hpd_cb,
Quoted 2 lines
bridge_connector);
}
Does registering bridge_connector as the callback data here cause hotplug detection events to be misrouted?
When an event fires, the handler resolves the target via &bridge_connector->dynconn->connector. If multiple dynamic connectors are created concurrently, bridge_connector->dynconn will point to the most recently created one, potentially corrupting the state of a newer connector.
Additionally, if bridge_connector->dynconn has been set to NULL (such as after a hot-unplug), could this path trigger a NULL pointer dereference when the callback accesses connector->status?
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c static void drm_bridge_connector_dynconn_destroy(struct drm_connector *connector · line 330
Quoted 8 lines
drivers/gpu/drm/display/drm_bridge_connector.c +1
-1@@ -320,7 +325,7 @@ static void drm_bridge_connector_dynconn_destroy(struct drm_connector *connector container_of(connector, struct drm_bridge_connector_dynconn, connector);drm_connector_cleanup (connector); -drm_bridge_connector_put_bridges (dynconn->bridge_connector); +drm_bridge_connector_put_bridges (dynconn);kfree (dynconn); }
Since drm_bridge_connector_init_hdmi_audio_cec() registers components using drmm_connector_hdmi_cec_notifier_register() and drmm_connector_hdmi_cec_register(), the cleanup actions are deferred and bound to the global drm_device (connector->dev).
Because the connector is explicitly freed here via kfree(dynconn), will the delayed drmm_ actions dereference the freed connector pointer when the drm_device is eventually torn down, leading to a use-after-free regression?
[ ... ]
Quoted 6 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-2@@ -841,26 +845,26 @@ static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn* Ensure the last bridge declares OP_EDID or OP_MODES or both. */ if (bridge->ops &DRM_BRIDGE_OP_EDID || bridge->ops &DRM_BRIDGE_OP_MODES ) { -drm_bridge_put (bridge_connector->bridge_edid); - bridge_connector->bridge_edid =NULL ;
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_get_bridges(struct drm_bridge_connector_dynconn · line 854
Quoted 10 lines
drivers/gpu/drm/display/drm_bridge_connector.c +5
-3-drm_bridge_put (bridge_connector->bridge_modes); - bridge_connector->bridge_modes =NULL ; +drm_bridge_put (dynconn->bridge_edid); + dynconn->bridge_edid =NULL ; +drm_bridge_put (dynconn->bridge_modes); + dynconn->bridge_modes =NULL ;if (bridge->ops &DRM_BRIDGE_OP_EDID ) - bridge_connector->bridge_edid =drm_bridge_get (bridge); + dynconn->bridge_edid =drm_bridge_get (bridge);
When this function populates these bridge references in dynconn, if it later encounters an error (like returning -EINVAL for missing callbacks), the caller drm_bridge_connector_add_connector() will free dynconn without calling drm_bridge_connector_put_bridges().
Could this regression result in leaking these newly acquired bridge references on the error path?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Luca Ceresoli
reviewerPATCH 17/37 drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
In reply to Luca CeresoliBridge hotplug will make the connector dynamically created and destroyed based on hotplug events.
In preparation for that, add a mutex to mutually exclude connector creation and destruction.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/display/drm_bridge_connector.c +11 -0
@@ -8,6 +8,7 @@#include <linux/export.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/property.h> #include <linux/slab.h>
@@ -152,6 +153,11 @@ struct drm_bridge_connector {* @dynconn: The DRM connector added by the drm_bridge_connector */ struct drm_bridge_connector_dynconn *dynconn; +/** +* @dynconn_mutex: Protect @dynconn from concurrent creation and +* destruction +*/ +struct mutex dynconn_mutex; }; static struct drm_bridge_connector_dynconn *
@@ -810,6 +816,8 @@ static const struct drm_connector_hdmi_cec_funcs drm_bridge_connector_hdmi_cec_fstatic void drm_bridge_connector_dynconn_release (struct drm_bridge_connector *bridge_connector) { +guard (mutex)(&bridge_connector->dynconn_mutex); +if (!bridge_connector->dynconn)return ;
@@ -1050,6 +1058,8 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgint connector_type;int ret; +guard (mutex)(&bridge_connector->dynconn_mutex); +struct drm_bridge_connector_dynconn *dynconn =kzalloc_obj (*dynconn);if (!dynconn)return -ENOMEM ;
@@ -1177,6 +1187,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (!bridge_connector)return ERR_PTR (-ENOMEM ); +mutex_init (&bridge_connector->dynconn_mutex); bridge_connector->drm = drm; bridge_connector->encoder = encoder;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 17/37] drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Missing state check inside the locked section of drm_bridge_connector_add_connector() allows…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Missing state check inside the locked section of drm_bridge_connector_add_connector() allows overwriting an existing connector
- [High] Unprotected access to dynconn in drm_bridge_connector_handle_hpd() leads to NULL pointer dereference
- [High] Use-After-Free caused by mixing drmm cleanup actions with dynamically freed connectors
- [Medium] Mixing goto-based error handling with scope-based guard() cleanup in drm_bridge_connector_add_connector()
- [Medium] Missing mutex_destroy() or drmm_mutex_init() for dynconn_mutex
--
commit 83c9dccacbc0bf010c7c667632a3090398d3e6ed
Author: Luca Ceresoli <[email protected]>
drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
This commit introduces a mutex to mutually exclude connector creation and destruction based on bridge hotplug events. It adds dynconn_mutex to the drm_bridge_connector structure and uses guard() to protect the relevant sections.
Quoted 5 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0
drivers/gpu/drm/display/drm_bridge_connector.c struct drm_bridge_connector { · line 161
Quoted 9 lines
drivers/gpu/drm/display/drm_bridge_connector.c +5
-0@@ -152,6 +153,11 @@ struct drm_bridge_connector {* @dynconn: The DRM connector added by the drm_bridge_connector */ struct drm_bridge_connector_dynconn *dynconn; +/** +* @dynconn_mutex: Protect @dynconn from concurrent creation and +* destruction +*/ +struct mutex dynconn_mutex; };
Does drm_bridge_connector_handle_hpd() need to use this new mutex?
Since the connector lifecycle is now dynamic, if an asynchronous HPD event fires concurrently with a bridge detachment (which calls drm_bridge_connector_dynconn_release() and sets dynconn to NULL under the mutex), could drm_bridge_connector_handle_hpd() fetch the connector without the lock and trigger a NULL pointer dereference or use-after-free?
Could the dynamic lifecycle of the connector also cause a use-after-free with drmm cleanup actions?
drm_bridge_connector_add_connector() calls drm_bridge_connector_init_hdmi_audio_cec(), which uses drmm_connector_hdmi_cec_register() to register a cleanup action tied to the drm_device's lifetime.
Because the connector is now dynamically managed and freed via kfree when a bridge is detached, won't the drmm cleanup action hold a stale pointer and execute on an already-freed connector when the DRM device is unregistered?
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1062
Quoted 6 lines
drivers/gpu/drm/display/drm_bridge_connector.c +2
-0@@ -1050,6 +1058,8 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgint connector_type;int ret; +guard (mutex)(&bridge_connector->dynconn_mutex); +
Does introducing guard() here violate the cleanup subsystem guidelines?
The kernel cleanup subsystem guidelines forbid mixing goto-based error handling with scope-based cleanups like guard() in the same function because it creates confusing ownership semantics.
Later in this function we see:
if (ret) goto err_put; return 0;
err_put:
drm_connector_put(connector); bridge_connector->dynconn = NULL; return ret;
Could this mix of guard() and goto cause issues?
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1063
Quoted 1 line
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0struct drm_bridge_connector_dynconn *dynconn =kzalloc_obj (*dynconn);
Could concurrent hotplug events overwrite an existing connector here?
While later patches in the series introduce drm_bridge_connector_try_complete() which checks
if (bridge_connector->dynconn), that lockless check happens outside of dynconn_mutex.
If two threads pass that check simultaneously, they will sequentially acquire dynconn_mutex here. Would the second thread then unconditionally overwrite bridge_connector->dynconn with a new allocation, leaking the first connector's memory and leaving a dangling registered connector?
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 1190
Quoted 5 lines
drivers/gpu/drm/display/drm_bridge_connector.c +1
-0@@ -1177,6 +1187,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,if (!bridge_connector)return ERR_PTR (-ENOMEM ); +mutex_init (&bridge_connector->dynconn_mutex);
Should this be drmm_mutex_init() instead?
bridge_connector is allocated with drmm_kzalloc(), meaning its memory is tied to the DRM device's lifecycle. Since the registered cleanup action drm_bridge_connector_fini() does not call mutex_destroy(), could freeing the structure leave an active mutex and trigger kernel debug warnings when CONFIG_DEBUG_MUTEXES is enabled?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Maxime Ripard
maintainerRe: [PATCH 17/37] drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
In reply to Luca CeresoliQuoted 7 lines · Luca Ceresoli
Bridge hotplug will make the connector dynamically created and destroyed based on hotplug events.
In preparation for that, add a mutex to mutually exclude connector creation and destruction.
Signed-off-by Luca Ceresoli <[email protected]>
What is the source of concurrency, and what are you protecting against exactly with that lock?
Maxime
Luca Ceresoli
reviewerRe: [PATCH 17/37] drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
Quoted 11 lines · Maxime Ripard
Quoted 7 lines · Luca Ceresoli
Bridge hotplug will make the connector dynamically created and destroyed based on hotplug events.
In preparation for that, add a mutex to mutually exclude connector creation and destruction.
Signed-off-by Luca Ceresoli <[email protected]>What is the source of concurrency, and what are you protecting against exactly with that lock?
With bridge hotplug, the connector creation and destruction can be triggered by different code paths, so we need to prevent to:
* start destroying a connector that has not been created fully yet
* start creating a connector while the previous one is still being destroyed
Both conditions might happen startig with patch 36.
So I guess I'll just squash this patch into patch 36. The commit message will become quite verbose but it amkes sense to do it all at once.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 18/37 drm/bridge: samsung-dsim: remove the panel_bridge on host_detach
In reply to Luca CeresoliIn preparation for DRM bridge hot-plugging, we need to handle the dynamic lifetime of the following bridge in case the samsung-dsim is always present and the following bridge (next_bridge) is hot-unplugged.
Based on the 'if (!IS_ERR(panel))' check in samsung_dsim_host_attach(), the next_bridge could be A) a panel bridge created by this driver via devm_drm_panel_bridge_add() or B) a pre-existing bridge obtained via of_drm_find_and_get_bridge().
For case B) we need to put that reference when the next_bridge is removed, which is already handled by calling drm_bridge_clear_and_put() in samsung_dsim_host_detach() and in the samsung_dsim_host_attach() error management code.
In case A) we additionally have to remove the panel bridge. Currently it is created by devm_drm_panel_bridge_add(), which adds two devm actions with the refcounted panel bridge:
- drm_bridge_put_void() via devm_drm_bridge_alloc() on panel->dev
- devm_drm_panel_bridge_release() via devm_drm_panel_bridge_add_typed() on the consumer device (samsung-dsim)
The first action is OK: being tied to panel->dev it will happen when the panel is unplugged.
The second action is bound to the consumer device, so the devm semantics is not useful here when introducing hotplug. Indeed we need to drop the next_bridge in samsung_dsim_host_detach() anyway, before the driver .remove function, in order to support {add, {attach, detach} x N, remove} hotplug event sequences.
Thus move to the non-devm drm_panel_bridge_add() along with the matching drm_panel_bridge_remove(), so the lifetime of the panel-bridge is tied to the host_attach/host_detach cycle and not the whole samsung-dsim device lifetime.
---
In a previous discussion with Maxime he mentioned a plan to make every drm_panel always have a wrapping bridge. With that done, all the code handling the panel and adding the panel_bridge would become useless here (and in many other places) and could be entirely removed. This patch is a temporary solution until that happens. The best pointer I could find to that discussion is [0], but there might be more recent material I could not find at the moment.
[0] https://lore.kernel.org/lkml/20250218-faithful-white-magpie-da9ac9@houat/
--- drivers/gpu/drm/bridge/samsung-dsim.c | 17 ++++++++++++++--- include/drm/bridge/samsung-dsim.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/samsung-dsim.c +14 -3
@@ -1951,14 +1951,16 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!remote)return -ENODEV ; + dsi->panel_bridge_added = false; panel =of_drm_find_panel (remote);if (!IS_ERR (panel)) { - next_bridge =devm_drm_panel_bridge_add (dev, panel); + next_bridge =drm_panel_bridge_add (panel);if (IS_ERR (next_bridge)) { ret =PTR_ERR (next_bridge); next_bridge =NULL ;// Inhibit the cleanup action on an ERR_PTR }else {drm_bridge_get (next_bridge); + dsi->panel_bridge_added = true; } }else { next_bridge =of_drm_find_and_get_bridge (remote);
@@ -1989,7 +1991,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO )) { ret =samsung_dsim_register_te_irq (dsi, &device->dev);if (ret) - goto err_remove_bridge; + goto err_remove_panel_bridge; }// The next bridge can be used by host_ops->attach
@@ -2011,8 +2013,12 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,drm_bridge_clear_and_put (&dsi->bridge.next_bridge);if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO ))samsung_dsim_unregister_te_irq (dsi); -err_remove_bridge: +err_remove_panel_bridge:drm_bridge_remove (&dsi->bridge); +if (dsi->panel_bridge_added) { +drm_panel_bridge_remove (next_bridge); + dsi->panel_bridge_added = false; + }return ret; }
@@ -2022,6 +2028,11 @@ static int samsung_dsim_host_detach(struct mipi_dsi_host *host,struct samsung_dsim *dsi =host_to_dsi (host);const struct samsung_dsim_plat_data *pdata = dsi->plat_data; +if (dsi->panel_bridge_added) { +drm_panel_bridge_remove (dsi->bridge.next_bridge); + dsi->panel_bridge_added = false; + } +if (pdata->host_ops && pdata->host_ops->detach) pdata->host_ops->detach (dsi, device);
include/drm/bridge/samsung-dsim.h +2 -0
@@ -131,6 +131,8 @@ struct samsung_dsim {const struct samsung_dsim_plat_data *plat_data;void *priv; + +bool panel_bridge_added;/* true iff next_bridge is a panel_bridge we created */ };extern int samsung_dsim_probe (struct platform_device *pdev);
Signature · 1 line
2.54.0
Maxime Ripard
maintainerRe: [PATCH 18/37] drm/bridge: samsung-dsim: remove the panel_bridge on host_detach
Quoted 86 lines · Luca Ceresoli
In preparation for DRM bridge hot-plugging, we need to handle the dynamic lifetime of the following bridge in case the samsung-dsim is always present and the following bridge (
next_bridge) is hot-unplugged.Based on the 'if (!IS_ERR(panel))' check in
samsung_dsim_host_attach(), thenext_bridgecould be A) a panel bridge created by this driver viadevm_drm_panel_bridge_add()or B) a pre-existing bridge obtained viaof_drm_find_and_get_bridge().For case B) we need to put that reference when the
next_bridgeis removed, which is already handled by callingdrm_bridge_clear_and_put()insamsung_dsim_host_detach()and in thesamsung_dsim_host_attach()error management code.In case A) we additionally have to remove the panel bridge. Currently it is created by
devm_drm_panel_bridge_add(), which adds two devm actions with the refcounted panel bridge:-
drm_bridge_put_void()viadevm_drm_bridge_alloc()onpanel->dev
-devm_drm_panel_bridge_release()viadevm_drm_panel_bridge_add_typed()on the consumer device (samsung-dsim)The first action is OK: being tied to
panel->devit will happen when the panel is unplugged.The second action is bound to the consumer device, so the devm semantics is not useful here when introducing hotplug. Indeed we need to drop the
next_bridgeinsamsung_dsim_host_detach()anyway, before the driver .remove function, in order to support {add, {attach, detach} x N, remove} hotplug event sequences.Thus move to the non-devm
drm_panel_bridge_add()along with the matchingdrm_panel_bridge_remove(), so the lifetime of the panel-bridge is tied to the host_attach/host_detach cycle and not the whole samsung-dsim device lifetime.Signed-off-by Luca Ceresoli <[email protected]>---
In a previous discussion with Maxime he mentioned a plan to make every
drm_panelalways have a wrapping bridge. With that done, all the code handling the panel and adding thepanel_bridgewould become useless here (and in many other places) and could be entirely removed. This patch is a temporary solution until that happens. The best pointer I could find to that discussion is [0], but there might be more recent material I could not find at the moment.[0] https://lore.kernel.org/lkml/20250218-faithful-white-magpie-da9ac9@houat/
--- drivers/gpu/drm/bridge/samsung-dsim.c | 17 ++++++++++++++--- include/drm/bridge/samsung-dsim.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-)drivers/gpu/drm/bridge/samsung-dsim.c +4
-2@@ -1951,14 +1951,16 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!remote)return -ENODEV ; + dsi->panel_bridge_added = false; panel =of_drm_find_panel (remote);if (!IS_ERR (panel)) { - next_bridge =devm_drm_panel_bridge_add (dev, panel); + next_bridge =drm_panel_bridge_add (panel);if (IS_ERR (next_bridge)) { ret =PTR_ERR (next_bridge); next_bridge =NULL ;// Inhibit the cleanup action on an ERR_PTR }else {drm_bridge_get (next_bridge); + dsi->panel_bridge_added = true; } }else { next_bridge =of_drm_find_and_get_bridge (remote);@@ -1989,7 +1991,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO )) { ret =samsung_dsim_register_te_irq (dsi, &device->dev);if (ret) - goto err_remove_bridge; + goto err_remove_panel_bridge; }// The next bridge can be used by host_ops->attach
drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_host_attach(struct mipi_dsi_host *host, · line 2021
Quoted 10 lines
drivers/gpu/drm/bridge/samsung-dsim.c +5
-1@@ -2011,8 +2013,12 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,drm_bridge_clear_and_put (&dsi->bridge.next_bridge);if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO ))samsung_dsim_unregister_te_irq (dsi); -err_remove_bridge: +err_remove_panel_bridge:drm_bridge_remove (&dsi->bridge); +if (dsi->panel_bridge_added) { +drm_panel_bridge_remove (next_bridge); + dsi->panel_bridge_added = false; + }
This is a pretty big abstraction leak. We don't want to have that in everything driver. The removal path should be the same for both cases, and it's not something the driver should take care of.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 18/37] drm/bridge: samsung-dsim: remove the panel_bridge on host_detach
Quoted 85 lines · Maxime Ripard
Quoted 84 lines · Luca Ceresoli
In preparation for DRM bridge hot-plugging, we need to handle the dynamic lifetime of the following bridge in case the samsung-dsim is always present and the following bridge (
next_bridge) is hot-unplugged.Based on the 'if (!IS_ERR(panel))' check in
samsung_dsim_host_attach(), thenext_bridgecould be A) a panel bridge created by this driver viadevm_drm_panel_bridge_add()or B) a pre-existing bridge obtained viaof_drm_find_and_get_bridge().For case B) we need to put that reference when the
next_bridgeis removed, which is already handled by callingdrm_bridge_clear_and_put()insamsung_dsim_host_detach()and in thesamsung_dsim_host_attach()error management code.In case A) we additionally have to remove the panel bridge. Currently it is created by
devm_drm_panel_bridge_add(), which adds two devm actions with the refcounted panel bridge:-
drm_bridge_put_void()viadevm_drm_bridge_alloc()onpanel->dev
-devm_drm_panel_bridge_release()viadevm_drm_panel_bridge_add_typed()on the consumer device (samsung-dsim)The first action is OK: being tied to
panel->devit will happen when the panel is unplugged.The second action is bound to the consumer device, so the devm semantics is not useful here when introducing hotplug. Indeed we need to drop the
next_bridgeinsamsung_dsim_host_detach()anyway, before the driver .remove function, in order to support {add, {attach, detach} x N, remove} hotplug event sequences.Thus move to the non-devm
drm_panel_bridge_add()along with the matchingdrm_panel_bridge_remove(), so the lifetime of the panel-bridge is tied to the host_attach/host_detach cycle and not the whole samsung-dsim device lifetime.Signed-off-by Luca Ceresoli <[email protected]>---
In a previous discussion with Maxime he mentioned a plan to make every
drm_panelalways have a wrapping bridge. With that done, all the code handling the panel and adding thepanel_bridgewould become useless here (and in many other places) and could be entirely removed. This patch is a temporary solution until that happens. The best pointer I could find to that discussion is [0], but there might be more recent material I could not find at the moment.[0] https://lore.kernel.org/lkml/20250218-faithful-white-magpie-da9ac9@houat/
--- drivers/gpu/drm/bridge/samsung-dsim.c | 17 ++++++++++++++--- include/drm/bridge/samsung-dsim.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-)drivers/gpu/drm/bridge/samsung-dsim.c +4
-2@@ -1951,14 +1951,16 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!remote)return -ENODEV ; + dsi->panel_bridge_added = false; panel =of_drm_find_panel (remote);if (!IS_ERR (panel)) { - next_bridge =devm_drm_panel_bridge_add (dev, panel); + next_bridge =drm_panel_bridge_add (panel);if (IS_ERR (next_bridge)) { ret =PTR_ERR (next_bridge); next_bridge =NULL ;// Inhibit the cleanup action on an ERR_PTR }else {drm_bridge_get (next_bridge); + dsi->panel_bridge_added = true; } }else { next_bridge =of_drm_find_and_get_bridge (remote);@@ -1989,7 +1991,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO )) { ret =samsung_dsim_register_te_irq (dsi, &device->dev);if (ret) - goto err_remove_bridge; + goto err_remove_panel_bridge; }
Quoted 16 lines
drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_host_attach(struct mipi_dsi_host *host, · line 2021
Quoted 12 lines
drivers/gpu/drm/bridge/samsung-dsim.c +5
-1// The next bridge can be used by host_ops->attach @@ -2011,8 +2013,12 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,drm_bridge_clear_and_put (&dsi->bridge.next_bridge);if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO ))samsung_dsim_unregister_te_irq (dsi); -err_remove_bridge: +err_remove_panel_bridge:drm_bridge_remove (&dsi->bridge); +if (dsi->panel_bridge_added) { +drm_panel_bridge_remove (next_bridge); + dsi->panel_bridge_added = false; + }This is a pretty big abstraction leak. We don't want to have that in everything driver. The removal path should be the same for both cases, and it's not something the driver should take care of.
Yes. The comment after the '---' separator was meant to discuss this concern:
Quoted 7 lines
In a previous discussion with Maxime he mentioned a plan to make every
drm_panelalways have a wrapping bridge. With that done, all the code handling the panel and adding thepanel_bridgewould become useless here (and in many other places) and could be entirely removed. This patch is a temporary solution until that happens. The best pointer I could find to that discussion is [0], but there might be more recent material I could not find at the moment.
Do you have any update about that plan?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 18/37] drm/bridge: samsung-dsim: remove the panel_bridge on host_detach
Quoted 114 lines · Luca Ceresoli
Quoted 85 lines · Maxime Ripard
Quoted 84 lines · Luca Ceresoli
In preparation for DRM bridge hot-plugging, we need to handle the dynamic lifetime of the following bridge in case the samsung-dsim is always present and the following bridge (
next_bridge) is hot-unplugged.Based on the 'if (!IS_ERR(panel))' check in
samsung_dsim_host_attach(), thenext_bridgecould be A) a panel bridge created by this driver viadevm_drm_panel_bridge_add()or B) a pre-existing bridge obtained viaof_drm_find_and_get_bridge().For case B) we need to put that reference when the
next_bridgeis removed, which is already handled by callingdrm_bridge_clear_and_put()insamsung_dsim_host_detach()and in thesamsung_dsim_host_attach()error management code.In case A) we additionally have to remove the panel bridge. Currently it is created by
devm_drm_panel_bridge_add(), which adds two devm actions with the refcounted panel bridge:-
drm_bridge_put_void()viadevm_drm_bridge_alloc()onpanel->dev
-devm_drm_panel_bridge_release()viadevm_drm_panel_bridge_add_typed()on the consumer device (samsung-dsim)The first action is OK: being tied to
panel->devit will happen when the panel is unplugged.The second action is bound to the consumer device, so the devm semantics is not useful here when introducing hotplug. Indeed we need to drop the
next_bridgeinsamsung_dsim_host_detach()anyway, before the driver .remove function, in order to support {add, {attach, detach} x N, remove} hotplug event sequences.Thus move to the non-devm
drm_panel_bridge_add()along with the matchingdrm_panel_bridge_remove(), so the lifetime of the panel-bridge is tied to the host_attach/host_detach cycle and not the whole samsung-dsim device lifetime.Signed-off-by Luca Ceresoli <[email protected]>---
In a previous discussion with Maxime he mentioned a plan to make every
drm_panelalways have a wrapping bridge. With that done, all the code handling the panel and adding thepanel_bridgewould become useless here (and in many other places) and could be entirely removed. This patch is a temporary solution until that happens. The best pointer I could find to that discussion is [0], but there might be more recent material I could not find at the moment.[0] https://lore.kernel.org/lkml/20250218-faithful-white-magpie-da9ac9@houat/
--- drivers/gpu/drm/bridge/samsung-dsim.c | 17 ++++++++++++++--- include/drm/bridge/samsung-dsim.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-)drivers/gpu/drm/bridge/samsung-dsim.c +4
-2@@ -1951,14 +1951,16 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!remote)return -ENODEV ; + dsi->panel_bridge_added = false; panel =of_drm_find_panel (remote);if (!IS_ERR (panel)) { - next_bridge =devm_drm_panel_bridge_add (dev, panel); + next_bridge =drm_panel_bridge_add (panel);if (IS_ERR (next_bridge)) { ret =PTR_ERR (next_bridge); next_bridge =NULL ;// Inhibit the cleanup action on an ERR_PTR }else {drm_bridge_get (next_bridge); + dsi->panel_bridge_added = true; } }else { next_bridge =of_drm_find_and_get_bridge (remote);@@ -1989,7 +1991,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO )) { ret =samsung_dsim_register_te_irq (dsi, &device->dev);if (ret) - goto err_remove_bridge; + goto err_remove_panel_bridge; }Quoted 16 lines
drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_host_attach(struct mipi_dsi_host *host, · line 2021
Quoted 12 lines
drivers/gpu/drm/bridge/samsung-dsim.c +5
-1// The next bridge can be used by host_ops->attach @@ -2011,8 +2013,12 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,drm_bridge_clear_and_put (&dsi->bridge.next_bridge);if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO ))samsung_dsim_unregister_te_irq (dsi); -err_remove_bridge: +err_remove_panel_bridge:drm_bridge_remove (&dsi->bridge); +if (dsi->panel_bridge_added) { +drm_panel_bridge_remove (next_bridge); + dsi->panel_bridge_added = false; + }This is a pretty big abstraction leak. We don't want to have that in everything driver. The removal path should be the same for both cases, and it's not something the driver should take care of.
Yes. The comment after the '---' separator was meant to discuss this concern:
Quoted 7 lines
In a previous discussion with Maxime he mentioned a plan to make every
drm_panelalways have a wrapping bridge. With that done, all the code handling the panel and adding thepanel_bridgewould become useless here (and in many other places) and could be entirely removed. This patch is a temporary solution until that happens. The best pointer I could find to that discussion is [0], but there might be more recent material I could not find at the moment.
Quoted 1 line
Do you have any update about that plan?
I think we're pretty much there. As of 7.2, all panels will use devm_drm_panel_alloc. It should be fairly easy now to create a bridge for them all in devm_drm_panel_alloc, and then call drm_bridge_add in drm_panel_add.
It's also tangentially related to https://lore.kernel.org/ksummit/[email protected]/
Maxime
Luca Ceresoli
reviewerPATCH 19/37 drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
In reply to Luca CeresoliThis bridge driver calls drm_bridge_add() in the DSI host .attach callback instead of in the probe function.
This works for current use cases but is problematic for supporting hotplug of DRM bridges. The problematic case is when this DSI host is always present while its DSI device is hot-pluggable. In such case with the current code the DRM card will not be populated until after the DSI device attaches to the host, which could happen a very long time after booting, or even not happen at all.
The reason is that the previous pipeline component (the encoder in this case) when probing cannot find the samsung-dsim bridge. What happens is:
[1 and 2 can happen in any order, same result]
1) samsung-dsim probes (does not drm_bridge_add() itself)
2) The lcdif starts probing multiple times, but
lcdif_probe
-> lcdif_load
-> lcdif_attach_bridge
-> devm_drm_of_get_bridge() returns -EPROBE_DEFER because
the samsung-dsim is not in the global bridge_list
(deferred probe pending: imx-lcdif: Cannot connect bridge)The samsung-dsim will not drm_bridge_add() itself until a DSI device will try to mipi_dsi_attach() to the DSI Host, which can happen arbitratily late on hot-pluggable hardware.
As a preliminary step to supporting hotplug move drm_bridge_add() at probe time, so that the samsung-dsim DSI host bridge is available during boot, even without a connected DSI device. This results in:
1) samsung-dsim probes (and adds to drm_bridge_add() itself)
2) The lcdif starts probing multiple times, but
lcdif_probe
-> lcdif_load
-> lcdif_attach_bridge
-> devm_drm_of_get_bridge() --> OK, returns samsung-dsim ptr--- drivers/gpu/drm/bridge/samsung-dsim.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/bridge/samsung-dsim.c +4 -5
@@ -1980,8 +1980,6 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,mipi_dsi_pixel_format_to_bpp (device->format), device->mode_flags); -drm_bridge_add (&dsi->bridge); -/* * This is a temporary solution and should be made by more generic way. *
@@ -2014,7 +2012,6 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,if (!(device->mode_flags &MIPI_DSI_MODE_VIDEO ))samsung_dsim_unregister_te_irq (dsi); err_remove_panel_bridge: -drm_bridge_remove (&dsi->bridge);if (dsi->panel_bridge_added) {drm_panel_bridge_remove (next_bridge); dsi->panel_bridge_added = false;
@@ -2040,8 +2037,6 @@ static int samsung_dsim_host_detach(struct mipi_dsi_host *host,samsung_dsim_unregister_te_irq (dsi); -drm_bridge_remove (&dsi->bridge); -return 0 ; }
@@ -2242,6 +2237,8 @@ int samsung_dsim_probe(struct platform_device *pdev) goto err_disable_runtime; } +drm_bridge_add (&dsi->bridge); +return 0 ; err_disable_runtime:
@@ -2255,6 +2252,8 @@ void samsung_dsim_remove(struct platform_device *pdev) {struct samsung_dsim *dsi =platform_get_drvdata (pdev); +drm_bridge_remove (&dsi->bridge); +pm_runtime_disable (&pdev->dev);if (dsi->plat_data->host_ops && dsi->plat_data->host_ops->unregister_host)
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 19/37] drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Moving drm_bridge_add() to probe() breaks probe deferral, causing a permanent -EINVAL failure.…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Moving drm_bridge_add() to probe() breaks probe deferral, causing a permanent -EINVAL failure.
- [Medium] Lockless data race on bridge state and next_bridge pointer when the panel attaches asynchronously. --
commit 8b9a88707049c09bf2d0cddc2aeab67e8c2ea0b4
Author: Luca Ceresoli <[email protected]>
drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
This commit moves the drm_bridge_add() call from the DSI host attach callback to the probe function to allow the DRM card to populate even without a connected DSI device.
Quoted 3 lines
drivers/gpu/drm/bridge/samsung-dsim.c +0
-0
[ ... ]
drivers/gpu/drm/bridge/samsung-dsim.c int samsung_dsim_probe(struct platform_device *pdev) · line 2222
Quoted 7 lines
drivers/gpu/drm/bridge/samsung-dsim.c +2
-0@@ -2222,6 +2217,8 @@ int samsung_dsim_probe(struct platform_device *pdev) goto err_disable_runtime; } +drm_bridge_add (&dsi->bridge); +return 0 ;
Does moving drm_bridge_add() to the probe function break probe deferral?
By registering the DRM bridge here, the bridge becomes immediately available to the DRM master (like imx-lcdif) before the downstream DSI panel has probed. When the DRM master probes, it finds the bridge and calls drm_bridge_attach(). This routes to samsung_dsim_attach(), which unconditionally attempts to attach dsi->bridge.next_bridge.
Because the panel hasn't attached yet, next_bridge is NULL. Passing a NULL bridge to drm_bridge_attach() returns -EINVAL. This seems to cause the display controller's probe to fail permanently instead of properly deferring via -EPROBE_DEFER.
I noticed this is resolved later in the series by commit b9977e0ebaa4d (drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available), but it introduces a regression at this point in the tree.
Also, does this introduce a data race on the bridge state when the panel attaches asynchronously?
Since the bridge is now exposed to the global bridge_list early, the DRM core or master could access it while the downstream panel is still probing. The dsi->bridge.next_bridge pointer and configurations like lanes, format, and mode_flags are updated later in samsung_dsim_host_attach() without acquiring any locks.
Is it possible for atomic callbacks or the DRM master's probe to read a partially-updated next_bridge pointer or uninitialized configuration state during this window?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
Maxime Ripard
maintainerRe: [PATCH 19/37] drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
In reply to Luca CeresoliQuoted 31 lines · Luca Ceresoli
This bridge driver calls
drm_bridge_add()in the DSI host .attach callback instead of in the probe function.This works for current use cases but is problematic for supporting hotplug of DRM bridges. The problematic case is when this DSI host is always present while its DSI device is hot-pluggable. In such case with the current code the DRM card will not be populated until after the DSI device attaches to the host, which could happen a very long time after booting, or even not happen at all.
The reason is that the previous pipeline component (the encoder in this case) when probing cannot find the samsung-dsim bridge. What happens is:
[1 and 2 can happen in any order, same result]
1) samsung-dsim probes (does notdrm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() returns -EPROBE_DEFER because the samsung-dsim is not in the global bridge_list (deferred probe pending: imx-lcdif: Cannot connect bridge)The samsung-dsim will not
drm_bridge_add()itself until a DSI device will try tomipi_dsi_attach()to the DSI Host, which can happen arbitratily late on hot-pluggable hardware.As a preliminary step to supporting hotplug move
drm_bridge_add()at probe time, so that the samsung-dsim DSI host bridge is available during boot, even without a connected DSI device. This results in:
Quoted 8 lines
1) samsung-dsim probes (and adds to
drm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() --> OK, returns samsung-dsim ptrSigned-off-by Luca Ceresoli <[email protected]>
We should probably amend
https://www.kernel.org/doc/html/latest/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges
To mention this use case here
Maxime
Luca Ceresoli
reviewerRe: [PATCH 19/37] drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
Quoted 39 lines · Maxime Ripard
Quoted 38 lines · Luca Ceresoli
This bridge driver calls
drm_bridge_add()in the DSI host .attach callback instead of in the probe function.This works for current use cases but is problematic for supporting hotplug of DRM bridges. The problematic case is when this DSI host is always present while its DSI device is hot-pluggable. In such case with the current code the DRM card will not be populated until after the DSI device attaches to the host, which could happen a very long time after booting, or even not happen at all.
The reason is that the previous pipeline component (the encoder in this case) when probing cannot find the samsung-dsim bridge. What happens is:
[1 and 2 can happen in any order, same result]
1) samsung-dsim probes (does notdrm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() returns -EPROBE_DEFER because the samsung-dsim is not in the global bridge_list (deferred probe pending: imx-lcdif: Cannot connect bridge)The samsung-dsim will not
drm_bridge_add()itself until a DSI device will try tomipi_dsi_attach()to the DSI Host, which can happen arbitratily late on hot-pluggable hardware.As a preliminary step to supporting hotplug move
drm_bridge_add()at probe time, so that the samsung-dsim DSI host bridge is available during boot, even without a connected DSI device. This results in:1) samsung-dsim probes (and adds to
drm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() --> OK, returns samsung-dsim ptr
Quoted 6 lines
Quoted 1 line
Signed-off-by Luca Ceresoli <[email protected]>We should probably amend
https://www.kernel.org/doc/html/latest/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridgesTo mention this use case here
Right. I haven't updated the docs for this v1 because I was not sure the overall approach would be acked. Now Dmitry acked it overall, and I kind of infer you are not against, so I'll look into updating the docs in v2.
However I find that section of the docs a bit hard to read especially from a newcomer perspective.
A better understanding on my side would help in doing the right change as far as this patch is concerned, and as a bonus in improving the section overall (that would probably be a separate series).
So I have a couple questions to start from:
* Do I understand correctly that using the component framework is legacy, not recommended for new DRM development, and that converting existing code to stop using it is welcome?
* The first bullet quotes "The upstream driver [...] isn’t a MIPI-DSI host". If the upstream driver of a MIPI DSI link isn't a MIPI DSI host, what else could it be? What are the use cases here?
* If read literally, none of the 4 bullets after "Indeed, there’s multiple cases that needs to be considered" covers this driver (it does not use the component framework, it does not use DCS, and the upstream device is a DSI host). However the 3 bullets after "The ideal pattern to cover the last item" appear to cover what this driver does. Do we need a fifth bullet for drivers like this one? Or...?
* To me it looks like the "bridge" word in this section is always used to refer to the DSI device. Would it make sense to replace "bridge" -> "[DSI ]device" in this section? (especially as the DSI host is also a DRM bridge)
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 19/37] drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
Quoted 45 lines · Luca Ceresoli
Quoted 44 lines · Maxime Ripard
Quoted 31 lines · Luca Ceresoli
This bridge driver calls
drm_bridge_add()in the DSI host .attach callback instead of in the probe function.This works for current use cases but is problematic for supporting hotplug of DRM bridges. The problematic case is when this DSI host is always present while its DSI device is hot-pluggable. In such case with the current code the DRM card will not be populated until after the DSI device attaches to the host, which could happen a very long time after booting, or even not happen at all.
The reason is that the previous pipeline component (the encoder in this case) when probing cannot find the samsung-dsim bridge. What happens is:
[1 and 2 can happen in any order, same result]
1) samsung-dsim probes (does notdrm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() returns -EPROBE_DEFER because the samsung-dsim is not in the global bridge_list (deferred probe pending: imx-lcdif: Cannot connect bridge)The samsung-dsim will not
drm_bridge_add()itself until a DSI device will try tomipi_dsi_attach()to the DSI Host, which can happen arbitratily late on hot-pluggable hardware.As a preliminary step to supporting hotplug move
drm_bridge_add()at probe time, so that the samsung-dsim DSI host bridge is available during boot, even without a connected DSI device. This results in:Quoted 8 lines
1) samsung-dsim probes (and adds to
drm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() --> OK, returns samsung-dsim ptrSigned-off-by Luca Ceresoli <[email protected]>We should probably amend
https://www.kernel.org/doc/html/latest/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridges
Quoted 8 lines
Quoted 1 line
To mention this use case here
Right. I haven't updated the docs for this v1 because I was not sure the overall approach would be acked. Now Dmitry acked it overall, and I kind of infer you are not against, so I'll look into updating the docs in v2.
However I find that section of the docs a bit hard to read especially from a newcomer perspective.
It's a complex problem, so I don't think we should expect the target audience to be newcomers. But maybe we can indeed improve it.
Quoted 9 lines
A better understanding on my side would help in doing the right change as far as this patch is concerned, and as a bonus in improving the section overall (that would probably be a separate series).
So I have a couple questions to start from:
* Do I understand correctly that using the component framework is legacy, not recommended for new DRM development, and that converting existing code to stop using it is welcome?
No. It's not legacy or deprecated. And about the conversion, I guess it's on a case-by-case basis? It's not encouraged or discouraged anyway.
Quoted 3 lines
* The first bullet quotes "The upstream driver [...] isn’t a MIPI-DSI host". If the upstream driver of a MIPI DSI link isn't a MIPI DSI host, what else could it be? What are the use cases here?
Nowhere is it said that we're considering a MIPI-DSI link here, so the use case is any bridge that isn't using MIPI-DSI at all.
Quoted 6 lines
* If read literally, none of the 4 bullets after "Indeed, there’s multiple cases that needs to be considered" covers this driver (it does not use the component framework, it does not use DCS, and the upstream device is a DSI host). However the 3 bullets after "The ideal pattern to cover the last item" appear to cover what this driver does. Do we need a fifth bullet for drivers like this one? Or...?
You tell me :)
How does hotplugging, say, a MIPI-DSI device bridge controlled over I2C, or a MIPI-DSI host bridge, affect the probing sequence, and can we end up in endless probe deferrals?
Quoted 3 lines
* To me it looks like the "bridge" word in this section is always used to refer to the DSI device. Would it make sense to replace "bridge" -> "[DSI ]device" in this section?
Not necessarily, and from a KMS point of view, MIPI-DSI doesn't exist, only bridge do.
Quoted 1 line
(especially as the DSI host is also a DRM bridge)
It doesn't have to be.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 19/37] drm/bridge: samsung-dsim: move drm_bridge_add() call to probe
Quoted 68 lines · Maxime Ripard
Quoted 45 lines · Luca Ceresoli
Quoted 44 lines · Maxime Ripard
Quoted 31 lines · Luca Ceresoli
This bridge driver calls
drm_bridge_add()in the DSI host .attach callback instead of in the probe function.This works for current use cases but is problematic for supporting hotplug of DRM bridges. The problematic case is when this DSI host is always present while its DSI device is hot-pluggable. In such case with the current code the DRM card will not be populated until after the DSI device attaches to the host, which could happen a very long time after booting, or even not happen at all.
The reason is that the previous pipeline component (the encoder in this case) when probing cannot find the samsung-dsim bridge. What happens is:
[1 and 2 can happen in any order, same result]
1) samsung-dsim probes (does notdrm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() returns -EPROBE_DEFER because the samsung-dsim is not in the global bridge_list (deferred probe pending: imx-lcdif: Cannot connect bridge)The samsung-dsim will not
drm_bridge_add()itself until a DSI device will try tomipi_dsi_attach()to the DSI Host, which can happen arbitratily late on hot-pluggable hardware.As a preliminary step to supporting hotplug move
drm_bridge_add()at probe time, so that the samsung-dsim DSI host bridge is available during boot, even without a connected DSI device. This results in:Quoted 8 lines
1) samsung-dsim probes (and adds to
drm_bridge_add()itself)
2) The lcdif starts probing multiple times, butlcdif_probe -> lcdif_load -> lcdif_attach_bridge -> devm_drm_of_get_bridge() --> OK, returns samsung-dsim ptrSigned-off-by Luca Ceresoli <[email protected]>We should probably amend
https://www.kernel.org/doc/html/latest/gpu/drm-kms-helpers.html#special-care-with-mipi-dsi-bridgesQuoted 8 lines
Quoted 1 line
To mention this use case here
Right. I haven't updated the docs for this v1 because I was not sure the overall approach would be acked. Now Dmitry acked it overall, and I kind of infer you are not against, so I'll look into updating the docs in v2.
However I find that section of the docs a bit hard to read especially from a newcomer perspective.
It's a complex problem, so I don't think we should expect the target audience to be newcomers. But maybe we can indeed improve it.
Quoted 9 lines
A better understanding on my side would help in doing the right change as far as this patch is concerned, and as a bonus in improving the section overall (that would probably be a separate series).
So I have a couple questions to start from:
* Do I understand correctly that using the component framework is legacy, not recommended for new DRM development, and that converting existing code to stop using it is welcome?
Quoted 8 lines
No. It's not legacy or deprecated. And about the conversion, I guess it's on a case-by-case basis? It's not encouraged or discouraged anyway.
Quoted 3 lines
* The first bullet quotes "The upstream driver [...] isn’t a MIPI-DSI host". If the upstream driver of a MIPI DSI link isn't a MIPI DSI host, what else could it be? What are the use cases here?
Nowhere is it said that we're considering a MIPI-DSI link here,
To me, the section title "Special Care with MIPI-DSI bridges" seems to suggest that.
What about rewording as "Possible driver combinations and their probe sequences" or the like?
Quoted 10 lines
so the
use case is any bridge that isn't using MIPI-DSI at all.Quoted 6 lines
* If read literally, none of the 4 bullets after "Indeed, there’s multiple cases that needs to be considered" covers this driver (it does not use the component framework, it does not use DCS, and the upstream device is a DSI host). However the 3 bullets after "The ideal pattern to cover the last item" appear to cover what this driver does. Do we need a fifth bullet for drivers like this one? Or...?
Quoted 5 lines
You tell me :)
How does hotplugging, say, a MIPI-DSI device bridge controlled over I2C, or a MIPI-DSI host bridge, affect the probing sequence, and can we end up in endless probe deferrals?
I'll try to write that in a fifth bullet in v2.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 20/37 drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available
In reply to Luca CeresoliWhen samsung_dsim_attach() is called but the next_bridge is not (yet) known, it calls drm_bridge_attach() unconditionally. In turn drm_bridge_attach() will return -EINVAL because the bridge pointer in NULL. -EINVAL is propagated transparently to the caller, resulting in the whole attach operation to fail.
This is fine for current use cases, but not when introducing for bridge hotplug, which implies the next bridge could be hot-plugged later on.
In preparation to support bridge hotplug, consider the absence of a next_bridge an -EPROBE_DEFER, not a hard error.
--- drivers/gpu/drm/bridge/samsung-dsim.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/bridge/samsung-dsim.c +3 -0
@@ -1828,6 +1828,9 @@ static int samsung_dsim_attach(struct drm_bridge *bridge, {struct samsung_dsim *dsi =bridge_to_dsi (bridge); +if (!dsi->bridge.next_bridge) +return -EPROBE_DEFER ; +return drm_bridge_attach (encoder, dsi->bridge.next_bridge, bridge, flags); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 20/37] drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Double fetch of `dsi->bridge.next_bridge` in `samsung_dsim_attach()` causes a race condition…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Double fetch of dsi->bridge.next_bridge in samsung_dsim_attach() causes a race condition leading to unintended -EINVAL errors or Use-After-Free. --
commit b9977e0ebaa4dd776acdd10e8085cc7df8ae862c
Author: Luca Ceresoli <[email protected]>
drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available
When samsung_dsim_attach() is called without a known next_bridge, it previously returned -EINVAL. This commit changes it to return -EPROBE_DEFER instead, in preparation for bridge hotplug support.
Quoted 1 line
drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available
This isn't a bug, but there is a typo in the subject line ("is" instead of "if").
drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_attach(struct drm_bridge *bridge, · line 1835
Quoted 13 lines
drivers/gpu/drm/bridge/samsung-dsim.c +3
-0@@ -1828,6 +1828,9 @@ static int samsung_dsim_attach(struct drm_bridge *bridge, {struct samsung_dsim *dsi =bridge_to_dsi (bridge); +if (!dsi->bridge.next_bridge) +return -EPROBE_DEFER ; +return drm_bridge_attach (encoder, dsi->bridge.next_bridge, bridge, flags);
Can this double fetch of dsi->bridge.next_bridge cause a race condition leading to unintended -EINVAL errors or a use-after-free?
The commit message states this change is in preparation for bridge hotplug, meaning hot-unplug events could occur concurrently.
If a detach executes concurrently during an unplug event, it could clear dsi->bridge.next_bridge between the if check and the call to drm_bridge_attach(). This would cause the first fetch to see a valid pointer, but the second fetch to read NULL, resulting in drm_bridge_attach() returning -EINVAL instead of -EPROBE_DEFER.
Furthermore, even if the value is fetched into a local variable to prevent the double fetch, could the bridge be freed by the concurrent detach before drm_bridge_attach() takes its own reference?
Does this require proper synchronization, such as holding a lock while checking and obtaining a reference to the bridge?
Quoted 1 line
drivers/gpu/drm/bridge/samsung-dsim.c +0
-0}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
Luca Ceresoli
reviewerPATCH 21/37 drm/bridge: initialize chain_node list head on allocation
In reply to Luca CeresoliIn preparation to add a check to detect whether a bridge is not yet attached, ensure the chain_node list_head is always empty [as in list_empty()] since it is allocated, until it is attached.
--- drivers/gpu/drm/drm_bridge.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_bridge.c +1 -0
@@ -378,6 +378,7 @@ void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,return ERR_PTR (-ENOMEM ); bridge = container + offset; +INIT_LIST_HEAD (&bridge->chain_node);INIT_LIST_HEAD (&bridge->list); bridge->container = container; bridge->funcs = funcs;
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 22/37 drm/bridge: initialize chain_node list head on detach and attach errors
In reply to Luca CeresoliWhen a bridge is detached it is removed from the encoder bridge_chain list, but the bridge::chain_node list head is not cleared. This is going to be problematic with the upcoming hotplug bridge support because if a bridge is detached from the encoder chain but not yet removed, when later detaching it the encoder code may think it is still attached, thus trying to detach it twice.
Avoid this by clearing the list head on detach, so there's a clear and simple way to know when a bridge is not attached anymore.
Do the same in the error management code in drm_bridge_attach(), so that chain_node is always empty [as in list_empty()] when it is not (yet|anymore) in the bridge chain.
--- drivers/gpu/drm/drm_bridge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_bridge.c +2 -2
@@ -598,7 +598,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, bridge->dev =NULL ; bridge->encoder =NULL ;mutex_lock (&encoder->bridge_chain_mutex); -list_del (&bridge->chain_node); +list_del_init (&bridge->chain_node);mutex_unlock (&encoder->bridge_chain_mutex);if (ret != -EPROBE_DEFER )
@@ -629,7 +629,7 @@ void drm_bridge_detach(struct drm_bridge *bridge)if (bridge->funcs->detach) bridge->funcs->detach (bridge); -list_del (&bridge->chain_node); +list_del_init (&bridge->chain_node); bridge->dev =NULL ;drm_bridge_put (bridge); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 22/37] drm/bridge: initialize chain_node list head on detach and attach errors
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Data race and NULL pointer dereference in drm_bridge_attach() error path during dynamic hotplug --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Data race and NULL pointer dereference in drm_bridge_attach() error path during dynamic hotplug --
commit b83693320d718d054d9327b487d4044213901c1e
Author: Luca Ceresoli <[email protected]>
drm/bridge: initialize chain_node list head on detach and attach errors
This commit updates drm_bridge_detach() and the error path of drm_bridge_attach() to use list_del_init() instead of list_del(). This ensures the bridge chain_node list head is clearly empty when detached, preventing double-detach issues during hotplug operations.
drivers/gpu/drm/drm_bridge.c int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, · line 602
Quoted 11 lines
drivers/gpu/drm/drm_bridge.c +1
-1@@ -598,7 +598,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, bridge->dev =NULL ; bridge->encoder =NULL ;mutex_lock (&encoder->bridge_chain_mutex); -list_del (&bridge->chain_node); +list_del_init (&bridge->chain_node);mutex_unlock (&encoder->bridge_chain_mutex);
This is an existing issue not introduced by this patch, but since dynamic bridge hotplugging support is being introduced, can this sequence cause a NULL pointer dereference?
In this error path, bridge->dev and bridge->encoder are cleared to NULL outside the encoder->bridge_chain_mutex critical section, while the bridge is still linked into the encoder->bridge_chain.
If drm_bridge_attach() is executed at runtime and fails, a concurrent userspace atomic modeset iterating over encoder->bridge_chain could observe the bridge with bridge->encoder == NULL. Drivers typically use this to fetch the connector:
connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder);
If bridge->encoder is NULL, this returns a NULL connector, which could lead to a crash when calling drm_connector_index(connector).
Should the field assignments be moved inside the mutex-protected block, or after the bridge is removed from the list?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
Luca Ceresoli
reviewerPATCH 23/37 drm/encoder: add drm_encoder_cleanup_from()
In reply to Luca CeresoliSupporting hardware whose final part of the DRM pipeline can be physically removed requires the ability to detach all bridges from a given point to the end of the pipeline.
Introduce a variant of drm_encoder_cleanup() for this.
Take care to not try detaching non-attached bridges. This is needed because when two or more bridges are removed not in the backwards order, drm_encoder_cleanup_from() is called more than once for bridges closer to the panel.
---
Note: in theory drm_encoder_cleanup() is now a superset of drm_encoder_cleanup_from() and may be simplified to just call drm_encoder_cleanup_from() and then do the extra actions. However the common code is subtly different in terms of locking and checks, so this would complicate the code in this patch and has thus been kept separate for the time being to make reviewing sompler. Reimplementing drm_encoder_cleanup() by using drm_encoder_cleanup_from() cvacn be done later on.
A much simpler and now obsolete version of this patch (missing locking and checks) previously appeared in
https://lore.kernel.org/lkml/[email protected]/
--- drivers/gpu/drm/drm_encoder.c | 38 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_encoder.h | 1 + 2 files changed, 39 insertions(+)
drivers/gpu/drm/drm_encoder.c +38 -0
@@ -179,6 +179,44 @@ int drm_encoder_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_encoder_init); +/** +* drm_encoder_cleanup_from - remove a given bridge and all the following +* @encoder: encoder whole list of bridges shall be pruned +* @bridge: first bridge to remove +* +* Removes from an encoder all the bridges starting with a given bridge +* and until the end of the chain. +* +* Does nothing if the bridge is not attached to an encoder chain. +* +* This should not be used in "normal" DRM pipelines. It is only useful for +* devices whose final part of the DRM chain can be physically removed and +* later reconnected (possibly with different hardware). +*/ +void drm_encoder_cleanup_from (struct drm_encoder *encoder,struct drm_bridge *bridge) +{ +struct drm_bridge *next; +LIST_HEAD (tmplist); + +/* +* We need the bridge_chain_mutex to modify the chain, but +* drm_bridge_detach() will call DRM_MODESET_LOCK_ALL_BEGIN() (in +* drm_modeset_lock_fini()), resulting in a possible ABBA circular +* deadlock. Avoid it by first moving all the bridges to a +* temporary list holding the lock, and then calling +* drm_bridge_detach() without the lock. +*/ +mutex_lock (&encoder->bridge_chain_mutex); +if (!list_empty (&bridge->chain_node)) +list_for_each_entry_safe_from (bridge, next, &encoder->bridge_chain, chain_node) +list_move_tail (&bridge->chain_node, &tmplist); +mutex_unlock (&encoder->bridge_chain_mutex); + +while (!list_empty (&tmplist)) + drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node)); +} +EXPORT_SYMBOL (drm_encoder_cleanup_from); +/** * drm_encoder_cleanup - cleans up an initialised encoder * @encoder: encoder to cleanup
include/drm/drm_encoder.h +1 -0
@@ -324,6 +324,7 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, }void drm_encoder_cleanup (struct drm_encoder *encoder); +void drm_encoder_cleanup_from (struct drm_encoder *encoder,struct drm_bridge *bridge);/** * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 23/37] drm/encoder: add drm_encoder_cleanup_from()
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Infinite loop (kernel lockup) if `drm_bridge_detach()` returns early. - [High] Unsafe list…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Infinite loop (kernel lockup) if drm_bridge_detach() returns early.
- [High] Unsafe list membership check leads to out-of-bounds traversal and memory corruption.
- [High] Moving bridges to a stack list breaks bridge chain iterators during detach callbacks. --
commit 36261e8ecb547e8946c95a0aed4ce37428b2d56e
Author: Luca Ceresoli <[email protected]>
drm/encoder: add drm_encoder_cleanup_from()
Introduce a variant of drm_encoder_cleanup() to detach all bridges from a given point to the end of the pipeline.
Quoted 3 lines
drivers/gpu/drm/drm_encoder.c +0
-0
[ ... ]
Quoted 7 lines
drivers/gpu/drm/drm_encoder.c +7
-0+void drm_encoder_cleanup_from (struct drm_encoder *encoder,struct drm_bridge *bridge) +{ +struct drm_bridge *next; +LIST_HEAD (tmplist); + +/* +* We need the bridge_chain_mutex to modify the chain, but
[ ... ]
drivers/gpu/drm/drm_encoder.c int drm_encoder_init(struct drm_device *dev, · line 213
Quoted 6 lines
drivers/gpu/drm/drm_encoder.c +6
-0+*/ +mutex_lock (&encoder->bridge_chain_mutex); +if (!list_empty (&bridge->chain_node)) +list_for_each_entry_safe_from (bridge, next, &encoder->bridge_chain, chain_node) +list_move_tail (&bridge->chain_node, &tmplist); +mutex_unlock (&encoder->bridge_chain_mutex);
Could this list_empty() check lead to an out-of-bounds traversal?
The check confirms the bridge is on a list, but not necessarily the provided encoder's chain. If a caller mistakenly passes a bridge from a different encoder, or if a concurrent caller processes a bridge already moved to another thread's tmplist, list_for_each_entry_safe_from() will iterate over that unrelated list.
Since the loop termination checks against &encoder->bridge_chain, it will never find the list head, running past the end of the foreign list and corrupting memory.
drivers/gpu/drm/drm_encoder.c int drm_encoder_init(struct drm_device *dev, · line 216
Quoted 3 lines
drivers/gpu/drm/drm_encoder.c +3
-0+ +while (!list_empty (&tmplist)) + drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node));
Can this loop become infinite if drm_bridge_detach() returns early?
Looking at drm_bridge_detach() in drm_bridge.c:
void drm_bridge_detach(struct drm_bridge *bridge)
{
if (WARN_ON(!bridge))
return;
if (WARN_ON(!bridge->dev))
return;
...
list_del_init(&bridge->chain_node);...
If an early return triggers before list_del_init(), the bridge remains in tmplist. The list never becomes empty, and the loop will process the exact same failing bridge indefinitely. Should the bridge be unlinked from the temporary list before calling drm_bridge_detach()?
Also, does moving bridges to a stack-allocated tmplist break bridge chain iterators during the detach callbacks?
drm_bridge_detach() executes bridge->funcs->detach(bridge). If a driver calls a chain traversal API like drm_bridge_chain_get_next_bridge() during this detach callback, the macro checks:
list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain)
Because the bridge is currently on tmplist (a stack variable), this boundary check fails. This causes the iterator to read past the list end, returning the stack tmplist head cast as a struct drm_bridge *, leading to memory corruption.
Quoted 2 lines
drivers/gpu/drm/drm_encoder.c +2
-0+} +EXPORT_SYMBOL (drm_encoder_cleanup_from);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
Maxime Ripard
maintainerRe: [PATCH 23/37] drm/encoder: add drm_encoder_cleanup_from()
In reply to Luca CeresoliQuoted 68 lines · Luca Ceresoli
Supporting hardware whose final part of the DRM pipeline can be physically removed requires the ability to detach all bridges from a given point to the end of the pipeline.
Introduce a variant of
drm_encoder_cleanup()for this.Take care to not try detaching non-attached bridges. This is needed because when two or more bridges are removed not in the backwards order,
drm_encoder_cleanup_from()is called more than once for bridges closer to the panel.Signed-off-by Luca Ceresoli <[email protected]>---
Note: in theory
drm_encoder_cleanup()is now a superset ofdrm_encoder_cleanup_from()and may be simplified to just calldrm_encoder_cleanup_from()and then do the extra actions. However the common code is subtly different in terms of locking and checks, so this would complicate the code in this patch and has thus been kept separate for the time being to make reviewing sompler. Reimplementingdrm_encoder_cleanup()by usingdrm_encoder_cleanup_from()cvacn be done later on.A much simpler and now obsolete version of this patch (missing locking and checks) previously appeared in
https://lore.kernel.org/lkml/[email protected]/--- drivers/gpu/drm/drm_encoder.c | 38 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_encoder.h | 1 + 2 files changed, 39 insertions(+)drivers/gpu/drm/drm_encoder.c +28
-0@@ -179,6 +179,44 @@ int drm_encoder_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_encoder_init); +/** +* drm_encoder_cleanup_from - remove a given bridge and all the following +* @encoder: encoder whole list of bridges shall be pruned +* @bridge: first bridge to remove +* +* Removes from an encoder all the bridges starting with a given bridge +* and until the end of the chain. +* +* Does nothing if the bridge is not attached to an encoder chain. +* +* This should not be used in "normal" DRM pipelines. It is only useful for +* devices whose final part of the DRM chain can be physically removed and +* later reconnected (possibly with different hardware). +*/ +void drm_encoder_cleanup_from (struct drm_encoder *encoder,struct drm_bridge *bridge) +{ +struct drm_bridge *next; +LIST_HEAD (tmplist); + +/* +* We need the bridge_chain_mutex to modify the chain, but +* drm_bridge_detach() will call DRM_MODESET_LOCK_ALL_BEGIN() (in +* drm_modeset_lock_fini()), resulting in a possible ABBA circular +* deadlock. Avoid it by first moving all the bridges to a +* temporary list holding the lock, and then calling +* drm_bridge_detach() without the lock. +*/ +mutex_lock (&encoder->bridge_chain_mutex);
drivers/gpu/drm/drm_encoder.c int drm_encoder_init(struct drm_device *dev, · line 219
Quoted 10 lines
drivers/gpu/drm/drm_encoder.c +10
-0+if (!list_empty (&bridge->chain_node)) +list_for_each_entry_safe_from (bridge, next, &encoder->bridge_chain, chain_node) +list_move_tail (&bridge->chain_node, &tmplist); +mutex_unlock (&encoder->bridge_chain_mutex); + +while (!list_empty (&tmplist)) + drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node)); +} +EXPORT_SYMBOL (drm_encoder_cleanup_from); +
The name is super confusing, because it doesn't clean up anything. drm_encoder_cleanup is called that way because it cleans up the encoder. This function doesn't.
Unlike what's being documented, it doesn't remove any bridge either. It just detaches bridge, so let's just call it that way?
Maxime
Luca Ceresoli
reviewerRe: [PATCH 23/37] drm/encoder: add drm_encoder_cleanup_from()
Quoted 84 lines · Maxime Ripard
Quoted 68 lines · Luca Ceresoli
Supporting hardware whose final part of the DRM pipeline can be physically removed requires the ability to detach all bridges from a given point to the end of the pipeline.
Introduce a variant of
drm_encoder_cleanup()for this.Take care to not try detaching non-attached bridges. This is needed because when two or more bridges are removed not in the backwards order,
drm_encoder_cleanup_from()is called more than once for bridges closer to the panel.Signed-off-by Luca Ceresoli <[email protected]>---
Note: in theory
drm_encoder_cleanup()is now a superset ofdrm_encoder_cleanup_from()and may be simplified to just calldrm_encoder_cleanup_from()and then do the extra actions. However the common code is subtly different in terms of locking and checks, so this would complicate the code in this patch and has thus been kept separate for the time being to make reviewing sompler. Reimplementingdrm_encoder_cleanup()by usingdrm_encoder_cleanup_from()cvacn be done later on.A much simpler and now obsolete version of this patch (missing locking and checks) previously appeared in
https://lore.kernel.org/lkml/[email protected]/--- drivers/gpu/drm/drm_encoder.c | 38 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_encoder.h | 1 + 2 files changed, 39 insertions(+)drivers/gpu/drm/drm_encoder.c +28
-0@@ -179,6 +179,44 @@ int drm_encoder_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_encoder_init); +/** +* drm_encoder_cleanup_from - remove a given bridge and all the following +* @encoder: encoder whole list of bridges shall be pruned +* @bridge: first bridge to remove +* +* Removes from an encoder all the bridges starting with a given bridge +* and until the end of the chain. +* +* Does nothing if the bridge is not attached to an encoder chain. +* +* This should not be used in "normal" DRM pipelines. It is only useful for +* devices whose final part of the DRM chain can be physically removed and +* later reconnected (possibly with different hardware). +*/ +void drm_encoder_cleanup_from (struct drm_encoder *encoder,struct drm_bridge *bridge) +{ +struct drm_bridge *next; +LIST_HEAD (tmplist); + +/* +* We need the bridge_chain_mutex to modify the chain, but +* drm_bridge_detach() will call DRM_MODESET_LOCK_ALL_BEGIN() (in +* drm_modeset_lock_fini()), resulting in a possible ABBA circular +* deadlock. Avoid it by first moving all the bridges to a +* temporary list holding the lock, and then calling +* drm_bridge_detach() without the lock. +*/ +mutex_lock (&encoder->bridge_chain_mutex);drivers/gpu/drm/drm_encoder.c int drm_encoder_init(struct drm_device *dev, · line 219
Quoted 10 lines
drivers/gpu/drm/drm_encoder.c +10
-0+if (!list_empty (&bridge->chain_node)) +list_for_each_entry_safe_from (bridge, next, &encoder->bridge_chain, chain_node) +list_move_tail (&bridge->chain_node, &tmplist); +mutex_unlock (&encoder->bridge_chain_mutex); + +while (!list_empty (&tmplist)) + drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node)); +} +EXPORT_SYMBOL (drm_encoder_cleanup_from); +The name is super confusing, because it doesn't clean up anything.
drm_encoder_cleanupis called that way because it cleans up the encoder. This function doesn't.
Quoted 2 lines
Unlike what's being documented, it doesn't remove any bridge either. It just detaches bridge, so let's just call it that way?
Good point.
What about:
* rename to drm_bridge_detach_from()
* drop the @encoder argument (get if from bridge->encoder)
* maybe even move to drm_bridge.c?
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 23/37] drm/encoder: add drm_encoder_cleanup_from()
Quoted 88 lines · Luca Ceresoli
Quoted 84 lines · Maxime Ripard
Quoted 68 lines · Luca Ceresoli
Supporting hardware whose final part of the DRM pipeline can be physically removed requires the ability to detach all bridges from a given point to the end of the pipeline.
Introduce a variant of
drm_encoder_cleanup()for this.Take care to not try detaching non-attached bridges. This is needed because when two or more bridges are removed not in the backwards order,
drm_encoder_cleanup_from()is called more than once for bridges closer to the panel.Signed-off-by Luca Ceresoli <[email protected]>---
Note: in theory
drm_encoder_cleanup()is now a superset ofdrm_encoder_cleanup_from()and may be simplified to just calldrm_encoder_cleanup_from()and then do the extra actions. However the common code is subtly different in terms of locking and checks, so this would complicate the code in this patch and has thus been kept separate for the time being to make reviewing sompler. Reimplementingdrm_encoder_cleanup()by usingdrm_encoder_cleanup_from()cvacn be done later on.A much simpler and now obsolete version of this patch (missing locking and checks) previously appeared in
https://lore.kernel.org/lkml/[email protected]/--- drivers/gpu/drm/drm_encoder.c | 38 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_encoder.h | 1 + 2 files changed, 39 insertions(+)drivers/gpu/drm/drm_encoder.c +28
-0@@ -179,6 +179,44 @@ int drm_encoder_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_encoder_init); +/** +* drm_encoder_cleanup_from - remove a given bridge and all the following +* @encoder: encoder whole list of bridges shall be pruned +* @bridge: first bridge to remove +* +* Removes from an encoder all the bridges starting with a given bridge +* and until the end of the chain. +* +* Does nothing if the bridge is not attached to an encoder chain. +* +* This should not be used in "normal" DRM pipelines. It is only useful for +* devices whose final part of the DRM chain can be physically removed and +* later reconnected (possibly with different hardware). +*/ +void drm_encoder_cleanup_from (struct drm_encoder *encoder,struct drm_bridge *bridge) +{ +struct drm_bridge *next; +LIST_HEAD (tmplist); + +/* +* We need the bridge_chain_mutex to modify the chain, but +* drm_bridge_detach() will call DRM_MODESET_LOCK_ALL_BEGIN() (in +* drm_modeset_lock_fini()), resulting in a possible ABBA circular +* deadlock. Avoid it by first moving all the bridges to a +* temporary list holding the lock, and then calling +* drm_bridge_detach() without the lock. +*/ +mutex_lock (&encoder->bridge_chain_mutex);drivers/gpu/drm/drm_encoder.c int drm_encoder_init(struct drm_device *dev, · line 219
Quoted 10 lines
drivers/gpu/drm/drm_encoder.c +10
-0+if (!list_empty (&bridge->chain_node)) +list_for_each_entry_safe_from (bridge, next, &encoder->bridge_chain, chain_node) +list_move_tail (&bridge->chain_node, &tmplist); +mutex_unlock (&encoder->bridge_chain_mutex); + +while (!list_empty (&tmplist)) + drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node)); +} +EXPORT_SYMBOL (drm_encoder_cleanup_from); +The name is super confusing, because it doesn't clean up anything.
drm_encoder_cleanupis called that way because it cleans up the encoder. This function doesn't.Quoted 2 lines
Unlike what's being documented, it doesn't remove any bridge either. It just detaches bridge, so let's just call it that way?
Quoted 7 lines
Good point.
What about:
* rename to
drm_bridge_detach_from()
* drop the @encoder argument (get if frombridge->encoder)
* maybe even move todrm_bridge.c?
Yeah, sounds good
Maxime
Luca Ceresoli
reviewerPATCH 24/37 drm/atomic: move drm_atomic_helper_disable_all() and drm_atomic_helper_shutdown() from drm_atomic_helper to drm_atomic
In reply to Luca CeresoliTo support the upcoming DRM bridge hotplug, the drm_bridge.c code will need to call drm_atomic_helper_shutdown() to disable the pipeline when the tail bridges of the pipeline are removed without tearing down the card.
However this would create a module dependency loop between the drm module (where drm_encoder is) and the drm_kms_helper module where drm_atomic_helper_shutdown() function currently is and which already depends on the drm module.
Solve by moving drm_atomic_helper_shutdown(), along with its callee drm_atomic_helper_disable_all(), to drm_atomic which is in the drm module. Use identical names except for dropping the "_helper" infix, and make the original functions a deprecated wrapper to the new ones.
No changes to the functions body.
No functional changes except for moving the code to a different module.
--- drivers/gpu/drm/drm_atomic.c | 115 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_atomic_helper.c | 76 ++---------------------- include/drm/drm_atomic.h | 3 + 3 files changed, 124 insertions(+), 70 deletions(-)
drivers/gpu/drm/drm_atomic.c +115 -0
@@ -1993,6 +1993,121 @@ int __drm_atomic_helper_set_config(struct drm_mode_set *set, }EXPORT_SYMBOL (__drm_atomic_helper_set_config); +/** +* drm_atomic_disable_all - disable all currently active outputs +* @dev: DRM device +* @ctx: lock acquisition context +* +* Loops through all connectors, finding those that aren't turned off and then +* turns them off by setting their DPMS mode to OFF and deactivating the CRTC +* that they are connected to. +* +* This is used for example in suspend/resume to disable all currently active +* functions when suspending. If you just want to shut down everything at e.g. +* driver unload, look at drm_atomic_helper_shutdown(). +* +* Note that if callers haven't already acquired all modeset locks this might +* return -EDEADLK, which must be handled by calling drm_modeset_backoff(). +* +* Returns: +* 0 on success or a negative error code on failure. +* +* See also: +* drm_atomic_helper_suspend(), drm_atomic_helper_resume() and +* drm_atomic_helper_shutdown(). +*/ +int drm_atomic_disable_all (struct drm_device *dev, +struct drm_modeset_acquire_ctx *ctx) +{ +struct drm_atomic_commit *state; +struct drm_connector_state *conn_state; +struct drm_connector *conn; +struct drm_plane_state *plane_state; +struct drm_plane *plane; +struct drm_crtc_state *crtc_state; +struct drm_crtc *crtc; +int ret, i; + + state =drm_atomic_commit_alloc (dev); +if (!state) +return -ENOMEM ; + + state->acquire_ctx = ctx; + +drm_for_each_crtc (crtc, dev) { + crtc_state =drm_atomic_get_crtc_state (state, crtc); +if (IS_ERR (crtc_state)) { + ret =PTR_ERR (crtc_state); + goto free; + } + + crtc_state->active = false; + + ret =drm_atomic_set_mode_prop_for_crtc (crtc_state,NULL ); +if (ret <0 ) + goto free; + + ret =drm_atomic_add_affected_planes (state, crtc); +if (ret <0 ) + goto free; + + ret =drm_atomic_add_affected_connectors (state, crtc); +if (ret <0 ) + goto free; + } + +for_each_new_connector_in_state (state, conn, conn_state, i) { + ret =drm_atomic_set_crtc_for_connector (conn_state,NULL ); +if (ret <0 ) + goto free; + } + +for_each_new_plane_in_state (state, plane, plane_state, i) { + ret =drm_atomic_set_crtc_for_plane (plane_state,NULL ); +if (ret <0 ) + goto free; + +drm_atomic_set_fb_for_plane (plane_state,NULL ); + } + + ret =drm_atomic_commit (state); +free: +drm_atomic_commit_put (state); +return ret; +} +EXPORT_SYMBOL (drm_atomic_disable_all); + +/** +* drm_atomic_shutdown - shutdown all CRTC +* @dev: DRM device +* +* This shuts down all CRTC, which is useful for driver unloading. Shutdown on +* suspend should instead be handled with drm_atomic_helper_suspend(), since +* that also takes a snapshot of the modeset state to be restored on resume. +* +* This is just a convenience wrapper around drm_atomic_helper_disable_all(), +* and it is the atomic version of drm_helper_force_disable_all(). +*/ +void drm_atomic_shutdown (struct drm_device *dev) +{ +struct drm_modeset_acquire_ctx ctx; +int ret; + +if (dev ==NULL ) +return ; + +DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx,0 , ret); + + ret =drm_atomic_disable_all (dev, &ctx); +if (ret) +drm_err (dev, +"Disabling all crtc's during unload failed with %i\n" , + ret); + +DRM_MODESET_LOCK_ALL_END (dev, ctx, ret); +} +EXPORT_SYMBOL (drm_atomic_shutdown); +static void drm_atomic_private_obj_print_state (struct drm_printer *p,const struct drm_private_state *state) {
drivers/gpu/drm/drm_atomic_helper.c +6 -70
100 lines not on this page · raw message
include/drm/drm_atomic.h +3 -0
@@ -1373,5 +1373,8 @@ drm_atomic_get_old_bridge_state(const struct drm_atomic_commit *state,struct drm_bridge_state *drm_atomic_get_new_bridge_state (const struct drm_atomic_commit *state,struct drm_bridge *bridge); +int drm_atomic_disable_all (struct drm_device *dev, +struct drm_modeset_acquire_ctx *ctx); +void drm_atomic_shutdown (struct drm_device *dev);#endif /* DRM_ATOMIC_H_ */
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 24/37] drm/atomic: move drm_atomic_helper_disable_all() and drm_atomic_helper_shutdown() from drm_atomic_helper to drm_atomic
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Outdated function references in kernel-doc blocks after rename. - [Low] Use of return with an…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Outdated function references in kernel-doc blocks after rename.
- [Low] Use of return with an expression in a void function.
--
commit 8c33c13c9d809fde9c0dc4ffcc59c09b05d47d10
Author: Luca Ceresoli <[email protected]>
drm/atomic: move drm_atomic_helper_disable_all() and drm_atomic_helper_shutdown() from drm_atomic_helper to drm_atomic
This commit moves drm_atomic_helper_shutdown() and drm_atomic_helper_disable_all() to the drm_atomic module, renaming them to drop the "_helper" infix. The move resolves a module dependency loop to support upcoming DRM bridge hotplug features, replacing the original functions with deprecated wrappers.
Quoted 5 lines
drivers/gpu/drm/drm_atomic.c +0
-0@@ -1987,6 +1987,121 @@ int __drm_atomic_helper_set_config(struct drm_mode_set *set,
[ ... ]
Quoted 3 lines
+ * This is used for example in suspend/resume to disable all currently active
+ * functions when suspending. If you just want to shut down everything at e.g.
+ * driver unload, look atdrm_atomic_helper_shutdown().
This isn't a bug, but since the functions were renamed, should this kernel-doc comment be updated to point to the new drm_atomic_shutdown() function instead of the deprecated drm_atomic_helper_shutdown() wrapper?
[ ... ]
Quoted 5 lines
+ * See also:
+ *drm_atomic_helper_suspend(),drm_atomic_helper_resume()and
+ *drm_atomic_helper_shutdown().
+ */
+int drm_atomic_disable_all(structdrm_device*dev,
Similar to the above, should this refer to drm_atomic_shutdown()?
[ ... ]
drivers/gpu/drm/drm_atomic.c int __drm_atomic_helper_set_config(struct drm_mode_set *set, · line 2091
Quoted 12 lines
drivers/gpu/drm/drm_atomic.c +12
-0+/** +* drm_atomic_shutdown - shutdown all CRTC +* @dev: DRM device +* +* This shuts down all CRTC, which is useful for driver unloading. Shutdown on +* suspend should instead be handled with drm_atomic_helper_suspend(), since +* that also takes a snapshot of the modeset state to be restored on resume. +* +* This is just a convenience wrapper around drm_atomic_helper_disable_all(), +* and it is the atomic version of drm_helper_force_disable_all(). +*/ +void drm_atomic_shutdown (struct drm_device *dev)
Should this documentation state that it is a wrapper around the new drm_atomic_disable_all() rather than the deprecated drm_atomic_helper_disable_all()?
Quoted 4 lines
drivers/gpu/drm/drm_atomic_helper.c +0
-0
[ ... ]
Quoted 11 lines
drivers/gpu/drm/drm_atomic_helper.c +0
-7@@ -3673,21 +3623,7 @@ EXPORT_SYMBOL(drm_atomic_helper_reset_crtc);*/ void drm_atomic_helper_shutdown (struct drm_device *dev) { -struct drm_modeset_acquire_ctx ctx; -int ret; - -if (dev ==NULL ) -return ; - -DRM_MODESET_LOCK_ALL_BEGIN (dev, ctx,0 , ret);
drivers/gpu/drm/drm_atomic_helper.c EXPORT_SYMBOL(drm_atomic_helper_reset_crtc); · line 3627
Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +1
-8- - ret =drm_atomic_helper_disable_all (dev, &ctx); -if (ret) -drm_err (dev, -"Disabling all crtc's during unload failed with %i\n" , - ret); - -DRM_MODESET_LOCK_ALL_END (dev, ctx, ret); +return drm_atomic_shutdown (dev); }
Since both drm_atomic_helper_shutdown() and drm_atomic_shutdown() are declared as returning void, does returning an expression here violate ISO C standards? It might be better to just call drm_atomic_shutdown(dev) without the return keyword to avoid compiler warnings from stricter configurations like sparse or Clang.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
Luca Ceresoli
reviewerPATCH 25/37 drm/bridge: shutdown and cleanup on bridge unplug
In reply to Luca CeresoliWith the upcoming support for DRM bridge hot(un)plugging, bridges can be removed at any time withotu tearing down the entire card. When this happens, shutdown the pipeline and detach from the encoder chain the bridge being removed along with all the following ones.
--- drivers/gpu/drm/drm_bridge.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/drm_bridge.c +8 -0
@@ -462,9 +462,17 @@ EXPORT_SYMBOL(devm_drm_bridge_add);* 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. +* +* If the bridge is attached, also disable the active output and detach +* this bridge and the following ones. */ void drm_bridge_remove (struct drm_bridge *bridge) { +if (bridge->encoder) { +drm_atomic_shutdown (bridge->dev); +drm_encoder_cleanup_from (bridge->encoder, bridge); + } +mutex_lock (&bridge_lock);list_move_tail (&bridge->list, &bridge_lingering_list);mutex_unlock (&bridge_lock);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 25/37] drm/bridge: shutdown and cleanup on bridge unplug
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Use-After-Free (UAF) due to dangling `bridge->encoder` pointer - [Critical] Stack corruption…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Use-After-Free (UAF) due to dangling bridge->encoder pointer
- [Critical] Stack corruption via cross-thread list iteration in drm_encoder_cleanup_from()
- [High] Unintended system-wide display shutdown (Logic Error)
--
commit c68fe5f8aeb721d87ce6a0a639bb852359b46771
Author: Luca Ceresoli <[email protected]>
drm/bridge: shutdown and cleanup on bridge unplug
This commit aims to handle DRM bridge hot-unplugging by shutting down the pipeline and detaching the removed bridge and subsequent ones, rather than tearing down the entire card.
Quoted 2 lines
With the upcoming support for DRM bridge hot(un)plugging, bridges can be removed at any time withotu tearing down the entire card.
The commit message states the patch avoids tearing down the entire card, but looking at the code, could this implementation still cause a system-wide display shutdown?
Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +0
-0
[ ... ]
drivers/gpu/drm/drm_bridge.c EXPORT_SYMBOL(devm_drm_bridge_add); · line 465
Quoted 5 lines
drivers/gpu/drm/drm_bridge.c +2
-0@@ -462,9 +462,17 @@ EXPORT_SYMBOL(devm_drm_bridge_add);void drm_bridge_remove (struct drm_bridge *bridge) { +if (bridge->encoder) { +drm_atomic_shutdown (bridge->dev);
Looking at drm_atomic_shutdown(), it unconditionally calls drm_atomic_disable_all(dev, &ctx), which disables all CRTCs on the device.
If a single bridge is hot-unplugged, won't this unexpectedly shut down all other independent, active displays on the same system?
drivers/gpu/drm/drm_bridge.c EXPORT_SYMBOL(devm_drm_bridge_add); · line 473
Quoted 1 line
drivers/gpu/drm/drm_bridge.c +1
-0+drm_encoder_cleanup_from (bridge->encoder, bridge);
Is there a possibility of a use-after-free here if bridge->encoder is left dangling?
When a DRM device is torn down, drm_encoder_cleanup() iterates over the chain and calls drm_bridge_detach(). That function clears bridge->dev but does not clear bridge->encoder, and the encoder memory is subsequently freed.
Later, when the bridge driver is unbound, drm_bridge_remove() is executed. Since bridge->encoder is never cleared, it will still evaluate to true, passing a dangling pointer to drm_encoder_cleanup_from().
drm_encoder_cleanup_from() would then attempt to acquire the mutex from the freed encoder memory:
void drm_encoder_cleanup_from(...) {
...
mutex_lock(&encoder->bridge_chain_mutex);
...
}Additionally, could calling this function concurrently for bridges on the same chain cause stack list corruption?
Looking at drm_encoder_cleanup_from(), it uses a stack-allocated tmplist:
void drm_encoder_cleanup_from(struct drm_encoder *encoder, struct drm_bridge *bridge)
{
...
LIST_HEAD(tmplist);
mutex_lock(&encoder->bridge_chain_mutex);
if (!list_empty(&bridge->chain_node))
list_for_each_entry_safe_from(bridge, next, &encoder->bridge_chain, chain_node)
list_move_tail(&bridge->chain_node, &tmplist);
mutex_unlock(&encoder->bridge_chain_mutex);
...
}If two threads concurrently remove two bridges in the same chain (for example, Thread 1 removes Bridge A, and Thread 2 removes downstream Bridge B):
Thread 1 moves both bridges to its tmplist and unlocks the mutex.
Thread 2 then locks the mutex and sees !list_empty(&bridge_B->chain_node) is true because Bridge B is linked within Thread 1's tmplist.
Thread 2 then executes list_for_each_entry_safe_from() looking for the termination condition &encoder->bridge_chain. Because Bridge B is inside Thread 1's stack list, it would iterate locklessly into Thread 1's stack memory.
Would this cause Thread 2 to interpret Thread 1's stack LIST_HEAD as a drm_bridge and attempt to move it, corrupting both threads' lists and stack frames?
Quoted 5 lines
drivers/gpu/drm/drm_bridge.c +2
-0+ } +mutex_lock (&bridge_lock);list_move_tail (&bridge->list, &bridge_lingering_list);mutex_unlock (&bridge_lock);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
Maxime Ripard
maintainerRe: [PATCH 25/37] drm/bridge: shutdown and cleanup on bridge unplug
In reply to Luca CeresoliHi,
Quoted 22 lines · Luca Ceresoli
With the upcoming support for DRM bridge hot(un)plugging, bridges can be removed at any time withotu tearing down the entire card. When this happens, shutdown the pipeline and detach from the encoder chain the bridge being removed along with all the following ones.
Signed-off-by Luca Ceresoli <[email protected]>--- drivers/gpu/drm/drm_bridge.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/drm_bridge.c +3
-0@@ -462,9 +462,17 @@ EXPORT_SYMBOL(devm_drm_bridge_add);* 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. +* +* If the bridge is attached, also disable the active output and detach +* this bridge and the following ones. */
drivers/gpu/drm/drm_bridge.c EXPORT_SYMBOL(devm_drm_bridge_add); · line 478
Quoted 10 lines
drivers/gpu/drm/drm_bridge.c +5
-0void drm_bridge_remove (struct drm_bridge *bridge) { +if (bridge->encoder) { +drm_atomic_shutdown (bridge->dev); +drm_encoder_cleanup_from (bridge->encoder, bridge); + } +mutex_lock (&bridge_lock);list_move_tail (&bridge->list, &bridge_lingering_list);mutex_unlock (&bridge_lock);
I don't think this makes a lot of sense to disable the whole device at once. The connector, encoder, and the CRTC might, but the whole device doesn't.
Even then, I'm not sure we should disable anything. How does DP-MST handles removal?
Maxime
Luca Ceresoli
reviewerRe: [PATCH 25/37] drm/bridge: shutdown and cleanup on bridge unplug
Quoted 31 lines · Maxime Ripard
Hi,
Quoted 28 lines · Luca Ceresoli
With the upcoming support for DRM bridge hot(un)plugging, bridges can be removed at any time withotu tearing down the entire card. When this happens, shutdown the pipeline and detach from the encoder chain the bridge being removed along with all the following ones.
Signed-off-by Luca Ceresoli <[email protected]>--- drivers/gpu/drm/drm_bridge.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/drm_bridge.c +7
-0@@ -462,9 +462,17 @@ EXPORT_SYMBOL(devm_drm_bridge_add);* 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. +* +* If the bridge is attached, also disable the active output and detach +* this bridge and the following ones. */ void drm_bridge_remove (struct drm_bridge *bridge) { +if (bridge->encoder) { +drm_atomic_shutdown (bridge->dev); +drm_encoder_cleanup_from (bridge->encoder, bridge); + }
Quoted 8 lines
drivers/gpu/drm/drm_bridge.c EXPORT_SYMBOL(devm_drm_bridge_add); · line 478
Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +1
-0+mutex_lock (&bridge_lock);list_move_tail (&bridge->list, &bridge_lingering_list);mutex_unlock (&bridge_lock);I don't think this makes a lot of sense to disable the whole device at once. The connector, encoder, and the CRTC might, but the whole device doesn't.
Indeed this is wrong. Dmitry pointed it out during the discussion at Display Next Hackfest (see my report in reply to the cover letter). The drm_atomic_shutdown() call will be dropped.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 26/37 drm: event-notifier: add mechanism to notify about hotplug events
In reply to Luca CeresoliIn preparation for supporting DRM bridge hotplug, add an event notifier to allow interested parties to be notified about events they need to react to.
For the initial implementation of bridge hotplug, two events are needed:
bridge detach (happening in drm_bridge.c) and MIPI device attach to MIPI host (happening in drm_mipi_dsi.c).
For this reason implement the event notifier in a new common file that event producers can easily use to send events.
---
A different approach I have considered is keeping the event notifier in drm_bridge.c (as in [0]) instead of a new centralized file. But then another notifier would be needed in drm_mipi_dsi.c for the DSI attach event. That would be particularly awkward because the designated component to implement hotplug is the drm_bridge_connector, which would then need to depend on DRM_MIPI_DSI even though it does nothing MIPI specific.
[0] https://lore.kernel.org/lkml/[email protected]/
--- drivers/gpu/drm/Kconfig | 3 ++ drivers/gpu/drm/Makefile | 2 ++ drivers/gpu/drm/drm_event_notifier.c | 58 ++++++++++++++++++++++++++++++++++++ include/drm/drm_event_notifier.h | 36 ++++++++++++++++++++++ 4 files changed, 99 insertions(+)
drivers/gpu/drm/Kconfig +3 -0
@@ -33,6 +33,9 @@ endmenu if DRM +config DRM_EVENT_NOTIFIER + tristate + config DRM_MIPI_DBI tristate depends on DRM
drivers/gpu/drm/Makefile +2 -0
@@ -96,6 +96,8 @@ drm-$(CONFIG_DRM_PANIC_SCREEN_QR_CODE) += drm_panic_qr.o drm-$(CONFIG_DRM_RAS) += drm_ras.o drm_ras_nl.o drm_ras_genl_family.o obj-$(CONFIG_DRM) += drm.o +obj-$(CONFIG_DRM_EVENT_NOTIFIER) += drm_event_notifier.o + obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o obj-$(CONFIG_DRM_PANEL_BACKLIGHT_QUIRKS) += drm_panel_backlight_quirks.o
drivers/gpu/drm/drm_event_notifier.c new file +58 -0
58 lines not on this page · raw message
include/drm/drm_event_notifier.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Internal event notifier for DRM drivers +* +* Copyright (C) 2026 GE HealthCare +* Author: Luca Ceresoli <[email protected]> +*/ + +#ifndef _DRM_EVENT_NOTIFIER_H_ +#define _DRM_EVENT_NOTIFIER_H_ + +/** +* enum drm_event_notifier_event - DRM bridge events +*/ +enum drm_event_notifier_event { +/** +* @DRM_MIPI_DSI_ATTACHED: A MIPI DSI device has just been attached +* to its MIPI DSI host. @data is a pointer to the &struct +* mipi_dsi_device that has just attached. +*/ +DRM_MIPI_DSI_ATTACHED , +/** +* @DRM_BRIDGE_NOTIFY_DETACHED: A bridge has just been detached +* from the encoder bridge chain. Emitted at the end of +* drm_bridge_detach(), after removing the bridge from the encoder +* chain. @data is a pointer to the &struct drm_bridge that has +* just been detached. +*/ +DRM_BRIDGE_DETACHED , +}; + +int drm_event_notifier_register (struct notifier_block *nb); +int drm_event_notifier_unregister (struct notifier_block *nb); +void drm_event_notifier_notify (unsigned long event,void *data); + +#endif /* _DRM_EVENT_NOTIFIER_H_ */
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 26/37] drm: event-notifier: add mechanism to notify about hotplug events
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Global blocking notifier chain couples independent DRM devices. - [Low] Missing forward…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Global blocking notifier chain couples independent DRM devices.
- [Low] Missing forward declaration for struct notifier_block in header.
- [Low] Kernel-doc mismatch for DRM_BRIDGE_DETACHED enum value.
--
commit 233daf5d4ef6810bfafb5fb5ba8829a7db6987d3
Author: Luca Ceresoli <[email protected]>
drm: event-notifier: add mechanism to notify about hotplug events
This patch introduces a DRM event notifier to allow interested parties to be notified about bridge hotplug events. It adds a new common file implementing the notifier and defines initial events for bridge detach and MIPI DSI attach.
Quoted 10 lines
drivers/gpu/drm/drm_event_notifier.c new file +4
-0@@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Internal event notifier for DRM drivers +*
drivers/gpu/drm/drm_event_notifier.c line 14
Quoted 10 lines
drivers/gpu/drm/drm_event_notifier.c new file +10
-0+* Copyright (C) 2026 GE HealthCare +* Author: Luca Ceresoli <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/notifier.h> + +#include <drm/drm_event_notifier.h> + +static BLOCKING_NOTIFIER_HEAD (drm_event_notifier);
Does using a single, global blocking notifier for all DRM hotplug events risk coupling independent DRM devices?
When an event occurs on one device, it appears this will trigger callbacks for every registered listener across the entire system. Could this lead to cross-device lock contention, or cause listeners on unrelated hardware to unexpectedly react to the event?
[ ... ]
Quoted 19 lines
include/drm/drm_event_notifier.h new file +13
-0@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Internal event notifier for DRM drivers +* +* Copyright (C) 2026 GE HealthCare +* Author: Luca Ceresoli <[email protected]> +*/ + +#ifndef _DRM_EVENT_NOTIFIER_H_ +#define _DRM_EVENT_NOTIFIER_H_ + +/** +* enum drm_event_notifier_event - DRM bridge events
include/drm/drm_event_notifier.h line 23
Quoted 10 lines
include/drm/drm_event_notifier.h new file +10
-0+*/ +enum drm_event_notifier_event { +/** +* @DRM_MIPI_DSI_ATTACHED: A MIPI DSI device has just been attached +* to its MIPI DSI host. @data is a pointer to the &struct +* mipi_dsi_device that has just attached. +*/ +DRM_MIPI_DSI_ATTACHED , +/** +* @DRM_BRIDGE_NOTIFY_DETACHED: A bridge has just been detached
This isn't a bug, but the kernel-doc references @DRM_BRIDGE_NOTIFY_DETACHED while the actual enum value is DRM_BRIDGE_DETACHED. Will this cause warnings during documentation builds?
include/drm/drm_event_notifier.h line 32
Quoted 9 lines
include/drm/drm_event_notifier.h new file +9
-0+* from the encoder bridge chain. Emitted at the end of +* drm_bridge_detach(), after removing the bridge from the encoder +* chain. @data is a pointer to the &struct drm_bridge that has +* just been detached. +*/ + DRM_BRIDGE_DETACHED, +}; + +int drm_event_notifier_register (struct notifier_block *nb);
Should there be a forward declaration for struct notifier_block here, or an include for <linux/notifier.h>?
Without it, files including this header might get compiler warnings about the struct being declared inside a parameter list, since kernel headers are typically expected to be self-contained.
Quoted 4 lines
include/drm/drm_event_notifier.h new file +4
-0+int drm_event_notifier_unregister (struct notifier_block *nb); +void drm_event_notifier_notify (unsigned long event,void *data); + +#endif /* _DRM_EVENT_NOTIFIER_H_ */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
Maxime Ripard
maintainerRe: [PATCH 26/37] drm: event-notifier: add mechanism to notify about hotplug events
In reply to Luca CeresoliQuoted 11 lines · Luca Ceresoli
In preparation for supporting DRM bridge hotplug, add an event notifier to allow interested parties to be notified about events they need to react to.
For the initial implementation of bridge hotplug, two events are needed:
bridge detach (happening indrm_bridge.c) and MIPI device attach to MIPI host (happening indrm_mipi_dsi.c).For this reason implement the event notifier in a new common file that event producers can easily use to send events.
Signed-off-by Luca Ceresoli <[email protected]>
So, you claim in the commit message that it's about a hotplug event, but the only events are the bridge being attached and detached, so not a hotplug event?
And why a bridge would want to be notified that itself (or another?) bridge is being attached or detached?
You need documentation, and a more descriptive commit message.
Maxime
Luca Ceresoli
reviewerRe: [PATCH 26/37] drm: event-notifier: add mechanism to notify about hotplug events
Quoted 13 lines · Maxime Ripard
Quoted 11 lines · Luca Ceresoli
In preparation for supporting DRM bridge hotplug, add an event notifier to allow interested parties to be notified about events they need to react to.
For the initial implementation of bridge hotplug, two events are needed:
bridge detach (happening indrm_bridge.c) and MIPI device attach to MIPI host (happening indrm_mipi_dsi.c).For this reason implement the event notifier in a new common file that event producers can easily use to send events.
Signed-off-by Luca Ceresoli <[email protected]>
Quoted 8 lines
So, you claim in the commit message that it's about a hotplug event, but the only events are the bridge being attached and detached, so not a hotplug event?
And why a bridge would want to be notified that itself (or another?) bridge is being attached or detached?
You need documentation, and a more descriptive commit message.
Yes.
But before that I need a decision about the scope we want to give to this notifier. It is a very generic module, with basically no dependencies, so people will try to add more unrelated events and we'd need to set a boundary.
Options:
* Should it be for hotplug-related events only?
* Should it be for any DRM event that needs notifications?
* Something else?
I'm happy to write that in the docs and commit message once it's agreed, so any comments would be welcome right now.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 26/37] drm: event-notifier: add mechanism to notify about hotplug events
Quoted 30 lines · Luca Ceresoli
Quoted 13 lines · Maxime Ripard
Quoted 11 lines · Luca Ceresoli
In preparation for supporting DRM bridge hotplug, add an event notifier to allow interested parties to be notified about events they need to react to.
For the initial implementation of bridge hotplug, two events are needed:
bridge detach (happening indrm_bridge.c) and MIPI device attach to MIPI host (happening indrm_mipi_dsi.c).For this reason implement the event notifier in a new common file that event producers can easily use to send events.
Signed-off-by Luca Ceresoli <[email protected]>Quoted 8 lines
So, you claim in the commit message that it's about a hotplug event, but the only events are the bridge being attached and detached, so not a hotplug event?
And why a bridge would want to be notified that itself (or another?) bridge is being attached or detached?
You need documentation, and a more descriptive commit message.
Yes.
But before that I need a decision about the scope we want to give to this notifier. It is a very generic module, with basically no dependencies, so people will try to add more unrelated events and we'd need to set a boundary.
Quoted 8 lines
Options:
* Should it be for hotplug-related events only?
* Should it be for any DRM event that needs notifications?
* Something else?I'm happy to write that in the docs and commit message once it's agreed, so any comments would be welcome right now.
At the end of the day, you'd be the first user of it, so you get to make the rules, but they should be written down :)
Maxime
Luca Ceresoli
reviewerPATCH 27/37 drm/bridge: notify about detached bridges
In reply to Luca CeresoliIn preparation to support DRM bridge hotplug, let the drm_bridge code emit an event when a bridge is detached, so that this event can trigger the actions needed to deconfigure the pipeline and unregister the connector as appropriate.
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/drm_bridge.c | 4 ++++ 2 files changed, 5 insertions(+)
drivers/gpu/drm/Kconfig +1 -0
@@ -17,6 +17,7 @@ menuconfig DRM # device and dmabuf fd. Let's make sure that is available for our userspace. select KCMP select VIDEO + select DRM_EVENT_NOTIFIER help Kernel-level support for the Direct Rendering Infrastructure (DRI) introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/drm_bridge.c +4 -0
@@ -34,6 +34,7 @@#include <drm/drm_debugfs.h> #include <drm/drm_edid.h> #include <drm/drm_encoder.h> +#include <drm/drm_event_notifier.h> #include <drm/drm_file.h> #include <drm/drm_of.h> #include <drm/drm_print.h>
@@ -638,6 +639,9 @@ void drm_bridge_detach(struct drm_bridge *bridge) bridge->funcs->detach (bridge);list_del_init (&bridge->chain_node); + +drm_event_notifier_notify (DRM_BRIDGE_DETACHED , bridge); + bridge->dev =NULL ;drm_bridge_put (bridge); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 27/37] drm/bridge: notify about detached bridges
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Dangling pointer: `bridge->encoder` is not cleared on detach, leading to potential Use-After-Free.…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Dangling pointer: bridge->encoder is not cleared on detach, leading to potential Use-After-Free.
- [High] Premature teardown of atomic state, list linkages, and bridge resources before pipeline deconfiguration leads to UAF and list corruption. --
commit 0a150cb9f7d5a0eebc9c0a446f33672c0a09a80b
Author: Luca Ceresoli <[email protected]>
drm/bridge: notify about detached bridges
In preparation to support DRM bridge hotplug, let the drm_bridge code emit an event when a bridge is detached, so that this event can trigger the actions needed to deconfigure the pipeline and unregister the connector as appropriate.
Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +0
-0
[ ... ]
drivers/gpu/drm/drm_bridge.c void drm_bridge_detach(struct drm_bridge *bridge) · line 643
Quoted 6 lines
drivers/gpu/drm/drm_bridge.c +2
-0@@ -638,6 +639,9 @@ void drm_bridge_detach(struct drm_bridge *bridge) bridge->funcs->detach (bridge);list_del_init (&bridge->chain_node); + +drm_event_notifier_notify (DRM_BRIDGE_DETACHED , bridge);
The commit message mentions this event is meant to trigger actions to deconfigure the pipeline. Since this event is emitted after tearing down the bridge's atomic state, list linkages, and bridge resources, could this cause issues when the listener attempts to safely disable the pipeline?
Specifically, earlier in this function:
if (drm_bridge_is_atomic(bridge)) drm_atomic_private_obj_fini(&bridge->base);
This destroys the bridge's modeset lock and frees its active atomic state. Any concurrent atomic commit (like a userspace page flip) or a teardown commit triggered by the listener might access freed memory or destroyed locks.
Additionally:
list_del_init(&bridge->chain_node);
This locklessly modifies the encoder's bridge chain, which might corrupt the list if a concurrent atomic commit is iterating the chain.
Finally, bridge->funcs->detach() has already executed, meaning the bridge has released its internal resources, potentially making subsequent atomic disable operations unsafe. Should the notification be emitted before the bridge state and linkages are forcefully torn down?
drivers/gpu/drm/drm_bridge.c void drm_bridge_detach(struct drm_bridge *bridge) · line 645
Quoted 2 lines
drivers/gpu/drm/drm_bridge.c +1
-0+ bridge->dev =NULL ;
Does this code also need to clear bridge->encoder?
Since bridges are refcounted, and listeners or other users might hold their own references via drm_bridge_get(), the bridge can outlive the encoder. If the encoder is destroyed (e.g., during driver unbind), could any access to bridge->encoder by asynchronous event listeners or delayed cleanup workers result in a use-after-free?
Quoted 2 lines
drivers/gpu/drm/drm_bridge.c +0
-0drm_bridge_put (bridge); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
Luca Ceresoli
reviewerPATCH 28/37 drm/mipi-dsi: turn DRM_MIPI_DSI into a tristate
In reply to Luca CeresoliDRM_MIPI_DSI is currently a bool, but there's no reason to not be allowed to build it as a loadable module.
Moreover being a bool prevents DRM_MIPI_DSI to depend on a tristate module that is configured as 'm'.
--- drivers/gpu/drm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +1 -1
@@ -43,7 +43,7 @@ config DRM_MIPI_DBI select DRM_KMS_HELPER config DRM_MIPI_DSI - bool + tristate depends on DRM config DRM_KMS_HELPER
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 28/37] drm/mipi-dsi: turn DRM_MIPI_DSI into a tristate
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Missing module_exit() routine in drm_mipi_dsi.c - [Low] Linker error due to…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Missing module_exit() routine in drm_mipi_dsi.c
- [Low] Linker error due to IS_ENABLED(CONFIG_DRM_MIPI_DSI) evaluating to true when built as a module --
commit 980deb1ce9940525b50bf77a81377ee0a4c56aad
Author: Luca Ceresoli <[email protected]>
drm/mipi-dsi: turn DRM_MIPI_DSI into a tristate
This commit converts the DRM_MIPI_DSI configuration option from a boolean to a tristate, allowing it to be built as a loadable module. This also enables other tristate modules to depend on it when it is built as a module.
drivers/gpu/drm/Kconfig config DRM_MIPI_DBI · line 46
Quoted 10 lines
drivers/gpu/drm/Kconfig +1
-1@@ -43,7 +43,7 @@ config DRM_MIPI_DBI select DRM_KMS_HELPER config DRM_MIPI_DSI - bool + tristate
Since DRM_MIPI_DSI can now be built as a module, does drm_mipi_dsi.c need a module_exit() routine?
Currently, drm_mipi_dsi.c uses postcore_initcall(mipi_dsi_bus_init) but does not define a corresponding module_exit() function to unregister the bus. Without this, the module will be permanently pinned in memory after loading and cannot be unloaded.
Could this change also cause a linker regression if CONFIG_DRM=y and CONFIG_DRM_MIPI_DSI=m?
Core DRM code like drm_of.c uses IS_ENABLED(CONFIG_DRM_MIPI_DSI) to conditionally compile drm_of_get_dsi_bus(). IS_ENABLED() evaluates to true for both y and m.
If DRM is built-in and MIPI_DSI is a module, drm_of.c will compile drm_of_get_dsi_bus(), which calls of_find_mipi_dsi_host_by_node(). This function is exported by the drm_mipi_dsi module, so it won't be present in vmlinux, resulting in an undefined reference.
Does the Kconfig dependency need to be adjusted, or should IS_REACHABLE(CONFIG_DRM_MIPI_DSI) be used instead to avoid this?
Quoted 3 lines
drivers/gpu/drm/Kconfig +0
-0depends on DRM config DRM_KMS_HELPER
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Luca Ceresoli
reviewerPATCH 29/37 drm/mipi-dsi: notify about DSI attach
In reply to Luca CeresoliIn preparation to support DRM bridge hotplug, let the drm_mipi_dsi code emit an event when a DSI device is attached to the corresponding DSI host, so that this event can trigger the actions needed to deconfigure the pipeline and unregister the connector as appropriate.
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/drm_mipi_dsi.c | 3 +++ 2 files changed, 4 insertions(+)
drivers/gpu/drm/Kconfig +1 -0
@@ -45,6 +45,7 @@ config DRM_MIPI_DBI config DRM_MIPI_DSI tristate depends on DRM + select DRM_EVENT_NOTIFIER config DRM_KMS_HELPER tristate
drivers/gpu/drm/drm_mipi_dsi.c +3 -0
@@ -34,6 +34,7 @@#include <linux/slab.h> #include <drm/display/drm_dsc.h> +#include <drm/drm_event_notifier.h> #include <drm/drm_mipi_dsi.h> #include <drm/drm_print.h>
@@ -386,6 +387,8 @@ int mipi_dsi_attach(struct mipi_dsi_device *dsi) dsi->attached = true; +drm_event_notifier_notify (DRM_MIPI_DSI_ATTACHED , dsi); +return 0 ; }EXPORT_SYMBOL (mipi_dsi_attach);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 29/37] drm/mipi-dsi: notify about DSI attach
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message incorrectly claims that the attach event will trigger deconfiguration and…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly claims that the attach event will trigger deconfiguration and unregistration. --
commit 24c698fb4d9fc9ee14ca2fe29864b46f2adbe654
Author: Luca Ceresoli <[email protected]>
drm/mipi-dsi: notify about DSI attach
This commit introduces a notification event when a DSI device is attached to its host. This change is made in preparation for supporting DRM bridge hotplug.
Quoted 4 lines
In preparation to support DRM bridge hotplug, let the
drm_mipi_dsicode emit an event when a DSI device is attached to the corresponding DSI host, so that this event can trigger the actions needed to deconfigure the pipeline and unregister the connector as appropriate.
This isn't a bug in the code, but does the commit message describe the wrong actions for an attach event? Attaching a device typically triggers pipeline configuration and connector registration, whereas deconfiguration and unregistration are normally associated with a detach event.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Luca Ceresoli
reviewerPATCH 30/37 drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
In reply to Luca CeresoliFor bridge hotplug we need to successfully probe a card with an incomplete bridge chain, i.e. a chain whose last bridge currently in bridge_chain needs a next_bridge to work. Such a card would have no connector, and be able to add one as soon as the followong bridges are added up to the tail bridge (e.g. a panel_bridge or a connector_bridge).
Currently common DRM code is unable to tell whether the last bridge currently in the chain is the tail bridge (= the pipeline is complete) or not.
Add drm_bridge_is_tail(), and a .is_tail func for it to rely on, so common code can know whether a bridge is a tail bridge or needs a next_bridge.
--- drivers/gpu/drm/drm_bridge.c | 28 ++++++++++++++++++++++++++++ include/drm/drm_bridge.h | 19 +++++++++++++++++++ 2 files changed, 47 insertions(+)
drivers/gpu/drm/drm_bridge.c +28 -0
@@ -646,6 +646,34 @@ void drm_bridge_detach(struct drm_bridge *bridge)drm_bridge_put (bridge); } +/** +* drm_bridge_is_tail - check whether the bridge is the last required to +* have a full pipeline +* @bridge: the bridge to check +* +* Tell whether this is a tail bridge, i.e. a bridge that does not need a +* next bridge to work. E.g. a panel_bridge is final, a DSI-to-LVDS bridge +* is not. +* +* In case of hotplug the last bridge currently in the chain (as in +* drm_bridge_chain_get_last_bridge()) might not be final, and be waiting +* for a pipeline tail to be connected. +* +* Return: true if this bridge does not need a next bridge to work, false +* otherwise +*/ +bool drm_bridge_is_tail (struct drm_bridge *bridge) +{ +if (!(bridge->ops &DRM_BRIDGE_OP_IS_TAIL )) { +drm_warn_once (bridge->dev,"is_tail func not implemented by bridge %ps!" , + bridge->funcs); +return false; + } + +return bridge->funcs->is_tail (bridge); +} +EXPORT_SYMBOL (drm_bridge_is_tail); +/** * DOC: bridge operations *
include/drm/drm_bridge.h +19 -0
@@ -78,6 +78,19 @@ struct drm_bridge_funcs {int (*attach)(struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags); +/** +* @is_tail: +* +* Returns true if this is a tail bridge, i.e. it does not need a +* next bridge to work. E.g. a panel_bridge is a tail bridge, a +* DSI-to-LVDS bridge is not a tail bridge (no matter whether the +* next bridge is present or not). +* +* The @is_tail callback is optional but it is required if the +* bridge is part of a pipeline with hot-pluggable components. +*/ +bool (*is_tail)(struct drm_bridge *bridge); +/** * @destroy: *
@@ -1092,6 +1105,11 @@ enum drm_bridge_ops {* &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks. */ DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME =BIT (10 ), +/** +* @DRM_BRIDGE_OP_IS_TAIL: The bridge implements the +* &drm_bridge_funcs->is_tail callback. +*/ + DRM_BRIDGE_OP_IS_TAIL = BIT(11), };/**
@@ -1323,6 +1341,7 @@ void drm_bridge_remove(struct drm_bridge *bridge);int drm_bridge_attach (struct drm_encoder *encoder,struct drm_bridge *bridge,struct drm_bridge *previous,enum drm_bridge_attach_flags flags); +bool drm_bridge_is_tail (struct drm_bridge *bridge);#ifdef CONFIG_OF struct drm_bridge *of_drm_find_and_get_bridge (struct device_node *np);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 30/37] drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] drm_bridge_is_tail() emits a kernel warning and defaults to false for bridges omitting the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm_bridge_is_tail() emits a kernel warning and defaults to false for bridges omitting the optional .is_tail callback. --
commit 285e9eabd414f7b37079e41dd2875f7b3e588911
Author: Luca Ceresoli <[email protected]>
drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
This commit introduces drm_bridge_is_tail() and an .is_tail callback to determine if a bridge completes the display pipeline. This is useful for handling bridge hotplug scenarios where a pipeline might initially be incomplete.
Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +0
-0
[ ... ]
Quoted 1 line
drivers/gpu/drm/drm_bridge.c +0
-0@@ -646,6 +646,34 @@ void drm_bridge_detach(struct drm_bridge *bridge)
[ ... ]
drivers/gpu/drm/drm_bridge.c void drm_bridge_detach(struct drm_bridge *bridge) · line 675
Quoted 11 lines
drivers/gpu/drm/drm_bridge.c +11
-0+bool drm_bridge_is_tail (struct drm_bridge *bridge) +{ +if (!(bridge->ops &DRM_BRIDGE_OP_IS_TAIL )) { +drm_warn_once (bridge->dev,"is_tail func not implemented by bridge %ps!" , + bridge->funcs); +return false; + } + +return bridge->funcs->is_tail (bridge); +} +EXPORT_SYMBOL (drm_bridge_is_tail);
Will developers writing non-hot-pluggable bridges trigger spurious kernel warnings at runtime here if they follow the documentation and omit this callback?
Additionally, returning false when the callback is omitted means that legacy static tail bridges that haven't been updated will be seen as needing a next bridge. Could this result in display initialization failures for existing drivers across the kernel?
Quoted 4 lines
include/drm/drm_bridge.h +0
-0
[ ... ]
Quoted 1 line
include/drm/drm_bridge.h +0
-0@@ -78,6 +78,19 @@ struct drm_bridge_funcs {
[ ... ]
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 92
Quoted 12 lines
include/drm/drm_bridge.h +12
-0+/** +* @is_tail: +* +* Returns true if this is a tail bridge, i.e. it does not need a +* next bridge to work. E.g. a panel_bridge is a tail bridge, a +* DSI-to-LVDS bridge is not a tail bridge (no matter whether the +* next bridge is present or not). +* +* The @is_tail callback is optional but it is required if the +* bridge is part of a pipeline with hot-pluggable components. +*/ +bool (*is_tail)(struct drm_bridge *bridge);
Since this documentation explicitly states the callback is optional for bridges that aren't part of a hot-pluggable pipeline, is it safe for drm_bridge_is_tail() to default to false and warn when it is omitted?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
Maxime Ripard
maintainerRe: [PATCH 30/37] drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
In reply to Luca CeresoliQuoted 63 lines · Luca Ceresoli
For bridge hotplug we need to successfully probe a card with an incomplete bridge chain, i.e. a chain whose last bridge currently in
bridge_chainneeds anext_bridgeto work. Such a card would have no connector, and be able to add one as soon as the followong bridges are added up to the tail bridge (e.g. apanel_bridgeor aconnector_bridge).Currently common DRM code is unable to tell whether the last bridge currently in the chain is the tail bridge (= the pipeline is complete) or not.
Add
drm_bridge_is_tail(), and a .is_tail func for it to rely on, so common code can know whether a bridge is a tail bridge or needs anext_bridge.Signed-off-by Luca Ceresoli <[email protected]>--- drivers/gpu/drm/drm_bridge.c | 28 ++++++++++++++++++++++++++++ include/drm/drm_bridge.h | 19 +++++++++++++++++++ 2 files changed, 47 insertions(+)drivers/gpu/drm/drm_bridge.c +28
-0@@ -646,6 +646,34 @@ void drm_bridge_detach(struct drm_bridge *bridge)drm_bridge_put (bridge); } +/** +* drm_bridge_is_tail - check whether the bridge is the last required to +* have a full pipeline +* @bridge: the bridge to check +* +* Tell whether this is a tail bridge, i.e. a bridge that does not need a +* next bridge to work. E.g. a panel_bridge is final, a DSI-to-LVDS bridge +* is not. +* +* In case of hotplug the last bridge currently in the chain (as in +* drm_bridge_chain_get_last_bridge()) might not be final, and be waiting +* for a pipeline tail to be connected. +* +* Return: true if this bridge does not need a next bridge to work, false +* otherwise +*/ +bool drm_bridge_is_tail (struct drm_bridge *bridge) +{ +if (!(bridge->ops &DRM_BRIDGE_OP_IS_TAIL )) { +drm_warn_once (bridge->dev,"is_tail func not implemented by bridge %ps!" , + bridge->funcs); +return false; + } + +return bridge->funcs->is_tail (bridge); +} +EXPORT_SYMBOL (drm_bridge_is_tail); +/** * DOC: bridge operations * include/drm/drm_bridge.h +0
-0
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 87
Quoted 10 lines
include/drm/drm_bridge.h +7
-0@@ -78,6 +78,19 @@ struct drm_bridge_funcs {int (*attach)(struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags); +/** +* @is_tail: +* +* Returns true if this is a tail bridge, i.e. it does not need a +* next bridge to work. E.g. a panel_bridge is a tail bridge, a +* DSI-to-LVDS bridge is not a tail bridge (no matter whether the +* next bridge is present or not).
Why a DSI-to-LDVS bridge isn't a tail bridge? It only needs a panel next, right?
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 93
Quoted 5 lines
include/drm/drm_bridge.h +5
-0+* The @is_tail callback is optional but it is required if the +* bridge is part of a pipeline with hot-pluggable components. +*/ +bool (*is_tail)(struct drm_bridge *bridge); +
I don't think that's the right way to think about it, if only because you never really know at the driver level if you're supposed to be last or not. A DSI-to-LVDS bridge might just as well be chained with an LVDS-to-eDP bridge, or feed the panel directly without any additional bridge.
I *think* that what you're trying to find out here is whether the chain is complete or not. I think you can get the same information by checking whether you have a connector for that bridge chain. If you don't, you know the chain isn't complete, and if you do, it's supposed to be. DRM_BRIDGE_ATTACH_NO_CONNECTOR could be useful too, because if all you bridges support it but there's no connector, there's something wrong.
Anyway.
Maxime
include/drm/drm_bridge.h enum drm_bridge_ops { · line 1113
Quoted 13 lines
include/drm/drm_bridge.h +5
-0/** * @destroy: * @@ -1092,6 +1105,11 @@ enum drm_bridge_ops {* &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks. */ DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME =BIT (10 ), +/** +* @DRM_BRIDGE_OP_IS_TAIL: The bridge implements the +* &drm_bridge_funcs->is_tail callback. +*/ + DRM_BRIDGE_OP_IS_TAIL = BIT(11), };
That part is confusing to me. This is meant for drm_bridge_connector, but since we need to handle the case where we don't have a connector (and thus no drm_bridge_connector) I don't think this should be used at all?
Maxime
Luca Ceresoli
reviewerRe: [PATCH 30/37] drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
Hi Maxime,
thanks for the review of this long series!
On Mon Jun 8, 2026 at 2:34 PM CEST, Maxime Ripard wrote:
...
Quoted 6 lines
Quoted 6 lines
include/drm/drm_bridge.h +0
-0@@ -78,6 +78,19 @@ struct drm_bridge_funcs {int (*attach)(struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags);
Quoted 10 lines
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 87
Quoted 7 lines
include/drm/drm_bridge.h +7
-0+/** +* @is_tail: +* +* Returns true if this is a tail bridge, i.e. it does not need a +* next bridge to work. E.g. a panel_bridge is a tail bridge, a +* DSI-to-LVDS bridge is not a tail bridge (no matter whether the +* next bridge is present or not). Why a DSI-to-LDVS bridge isn't a tail bridge? It only needs a panel next, right?
Uhm, good point, but I'd say it can be a tail bridge or not: in the ATTACH_NO_CONNECTOR case it will need a bridge (a panel_bridge most likely), no?
However this is possibly irrelevant as the whole .is_tail is meant to disappear in v2, see below.
Quoted 12 lines
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 93
Quoted 5 lines
include/drm/drm_bridge.h +5
-0+* The @is_tail callback is optional but it is required if the +* bridge is part of a pipeline with hot-pluggable components. +*/ +bool (*is_tail)(struct drm_bridge *bridge); +I don't think that's the right way to think about it, if only because you never really know at the driver level if you're supposed to be last or not. A DSI-to-LVDS bridge might just as well be chained with an LVDS-to-eDP bridge, or feed the panel directly without any additional bridge.
Quoted 2 lines
I *think* that what you're trying to find out here is whether the chain is complete or not.
You nailed it.
That was the main point discussed during the Display Next Hackfest 2026 (see the report [0]) and we all agreed the .is_tail along with the -EPROBE_DEFER changes (patches 20+35) are not a good approach.
This is actually the most crucial aspect of the whole work still not having no well-defined solution.
Quoted 3 lines
I think you can get the same information by checking whether you have a connector for that bridge chain. If you don't, you know the chain isn't complete, and if you do, it's supposed to be.
There's a checken-egg problem here. Knowing whether the pipeline is complete or not is needed to know whether we have to create a connector. See patch 36:
+ if (drm_bridge_connector_pipeline_is_complete(bridge_connector))
+ drm_bridge_connector_add_connector(bridge_connector);
So the question is still open, what I need the most right now is comments on the overall architecture of this aspecs. Maybe replying to [0] can be more effective than here.
In a nutshell what we need is:
* when a bridge needs a following element (a bridge, or a panel which however might/should have a panel_bridge), but that element is not present, instead of deferring the whole card probe the card should be allowed to probe but without a connector
* when something is added to an incomplete pipeline we need to know whether the pipeline has become complete (in order to create the connector)
How to implement this is still an open point. I'll welcome proposals in addition to the ones in [0].
[0] https://lore.kernel.org/all/[email protected]/
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Maxime Ripard
maintainerRe: [PATCH 30/37] drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
Quoted 23 lines · Luca Ceresoli
Hi Maxime,
thanks for the review of this long series!
On Mon Jun 8, 2026 at 2:34 PM CEST, Maxime Ripard wrote:
...Quoted 6 lines
Quoted 6 lines
include/drm/drm_bridge.h +0
-0@@ -78,6 +78,19 @@ struct drm_bridge_funcs {int (*attach)(struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags);Quoted 10 lines
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 87
Quoted 7 lines
include/drm/drm_bridge.h +7
-0+/** +* @is_tail: +* +* Returns true if this is a tail bridge, i.e. it does not need a +* next bridge to work. E.g. a panel_bridge is a tail bridge, a +* DSI-to-LVDS bridge is not a tail bridge (no matter whether the +* next bridge is present or not). Why a DSI-to-LDVS bridge isn't a tail bridge? It only needs a panel next, right?
Quoted 3 lines
Uhm, good point, but I'd say it can be a tail bridge or not: in the
ATTACH_NO_CONNECTORcase it will need a bridge (apanel_bridgemost likely), no?
Yeah, I think it cannot (always) be a blanket statement from the driver. For drivers that do not support ATTACH_NO_CONNECTOR, then it's always going to be a tail, but if the driver supports it, we should use a helper because it's going to depend on the DT, basically.
Quoted 18 lines
However this is possibly irrelevant as the whole .is_tail is meant to disappear in v2, see below.
Quoted 12 lines
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 93
Quoted 5 lines
include/drm/drm_bridge.h +5
-0+* The @is_tail callback is optional but it is required if the +* bridge is part of a pipeline with hot-pluggable components. +*/ +bool (*is_tail)(struct drm_bridge *bridge); +I don't think that's the right way to think about it, if only because you never really know at the driver level if you're supposed to be last or not. A DSI-to-LVDS bridge might just as well be chained with an LVDS-to-eDP bridge, or feed the panel directly without any additional bridge.
Quoted 2 lines
I *think* that what you're trying to find out here is whether the chain is complete or not.
Quoted 8 lines
You nailed it.
That was the main point discussed during the Display Next Hackfest 2026 (see the report [0]) and we all agreed the .is_tail along with the -EPROBE_DEFER changes (patches 20+35) are not a good approach.
This is actually the most crucial aspect of the whole work still not having no well-defined solution.
Ok
Quoted 22 lines
Quoted 3 lines
I think you can get the same information by checking whether you have a connector for that bridge chain. If you don't, you know the chain isn't complete, and if you do, it's supposed to be.
There's a checken-egg problem here. Knowing whether the pipeline is complete or not is needed to know whether we have to create a connector. See patch 36:
+ if (
drm_bridge_connector_pipeline_is_complete(bridge_connector))
+drm_bridge_connector_add_connector(bridge_connector);So the question is still open, what I need the most right now is comments on the overall architecture of this aspecs. Maybe replying to [0] can be more effective than here.
In a nutshell what we need is:
* when a bridge needs a following element (a bridge, or a panel which however might/should have a
panel_bridge), but that element is not present, instead of deferring the whole card probe the card should be allowed to probe but without a connector
Quoted 6 lines
* when something is added to an incomplete pipeline we need to know whether the pipeline has become complete (in order to create the connector)
How to implement this is still an open point. I'll welcome proposals in addition to the ones in [0].
Thanks for the notes, I think I largely agree with the discussion. Reading through it, I thought it would be nice for a new callback called get_next_bridge or something that would return either an error, NULL or a (refcounted) pointer to the next bridge in the chain. And have some kind of special error (ENODEV?) when the bridge should be there but isn't (and thus the chain isn't complete).
Maxime
Luca Ceresoli
reviewerRe: [PATCH 30/37] drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline
Quoted 84 lines · Maxime Ripard
Quoted 23 lines · Luca Ceresoli
Hi Maxime,
thanks for the review of this long series!
On Mon Jun 8, 2026 at 2:34 PM CEST, Maxime Ripard wrote:
...Quoted 6 lines
Quoted 6 lines
include/drm/drm_bridge.h +0
-0@@ -78,6 +78,19 @@ struct drm_bridge_funcs {int (*attach)(struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags);Quoted 10 lines
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 87
Quoted 7 lines
include/drm/drm_bridge.h +7
-0+/** +* @is_tail: +* +* Returns true if this is a tail bridge, i.e. it does not need a +* next bridge to work. E.g. a panel_bridge is a tail bridge, a +* DSI-to-LVDS bridge is not a tail bridge (no matter whether the +* next bridge is present or not). Why a DSI-to-LDVS bridge isn't a tail bridge? It only needs a panel next, right?
Quoted 3 lines
Uhm, good point, but I'd say it can be a tail bridge or not: in the
ATTACH_NO_CONNECTORcase it will need a bridge (apanel_bridgemost likely), no?Yeah, I think it cannot (always) be a blanket statement from the driver. For drivers that do not support
ATTACH_NO_CONNECTOR, then it's always going to be a tail, but if the driver supports it, we should use a helper because it's going to depend on the DT, basically.Quoted 18 lines
However this is possibly irrelevant as the whole .is_tail is meant to disappear in v2, see below.
Quoted 12 lines
include/drm/drm_bridge.h struct drm_bridge_funcs { · line 93
Quoted 5 lines
include/drm/drm_bridge.h +5
-0+* The @is_tail callback is optional but it is required if the +* bridge is part of a pipeline with hot-pluggable components. +*/ +bool (*is_tail)(struct drm_bridge *bridge); +I don't think that's the right way to think about it, if only because you never really know at the driver level if you're supposed to be last or not. A DSI-to-LVDS bridge might just as well be chained with an LVDS-to-eDP bridge, or feed the panel directly without any additional bridge.
Quoted 2 lines
I *think* that what you're trying to find out here is whether the chain is complete or not.
Quoted 8 lines
You nailed it.
That was the main point discussed during the Display Next Hackfest 2026 (see the report [0]) and we all agreed the .is_tail along with the -EPROBE_DEFER changes (patches 20+35) are not a good approach.
This is actually the most crucial aspect of the whole work still not having no well-defined solution.
Ok
Quoted 22 lines
Quoted 3 lines
I think you can get the same information by checking whether you have a connector for that bridge chain. If you don't, you know the chain isn't complete, and if you do, it's supposed to be.
There's a checken-egg problem here. Knowing whether the pipeline is complete or not is needed to know whether we have to create a connector. See patch 36:
+ if (
drm_bridge_connector_pipeline_is_complete(bridge_connector))
+drm_bridge_connector_add_connector(bridge_connector);So the question is still open, what I need the most right now is comments on the overall architecture of this aspecs. Maybe replying to [0] can be more effective than here.
In a nutshell what we need is:
* when a bridge needs a following element (a bridge, or a panel which however might/should have a
panel_bridge), but that element is not present, instead of deferring the whole card probe the card should be allowed to probe but without a connector
Quoted 8 lines
Quoted 6 lines
* when something is added to an incomplete pipeline we need to know whether the pipeline has become complete (in order to create the connector)
How to implement this is still an open point. I'll welcome proposals in addition to the ones in [0].
Thanks for the notes, I think I largely agree with the discussion.
Good! :)
Quoted 5 lines
Reading through it, I thought it would be nice for a new callback called
get_next_bridgeor something that would return either an error, NULL or a (refcounted) pointer to the next bridge in the chain. And have some kind of special error (ENODEV?) when the bridge should be there but isn't (and thus the chain isn't complete).
I initially preferred exposing the fwnode of the next bridge as discussed with Dmitry during the Display Next Hackfest, which looks simpler for driver writers. But then I realized it would be tricyk in cases such as dual-LVDS output bridges (ti-sn65dsi83.c) which have two output ports in DT, none of which is mandatory. So I've come to thinking a callback is better as it should be flexible enough.
Picking the best errno is probably the only aspect needing special attention now.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerPATCH 31/37 drm/bridge: panel: implement .is_tail
In reply to Luca CeresoliThis bridge is always a tail bridge, i.e. it never needs a following bridge to complete the pipeline. Add a is_tail func to expose this.
--- drivers/gpu/drm/bridge/panel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/panel.c +7 -1
@@ -58,6 +58,11 @@ static const struct drm_connector_funcs panel_bridge_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; +static bool panel_bridge_is_tail (struct drm_bridge *bridge) +{ +return true; +} +static int panel_bridge_attach (struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags)
@@ -206,6 +211,7 @@ static void panel_bridge_debugfs_init(struct drm_bridge *bridge, }static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { + .is_tail = panel_bridge_is_tail, .attach = panel_bridge_attach, .detach = panel_bridge_detach, .atomic_pre_enable = panel_bridge_atomic_pre_enable,
@@ -297,7 +303,7 @@ struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, panel_bridge->panel = panel; panel_bridge->bridge.of_node = panel->dev->of_node; - panel_bridge->bridge.ops =DRM_BRIDGE_OP_MODES ; + panel_bridge->bridge.ops =DRM_BRIDGE_OP_MODES |DRM_BRIDGE_OP_IS_TAIL ; panel_bridge->bridge.type = connector_type; panel_bridge->bridge.pre_enable_prev_first = panel->prepare_prev_first;
Signature · 1 line
2.54.0
Re: [PATCH 31/37] drm/bridge: panel: implement .is_tail
Quoted 34 lines · Luca Ceresoli
This bridge is always a tail bridge, i.e. it never needs a following bridge to complete the pipeline. Add a
is_tailfunc to expose this.Signed-off-by Luca Ceresoli <[email protected]>--- drivers/gpu/drm/bridge/panel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/panel.c +6
-0@@ -58,6 +58,11 @@ static const struct drm_connector_funcs panel_bridge_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; +static bool panel_bridge_is_tail (struct drm_bridge *bridge) +{ +return true; +} +static int panel_bridge_attach (struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags)@@ -206,6 +211,7 @@ static void panel_bridge_debugfs_init(struct drm_bridge *bridge, }static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { + .is_tail = panel_bridge_is_tail, .attach = panel_bridge_attach, .detach = panel_bridge_detach, .atomic_pre_enable = panel_bridge_atomic_pre_enable,
drivers/gpu/drm/bridge/panel.c struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, · line 309
Quoted 8 lines
drivers/gpu/drm/bridge/panel.c +1
-1@@ -297,7 +303,7 @@ struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, panel_bridge->panel = panel; panel_bridge->bridge.of_node = panel->dev->of_node; - panel_bridge->bridge.ops =DRM_BRIDGE_OP_MODES ; + panel_bridge->bridge.ops =DRM_BRIDGE_OP_MODES |DRM_BRIDGE_OP_IS_TAIL ; panel_bridge->bridge.type = connector_type; panel_bridge->bridge.pre_enable_prev_first = panel->prepare_prev_first;
This looks reasonable
Thanks,
Neil
Luca Ceresoli
reviewerPATCH 32/37 drm/bridge: display-connector: implement .is_tail
In reply to Luca CeresoliThis bridge is always a tail bridge, i.e. it never needs a following bridge to complete the pipeline. Add a is_tail func to expose this.
--- drivers/gpu/drm/bridge/display-connector.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/bridge/display-connector.c +7 -0
@@ -33,6 +33,11 @@ to_display_connector(struct drm_bridge *bridge) return container_of(bridge, struct display_connector, bridge); } +static bool display_connector_is_tail (struct drm_bridge *bridge) +{ +return true; +} +static int display_connector_attach (struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags)
@@ -176,6 +181,7 @@ static u32 *display_connector_get_input_bus_fmts(struct drm_bridge *bridge, }static const struct drm_bridge_funcs display_connector_bridge_funcs = { + .is_tail = display_connector_is_tail, .attach = display_connector_attach, .detect = display_connector_bridge_detect, .edid_read = display_connector_edid_read,
@@ -370,6 +376,7 @@ static int display_connector_probe(struct platform_device *pdev) conn->bridge.of_node = pdev->dev.of_node; + conn->bridge.ops =DRM_BRIDGE_OP_IS_TAIL ;if (conn->bridge.ddc) conn->bridge.ops |=DRM_BRIDGE_OP_EDID |DRM_BRIDGE_OP_DETECT ;
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 33/37 drm/bridge: samsung-dsim: implement .is_tail
In reply to Luca CeresoliThis bridge is never a tail bridge, i.e. it always needs a following bridge to complete the pipeline. Add a is_tail func to expose this.
--- drivers/gpu/drm/bridge/samsung-dsim.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/bridge/samsung-dsim.c +7 -0
@@ -1716,6 +1716,11 @@ static const u32 samsung_dsim_pixel_output_fmts[] = { MEDIA_BUS_FMT_RGB888_1X24, }; +static bool samsung_dsim_is_tail (struct drm_bridge *bridge) +{ +return false; +} +static bool samsung_dsim_pixel_output_fmt_supported (u32 fmt) {int i;
@@ -1836,6 +1841,7 @@ static int samsung_dsim_attach(struct drm_bridge *bridge, }static const struct drm_bridge_funcs samsung_dsim_bridge_funcs = { + .is_tail = samsung_dsim_is_tail, .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, .atomic_reset = drm_atomic_helper_bridge_reset,
@@ -2225,6 +2231,7 @@ int samsung_dsim_probe(struct platform_device *pdev)pm_runtime_enable (dev); + dsi->bridge.ops =DRM_BRIDGE_OP_IS_TAIL ; dsi->bridge.of_node = dev->of_node; dsi->bridge.type =DRM_MODE_CONNECTOR_DSI ;
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 34/37 drm/bridge: ti-sn65dsi83: implement .is_tail
In reply to Luca CeresoliThis bridge is never a tail bridge, i.e. it always needs a following bridge to complete the pipeline. Add a is_tail func to expose this.
--- drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi83.c +7 -0
@@ -293,6 +293,11 @@ static struct sn65dsi83 *bridge_to_sn65dsi83(struct drm_bridge *bridge) return container_of(bridge, struct sn65dsi83, bridge); } +static bool sn65dsi83_is_tail (struct drm_bridge *bridge) +{ +return false; +} +static int sn65dsi83_attach (struct drm_bridge *bridge,struct drm_encoder *encoder,enum drm_bridge_attach_flags flags)
@@ -792,6 +797,7 @@ sn65dsi83_atomic_get_input_bus_fmts(struct drm_bridge *bridge, }static const struct drm_bridge_funcs sn65dsi83_funcs = { + .is_tail = sn65dsi83_is_tail, .attach = sn65dsi83_attach, .detach = sn65dsi83_detach, .atomic_enable = sn65dsi83_atomic_enable,
@@ -1066,6 +1072,7 @@ static int sn65dsi83_probe(struct i2c_client *client)dev_set_drvdata (dev, ctx);i2c_set_clientdata (client, ctx); + ctx->bridge.ops =DRM_BRIDGE_OP_IS_TAIL ; ctx->bridge.of_node = dev->of_node; ctx->bridge.pre_enable_prev_first = true; ctx->bridge.type =DRM_MODE_CONNECTOR_LVDS ;
Signature · 1 line
2.54.0
Luca Ceresoli
reviewerPATCH 35/37 drm/bridge: drm_bridge_attach(): don't fail on -EPROBE_DEFER
In reply to Luca CeresoliWith bridge hotplug support, when a bridge attach func returns -EPROBE_DEFER it means the following bridge is not yet connected, but it could be later on. In this case don't fail the entire attach operation, so the card can probe (without a connector) and be ready to handle a future hotplug that completes the pipeline.
--- drivers/gpu/drm/drm_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_bridge.c +1 -1
@@ -593,7 +593,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,if (bridge->funcs->attach) { ret = bridge->funcs->attach (bridge, encoder, flags); -if (ret <0 ) +if (ret <0 && ret != -EPROBE_DEFER ) goto err_reset_bridge; }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 35/37] drm/bridge: drm_bridge_attach(): don't fail on -EPROBE_DEFER
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Masking `-EPROBE_DEFER` leaves failed, uninitialized bridges in the active bridge chain…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Masking -EPROBE_DEFER leaves failed, uninitialized bridges in the active bridge chain, leading to UAF and crashes.
- [High] Unconditionally swallowing -EPROBE_DEFER breaks the generic probe deferral mechanism for all bridge resources.
- [Low] The probe deferral diagnostic block in err_reset_bridge is now unreachable dead code.
--
commit 17390f0ac2160f3f951784d20085063db510a04e
Author: Luca Ceresoli <[email protected]>
drm/bridge: drm_bridge_attach(): don't fail on -EPROBE_DEFER
This commit modifies drm_bridge_attach() to bypass the error cleanup path when a bridge's attach callback returns -EPROBE_DEFER. This is intended to allow the display pipeline to probe even if a downstream bridge is not yet connected.
drivers/gpu/drm/drm_bridge.c int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, · line 598
Quoted 12 lines
drivers/gpu/drm/drm_bridge.c +1
-1@@ -593,7 +593,7 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,if (bridge->funcs->attach) { ret = bridge->funcs->attach (bridge, encoder, flags); -if (ret <0 ) +if (ret <0 && ret != -EPROBE_DEFER ) goto err_reset_bridge; }
If the bridge's attach callback returns -EPROBE_DEFER, skipping the err_reset_bridge path will cause the function to return 0 (success) instead of propagating the error. Does this break the generic probe deferral mechanism? -EPROBE_DEFER could be returned because any required resource (such as clocks or regulators) is missing, and returning 0 means the upstream driver will finish probing without the driver core ever retrying.
Additionally, because the bridge was added to encoder->bridge_chain prior to calling the attach callback:
mutex_lock(&encoder->bridge_chain_mutex); if (previous) list_add(&bridge->chain_node, &previous->chain_node); else list_add(&bridge->chain_node, &encoder->bridge_chain); mutex_unlock(&encoder->bridge_chain_mutex);
If we don't go to err_reset_bridge to remove it from the list, the bridge is left permanently linked in the active chain even though its attach operation failed and was rolled back. Will this cause use-after-free issues or crashes when the DRM core later traverses the chain to invoke pipeline callbacks?
Finally, lower down in this function at the err_reset_bridge label, there is a check for -EPROBE_DEFER:
err_reset_bridge:
... if (ret != -EPROBE_DEFER) DRM_ERROR(...); else dev_err_probe(encoder->dev->dev, -EPROBE_DEFER, ...);
Since the err_reset_bridge label is now only reachable when ret is strictly not equal to -EPROBE_DEFER, is the else branch containing dev_err_probe() now unreachable dead code?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=35
Luca Ceresoli
reviewerPATCH 36/37 drm/display: bridge-connector: handle bridge hotplug
In reply to Luca CeresoliThe drm_bridge_connector is nowadays the recommended way to implement DRM connectors when a chain of bridges is used, and as such it is the ideal component to implement DRM bridge hotplug. Thus, let the drm_bridge_connector be created once for the whole drm_encoder lifetime (as it is now), but make it able of creating and destroying the DRM connector reacting on bridge hot(un)plug events.
Unfortunately the current drm_bridge_connector_init() API is unable to support DRM bridge hotplug because it returns a drm_connector, and with hotplug the connector might start existing only later, and also be destroyed and recreated multiple times.
So add a new API which is similar but returns a pointer to the drm_bridge_connector, which is persistent, and supports bridge hotplug by creating and destroying the drm_connector based on hotplug events.
Because drm_bridge_connector_init() is really a drmm function (it does only drmm allocations), but without a drmm_ prefix, take this as an opportunity to call the new function with the same name but a drmm_ prefix:drmm_bridge_connector_init(). The old API can be replaced over time when needed to support hotplug, and eventually be removed if unused.
The new drmm_bridge_connector_init() API differs from the old one in a few aspects in order to support bridge hotplug:
* if the bridge chain is not (yet) complete, returns successfully without adding a drm_connector (in this case the old API returns an error)
* registers an event notifier block to be able of reacting to events related to bridge hotplug and create/destroy the drm_connector
---
I'm tempted to let drmm_bridge_connector_init() return int (0 or negative error) instead of a struct drm_bridge_connector *, but I'm not sure whether the drm_bridge_connector pointer may be useful in the future to invoke actions on the bridge_connector after its creation. Opnions about this would be welcome.
--- drivers/gpu/drm/display/drm_bridge_connector.c | 157 +++++++++++++++++++++++++ include/drm/drm_bridge_connector.h | 2 + 2 files changed, 159 insertions(+)
drivers/gpu/drm/display/drm_bridge_connector.c +157 -0
@@ -20,6 +20,7 @@#include <drm/drm_device.h> #include <drm/drm_edid.h> #include <drm/drm_managed.h> +#include <drm/drm_event_notifier.h> #include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h>
@@ -158,6 +159,10 @@ struct drm_bridge_connector {* destruction */ struct mutex dynconn_mutex; +/** +* @drm_event_nb: notifier to receive DRM hotplug-related events +*/ +struct notifier_block drm_event_nb; }; static struct drm_bridge_connector_dynconn *
@@ -1037,6 +1042,19 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector_return 0 ; } +static bool drm_bridge_connector_pipeline_is_complete (struct drm_bridge_connector *bridge_connector) +{ + struct drm_bridge *last_bridge __free(drm_bridge_put) = +drm_bridge_chain_get_last_bridge (bridge_connector->encoder); + +if (!last_bridge || !drm_bridge_is_tail (last_bridge)) { +drm_dbg_driver (bridge_connector->drm,"pipeline not (yet) fully connected" ); +return false; + } + +return true; +} +/** * drm_bridge_connector_add_connector - add the drm_connector * @bridge_connector: drm_bridge_connector to add the drm_connector to
@@ -1153,6 +1171,79 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgreturn ret; } +/* +* Propagate the attach chain and possibly add a drm_connector after a new +* drm_bridge is hot-plugged. +* +* The connector is added only if the pipeline is now complete. This could +* not be the case for various reasons: +* +* - the new bridge is just unrelated to our encoder +* - the new bridge is not be the next one in the pipeline +* - the new bridge is the next in the pipeline but the pipeline is not yet +* complete +* +* All these cases are normal, not an error. +*/ +static void drm_bridge_connector_try_complete (struct drm_bridge_connector *bridge_connector) +{ +int err; + +/* +* drm_connector already present, the new bridge must be for +* another card +*/ +if (bridge_connector->dynconn) +return ; + +/* Propagate the attach call chain to newly hotplugged bridge(s) */ + struct drm_bridge *last_bridge __free(drm_bridge_put) = +drm_bridge_chain_get_last_bridge (bridge_connector->encoder); + +/* Encoder chain empty? */ +if (!last_bridge) +return ; + + err = last_bridge->funcs->attach (last_bridge, bridge_connector->encoder, +DRM_BRIDGE_ATTACH_NO_CONNECTOR ); +if (err) +return ; + +/* Add the connector if the pipeline is now complete */ +if (drm_bridge_connector_pipeline_is_complete (bridge_connector)) +drm_bridge_connector_add_connector (bridge_connector); +} + +static int drm_bridge_connector_handle_event (struct notifier_block *nb, +unsigned long event,void *data) +{ +struct drm_bridge_connector *bridge_connector = + container_of(nb, struct drm_bridge_connector, drm_event_nb); + +switch (event) { +case DRM_MIPI_DSI_ATTACHED : +/* One or more bridges hot-plugged, try adding the drm_connector */ +drm_bridge_connector_try_complete (bridge_connector); +break ; +case DRM_BRIDGE_DETACHED : + { +/* +* A bridge was unplugged, remove the drm_connector if it's +* part of the same pipeline +*/ +struct drm_bridge *bridge = (struct drm_bridge *)data; + +if (bridge_connector->dynconn && + bridge->encoder == bridge_connector->encoder) +drm_bridge_connector_dynconn_release (bridge_connector); +break ; + } +default : + } + +return NOTIFY_DONE ; +} +static void drm_bridge_connector_fini (struct drm_device *dev,void *res) {struct drm_bridge_connector *bridge_connector = (struct drm_bridge_connector *)res;
@@ -1205,3 +1296,69 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,return &bridge_connector->dynconn->connector; }EXPORT_SYMBOL_GPL (drm_bridge_connector_init); + +static void drm_bridge_connector_notifier_unregister (struct drm_device *dev,void *res) +{ +struct notifier_block *nb = (struct notifier_block *)res; + +drm_event_notifier_unregister (nb); +} + +/** +* drmm_bridge_connector_init - Initialise the bridge_connector for a chain +* of bridges, with bridge hotplug support +* @drm: the DRM device +* @encoder: the encoder where the bridge chain starts +* +* Allocate, initialise and register a &drm_bridge_connector with the @drm +* device. The connector is associated with a chain of bridges that starts at +* the @encoder. All bridges in the chain shall report bridge operation flags +* (&drm_bridge->ops) and bridge output type (&drm_bridge->type), and none of +* them may create a DRM connector directly. +* +* Also adds a drm_connector if the bridge chain is complete, otherwise the +* &drm_bridge_connector will still be successfully created but without +* adding a drm_connector. In both cases the &drm_bridge_connector will +* receive events notifying bridge hot-plug and hot-unplug and add or +* destroy the drm_connector accordingly. +* +* Returns a pointer to the new &drm_bridge_connector on success, or a +* negative error pointer otherwise. +*/ +struct drm_bridge_connector *drmm_bridge_connector_init (struct drm_device *drm, +struct drm_encoder *encoder) +{ +struct drm_bridge_connector *bridge_connector; +int ret; + + bridge_connector =drmm_kzalloc (drm,sizeof (*bridge_connector),GFP_KERNEL ); +if (!bridge_connector) +return ERR_PTR (-ENOMEM ); + +mutex_init (&bridge_connector->dynconn_mutex); + bridge_connector->drm = drm; + bridge_connector->encoder = encoder; + bridge_connector->drm_event_nb.notifier_call = drm_bridge_connector_handle_event; + +if (drm_bridge_connector_pipeline_is_complete (bridge_connector)) { + ret =drm_bridge_connector_add_connector (bridge_connector); +if (ret) +return ERR_PTR (ret); + } + + ret =drmm_add_action_or_reset (drm, drm_bridge_connector_fini, bridge_connector); +if (ret) +return ERR_PTR (ret); + + ret =drm_event_notifier_register (&bridge_connector->drm_event_nb); +if (ret) +return ERR_PTR (ret); + + ret =drmm_add_action_or_reset (drm, drm_bridge_connector_notifier_unregister, + &bridge_connector->drm_event_nb); +if (ret) +return ERR_PTR (ret); + +return 0 ; +} +EXPORT_SYMBOL_GPL (drmm_bridge_connector_init);
include/drm/drm_bridge_connector.h +2 -0
@@ -10,6 +10,8 @@ struct drm_connector;struct drm_device ;struct drm_encoder ; +struct drm_bridge_connector *drmm_bridge_connector_init (struct drm_device *drm, +struct drm_encoder *encoder);struct drm_connector *drm_bridge_connector_init (struct drm_device *drm,struct drm_encoder *encoder);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 36/37] drm/display: bridge-connector: handle bridge hotplug
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Critical] `drmm_bridge_connector_init()` returns NULL instead of the allocated pointer on success.…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] drmm_bridge_connector_init() returns NULL instead of the allocated pointer on success.
- [High] Unchecked execution of the optional attach callback causes NULL pointer dereference.
- [High] TOCTOU race condition in dynconn creation leads to memory leaks and duplicate connector registrations.
- [High] Dynamic connector destruction on hot-unplug leaks drmm actions, leading to a Use-After-Free.
- [High] Lockless traversal of encoder->bridge_chain risks list corruption and Use-After-Free. --
commit 31a28cb0ac7316fddfb3b8148c8e28f4da0bce4f
Author: Luca Ceresoli <[email protected]>
drm/display: bridge-connector: handle bridge hotplug
This commit updates the DRM bridge connector infrastructure to handle bridge hot-plugging by creating and destroying the DRM connector dynamically. It introduces the drmm_bridge_connector_init() API, which registers a notifier to react to attach/detach events and manage the connector lifecycle.
Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0
-0
[ ... ]
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector_ · line 1048
Quoted 8 lines
drivers/gpu/drm/display/drm_bridge_connector.c +4
-0@@ -1037,6 +1042,19 @@ static int drm_bridge_connector_init_hdmi_audio_cec(struct drm_bridge_connector_return 0 ; } +static bool drm_bridge_connector_pipeline_is_complete (struct drm_bridge_connector *bridge_connector) +{ + struct drm_bridge *last_bridge __free(drm_bridge_put) = +drm_bridge_chain_get_last_bridge (bridge_connector->encoder);
Is it safe to call drm_bridge_chain_get_last_bridge() here without holding bridge_connector->encoder->bridge_chain_mutex? It seems this can be called asynchronously from hotplug event notifiers, potentially traversing the list while it is being modified.
Quoted 8 lines
drivers/gpu/drm/display/drm_bridge_connector.c +8
-0+ +if (!last_bridge || !drm_bridge_is_tail (last_bridge)) { +drm_dbg_driver (bridge_connector->drm,"pipeline not (yet) fully connected" ); +return false; + } + +return true; +}
[ ... ]
Quoted 17 lines
drivers/gpu/drm/display/drm_bridge_connector.c +13
-0@@ -1153,6 +1171,79 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridgreturn ret; } +/* +* Propagate the attach chain and possibly add a drm_connector after a new +* drm_bridge is hot-plugged. +* +* The connector is added only if the pipeline is now complete. This could +* not be the case for various reasons: +* +* - the new bridge is just unrelated to our encoder +* - the new bridge is not be the next one in the pipeline +* - the new bridge is the next in the pipeline but the pipeline is not yet +* complete +* +* All these cases are normal, not an error.
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1196
Quoted 10 lines
drivers/gpu/drm/display/drm_bridge_connector.c +10
-0+*/ +static void drm_bridge_connector_try_complete (struct drm_bridge_connector *bridge_connector) +{ +int err; + +/* +* drm_connector already present, the new bridge must be for +* another card +*/ +if (bridge_connector->dynconn)
Could there be a race condition here? If multiple hotplug events are processed concurrently, two threads could observe dynconn as NULL here outside the lock, and both proceed to allocate and assign it in drm_bridge_connector_add_connector().
Would it be better to re-verify bridge_connector->dynconn after acquiring dynconn_mutex inside drm_bridge_connector_add_connector()?
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1201
Quoted 5 lines
drivers/gpu/drm/display/drm_bridge_connector.c +5
-0+return ; + +/* Propagate the attach call chain to newly hotplugged bridge(s) */ + struct drm_bridge *last_bridge __free(drm_bridge_put) = +drm_bridge_chain_get_last_bridge (bridge_connector->encoder);
As mentioned above, should this list traversal be protected by bridge_connector->encoder->bridge_chain_mutex?
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1208
Quoted 7 lines
drivers/gpu/drm/display/drm_bridge_connector.c +7
-0+ +/* Encoder chain empty? */ +if (!last_bridge) +return ; + + err = last_bridge->funcs->attach (last_bridge, bridge_connector->encoder, +DRM_BRIDGE_ATTACH_NO_CONNECTOR );
What happens if the last bridge does not implement the attach callback?
Since attach is optional in struct drm_bridge_funcs, should there be a check for last_bridge->funcs->attach before calling it to avoid a NULL pointer dereference?
Quoted 20 lines
drivers/gpu/drm/display/drm_bridge_connector.c +20
-0+if (err) +return ; + +/* Add the connector if the pipeline is now complete */ +if (drm_bridge_connector_pipeline_is_complete (bridge_connector)) +drm_bridge_connector_add_connector (bridge_connector); +} + +static int drm_bridge_connector_handle_event (struct notifier_block *nb, +unsigned long event,void *data) +{ +struct drm_bridge_connector *bridge_connector = + container_of(nb, struct drm_bridge_connector, drm_event_nb); + +switch (event) { +case DRM_MIPI_DSI_ATTACHED : +/* One or more bridges hot-plugged, try adding the drm_connector */ +drm_bridge_connector_try_complete (bridge_connector); +break ; +case DRM_BRIDGE_DETACHED :
drivers/gpu/drm/display/drm_bridge_connector.c static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg · line 1238
Quoted 10 lines
drivers/gpu/drm/display/drm_bridge_connector.c +10
-0+ { +/* +* A bridge was unplugged, remove the drm_connector if it's +* part of the same pipeline +*/ +struct drm_bridge *bridge = (struct drm_bridge *)data; + +if (bridge_connector->dynconn && + bridge->encoder == bridge_connector->encoder) +drm_bridge_connector_dynconn_release (bridge_connector);
Does drm_bridge_connector_dynconn_release() safely clean up the drmm actions registered in drm_bridge_connector_init_hdmi_audio_cec()?
Since drmm_connector_hdmi_cec_register() and similar tie cleanup actions to the drm_device, releasing the connector here and freeing the dynconn structure might leave those actions active, potentially causing a use-after-free when the device is eventually destroyed.
Quoted 7 lines
drivers/gpu/drm/display/drm_bridge_connector.c +7
-0+break ; + } +default : + } + +return NOTIFY_DONE ; +}
[ ... ]
Quoted 25 lines
drivers/gpu/drm/display/drm_bridge_connector.c +25
-0+struct drm_bridge_connector *drmm_bridge_connector_init (struct drm_device *drm, +struct drm_encoder *encoder) +{ +struct drm_bridge_connector *bridge_connector; +int ret; + + bridge_connector =drmm_kzalloc (drm,sizeof (*bridge_connector),GFP_KERNEL ); +if (!bridge_connector) +return ERR_PTR (-ENOMEM ); + +mutex_init (&bridge_connector->dynconn_mutex); + bridge_connector->drm = drm; + bridge_connector->encoder = encoder; + bridge_connector->drm_event_nb.notifier_call = drm_bridge_connector_handle_event; + +if (drm_bridge_connector_pipeline_is_complete (bridge_connector)) { + ret =drm_bridge_connector_add_connector (bridge_connector); +if (ret) +return ERR_PTR (ret); + } + + ret =drmm_add_action_or_reset (drm, drm_bridge_connector_fini, bridge_connector); +if (ret) +return ERR_PTR (ret); +
drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 1362
Quoted 10 lines
drivers/gpu/drm/display/drm_bridge_connector.c +10
-0+ ret =drm_event_notifier_register (&bridge_connector->drm_event_nb); +if (ret) +return ERR_PTR (ret); + + ret =drmm_add_action_or_reset (drm, drm_bridge_connector_notifier_unregister, + &bridge_connector->drm_event_nb); +if (ret) +return ERR_PTR (ret); + +return 0 ;
Should this return the bridge_connector pointer instead of 0? Callers using IS_ERR() will treat 0 (NULL) as success and potentially dereference it.
Quoted 2 lines
drivers/gpu/drm/display/drm_bridge_connector.c +2
-0+} +EXPORT_SYMBOL_GPL (drmm_bridge_connector_init);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=36
Luca Ceresoli
reviewerPATCH 37/37 drm/mxsfb/lcdif: enable bridge hotplug
In reply to Luca CeresoliSwitch to the new drmm_bridge_connector_init() so the drm_bridge_connector will handle bridge hotplugging.
--- drivers/gpu/drm/mxsfb/lcdif_drv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/mxsfb/lcdif_drv.c +4 -4
@@ -58,7 +58,7 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)struct of_endpoint of_ep;struct drm_bridge *bridge;struct drm_encoder *encoder; -struct drm_connector *connector; +struct drm_bridge_connector *bridge_connector;int ret;if (!of_device_is_available (remote))
@@ -94,9 +94,9 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)"Failed to attach bridge for endpoint%u\n" , of_ep.id); - connector =drm_bridge_connector_init (lcdif->drm, encoder); -if (IS_ERR (connector)) -return dev_err_probe (dev,PTR_ERR (connector), + bridge_connector =drmm_bridge_connector_init (lcdif->drm, encoder); +if (IS_ERR (bridge_connector)) +return dev_err_probe (dev,PTR_ERR (bridge_connector),"Failed to init bridge_connector for endpoint%u\n" , of_ep.id); }
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 37/37] drm/mxsfb/lcdif: enable bridge hotplug
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Use-After-Free via global DRM event notifier due to lifetime mismatch. - [High] The newly…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Use-After-Free via global DRM event notifier due to lifetime mismatch.
- [High] The newly introduced API drmm_bridge_connector_init() returns NULL instead of the allocated pointer on success. --
commit cc8f05ac9a777f8eb1ce4636df74812c2db5a92c
Author: Luca Ceresoli <[email protected]>
drm/mxsfb/lcdif: enable bridge hotplug
This commit switches to the new drmm_bridge_connector_init() function to allow the drm_bridge_connector to handle bridge hotplugging.
Quoted 3 lines
drivers/gpu/drm/mxsfb/lcdif_drv.c +0
-0
[ ... ]
drivers/gpu/drm/mxsfb/lcdif_drv.c static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) · line 97
Quoted 8 lines
drivers/gpu/drm/mxsfb/lcdif_drv.c +1
-3@@ -94,9 +94,9 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)"Failed to attach bridge for endpoint%u\n" , of_ep.id); - connector =drm_bridge_connector_init (lcdif->drm, encoder); -if (IS_ERR (connector)) - return dev_err_probe(dev, PTR_ERR(connector), + bridge_connector =drmm_bridge_connector_init (lcdif->drm, encoder);
Could this regression lead to a use-after-free if the physical device is unbound?
The encoder passed to drmm_bridge_connector_init() is allocated earlier in this function using devm_kzalloc(), which ties its lifetime to the physical device.
However, drmm_bridge_connector_init() ties the new bridge connector to the DRM device's lifetime and registers a global hotplug notifier that references this encoder.
If the physical device is unbound while a userspace file descriptor is still open, the DRM device and its notifier remain active after devres has freed the encoder.
A subsequent bridge hotplug event (such as DRM_MIPI_DSI_ATTACHED) could then trigger the notifier, causing it to dereference the freed encoder when locking encoder->bridge_chain_mutex.
Would it be safer to allocate the encoder using drmm_encoder_alloc() instead of devm_kzalloc() so its lifetime matches the DRM device?
drivers/gpu/drm/mxsfb/lcdif_drv.c static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) · line 99
Quoted 2 lines
drivers/gpu/drm/mxsfb/lcdif_drv.c +2
-0+if (IS_ERR (bridge_connector)) + return dev_err_probe(dev, PTR_ERR(bridge_connector),
Does the new drmm_bridge_connector_init() API return a NULL pointer instead of the allocated object on success?
Looking at the core implementation of drmm_bridge_connector_init(), it appears to correctly allocate and initialize the bridge connector, but incorrectly ends with return 0 instead of returning the allocated object.
Since IS_ERR() evaluates to false for NULL, the check here passes, but this regression means any code trying to use the returned bridge_connector pointer later will encounter a NULL pointer dereference.
Does the implementation in drivers/gpu/drm/display/drm_bridge_connector.c need to be updated to return the allocated object?
Quoted 3 lines
drivers/gpu/drm/mxsfb/lcdif_drv.c +0
-0"Failed to init bridge_connector for endpoint%u\n" , of_ep.id); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=37
Luca Ceresoli
reviewerHello,
I presented this series last Friday during the Display Next Hackfest 2026. Here's a summary of the discussion.
The discussion was mostly with Dmitry Baryshkov (major contributor to the drm_bridge_connector code) and a bit with Paul Kocialkowski and others. Thanks all!
The proposal to extend the drm_bridge_connector to implement hotplug, and the general architecture proposed, raised no objection. So I'm going to continue with this approach.
There were various implementation aspects discussed, which will be my focus in the coming weeks:
* The requirement that bridge drivers (the last bridge before the hotplug connector, at least) must return -EPROBE_DEFER when the next bridge is not present is risky: some drivers might just defer during their probe, potentially generating defer loops.
* Alternative discussed: bridge drivers can expose info about how to find the next bridge (the fwnode perhaps) using a new API, keeping the existing untouched. Maybe they could also expose the previous driver fwnode, even though it currently seems unnecessary.
* There are various options about how such new API should look like:
during registration (drm_bridge_add()? too early for some complex drivers?), at attach time (maybe too late?) or as a new callback (called when?). In all cases this new API would be a superset of the .is_tail callback proposed in patch 30, which would then become unnecessary.
* Dmitry asked whether all the attach chain could be entirely moved to the drm_bridge_connector for drivers using it. Worth investigating.
* I did a quick investigation after the event and it would work nicely for many drivers but some are tricky. Needs more understanding.
* The added drm_atomic_shutdown() is wrong, it would stop streaming on all outputs on the card. But it is probably unnecessary, just removing the connector should be enough.
That's all according to my notes. Feel free to reply in case I forgot anything or something is wrong. Expect a v2 in the coming weeks with the above changes, or discussion in case of unexpected issues.
Kind regards,
Luca
Quoted 299 lines · Luca Ceresoli
Hello,
this series adds support for Linux-based devices with a DRM pipeline whose final components, including one or more bridges, can be hot-plugged and hot-unplugged.
TL;DR:
* This new approach is totally different from the one proposed in the past [0], and the code is an almost completely rewrite
* If you already know the use case, feel free to skip to the "Design" section belowUse case
========This series targets as its first use case a professional product (GE SUNH) that is composed of a "main" part, with the main SoC and able to work autonomously with limited features, and an optional "add-on" that enables more features by adding more hardware peripherals.
The hotplug connector has a MIPI DSI bus. The addon has a DSI-to-LVDS bridge and an LVDS panel attached to it. Different addon models can have different components. As a consequence, a DRM bridge must be added and removed at runtime without tearing down the whole card. This is currently not possible, and this series enables it.
DRM already supports pipelines whose display can be removed, but all the components preceding it (all the display controller and any bridges) are assumed to be fixed and cannot be plugged, removed or modified at runtime. Additionally, dynamic
drm_connectorsare supported for DP MST.This picture summarizes the DRM structure implemented by this series:
.------------------------.
| DISPLAY CONTROLLER | | .---------. .------. | | | ENCODER |<--| CRTC | | | '---------' '------' | '------|-----------------' | MACHANICAL |DSI HOTPLUG V CONNECTOR .---------. .--. .-. .---------. .-------. | 0 to N | | _| _| | | 1 to N | | | | BRIDGES |--DSI-->||_ |_ |--DSI-->| BRIDGES |--LVDS-->| PANEL | | | | | | | | | | | '---------' '--' '-' '---------' '-------'[--- fixed components --] [----------- removable add-on -----------]
The video bus is MIPI DSI in the example and in the implementation provided by this series, but the implementation is meant to allow generalization to other video busses without native hotplug support, such as parallel video and LVDS. Addons which terminate with a HDMI/DP connector are possible too.
== Design
The old approach [0] was based on a hotplug-bridge driver, connected between the last fixed bridge and the first removable bridge.
That approach has been rejected, and this new approach is based on a central place to handle DRM hotplug, not a specific driver.
The
drm_bridge_connectoris nowadays the recommended way to implement DRM connectors when a chain of bridges is used. It takes care of adding thedrm_connectorwhen the pipeline is composed by an arbitrarily long chain of bridges, which it scans to properly implement thedrm_connectoroperations.As such the
drm_bridge_connectorlooked like the ideal component to implement DRM bridge hotplug.This series augments the
drm_bridge_connectorcode to be able to create and destroy thedrm_connectorreacting on hot(un)plug events.== Series description
This series has many preparatory patches: to make the
drm_bridge_connectorcode allocate thedrm_connectordynamically and to prepare various other parts of the involved DRM code.In current code the last bridge in the encoder chain is always assumed to complete the pipeline. There is no way for a bridge to tell "I'm currently the last bridge in the encoder chain, but I need an next bridge to work". This series has some patches to allow such a behaviour:
* bridges can now report whether they conclude the pipeline or not (I propose the "tail bridge" naming to tell this)
* returning -EPROBE_DEFER on bridge attach is not considered a hard error anymore, it's normal when the next bridge is needed but not yet presentCompared to the hotplug-bridge approach, now bridge drivers need a bit of adaptation in order to support that the following bridge is hotpluggable. So there are a few changes to the samsung-dsim bridge driver, which in the hardware I'm working on is the last fixed bridge.
Finally, as the current
drm_bridge_connectorAPI is unable to support hotplug, a new API is added to enable the new features. This makes existing drivers not affected by the changes. The last patch shows to changes needed to an encoder driver to switch to the new API enabling hotplug support.== Series layout
1. Add a dynamic variant of
drm_connector_hdmi_init()
(needed for the bridge-connector to allocate the connector dynamically)* drm/connector: split
drmm_connector_hdmi_init()in 3 parts
* drm/connector: adddrm_connector_hdmi_dynamic_init()2. bridge-connector: split the long
drm_bridge_connector_init()in various parts in preparation to be called in different ways* drm/display: bridge-connector: rename variable for consistency
* drm/display: bridge-connector: store thedrm_devicepointer
* drm/display: bridge-connector: split code creating the connector to a subfunction
* drm/display: bridge-connector: use adrm_bridge_connectorinternally, not adrm_connector
* drm/display: bridge-connector: extractdrm_bridge_connector_get_bridges()
* drm/display: bridge-connector: return int fromdrm_bridge_connector_get_bridges()
* drm/display: bridge-connector: extractdrm_bridge_connector_init_hdmi_audio_cec()
* drm/display: bridge-connector: return int fromdrm_bridge_connector_init_hdmi_audio_cec()
* drm/display: bridge-connector: return int fromdrm_bridge_connector_add_connector()3. bridge-connector: create the
drm_connectordynamically* drm/display: bridge-connector: hoist error management to common code
* drm/display: bridge-connector: movedrm_bridge_connector_put_bridges()definition eariler
* drm/display: bridge-connector: add non-drmm variant ofdrm_bridge_connector_put_bridges()
* drm/display: bridge-connector: allocate the connector dynamically
* drm/display: bridge-connector: move per-connector fields to the dynamic connector
* drm/display: bridge-connector: protect dynconn creation and destruction with a mutex4. samsung-dsim: prepare driver to work when the following bridge is hotpluggable
* drm/bridge: samsung-dsim: remove the
panel_bridgeonhost_detach
* drm/bridge: samsung-dsim: movedrm_bridge_add()call to probe
* drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available5. Misc preparation work
* drm/bridge: initialize
chain_nodelist head on allocation
* drm/bridge: initializechain_nodelist head on detach and attach errors6.
drm_bridge: stop pipeline when a bridge is removed* drm/encoder: add
drm_encoder_cleanup_from()
* drm/atomic: movedrm_atomic_helper_disable_all()anddrm_atomic_helper_shutdown()fromdrm_atomic_helpertodrm_atomic
* drm/bridge: shutdown and cleanup on bridge unplug7. Add notifier mechanism to let common code (the bridge-connector) take actions on hotplug events
* drm: event-notifier: add mechanism to notify about hotplug events
* drm/bridge: notify about detached bridges
* drm/mipi-dsi: turnDRM_MIPI_DSIinto a tristate
* drm/mipi-dsi: notify about DSI attach8. Allow common code to know when the pipeline is complete
* drm/bridge: add
drm_bridge_is_tail()to know whether a bridge completes the pipeline
* drm/bridge: panel: implement .is_tail
* drm/bridge: display-connector: implement .is_tail
* drm/bridge: samsung-dsim: implement .is_tail
* drm/bridge: ti-sn65dsi83: implement .is_tail9. Allow probing incomplete pipelines
* drm/bridge:
drm_bridge_attach(): don't fail on -EPROBE_DEFER10. Implement bridge hotplug in bridge-connector, enable it in a driver
* drm/display: bridge-connector: handle bridge hotplug
* drm/mxsfb/lcdif: enable bridge hotplug== Grand plan
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 ondevm_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 ondrm_bridgeaccessors
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 (v7.2)
7. ✔of_drm_find_bridge
a. ✔ addof_drm_get_bridge()(v7.0),
convert basic direct users (v7.0-v7.1)
b. ✔ convert directof_drm_get_bridge()users, part 2 (v7.0) c. ✔ convert directof_drm_get_bridge()users, part 3 (v7.0) d. ✔ convert directof_drm_get_bridge()users, part 4 (v7.1-v7.2) e. ✔ bridge-onlydrm_of_find_panel_or_bridge()users (v7.2)
8.drm_of_find_panel_or_bridge,*_of_get_bridge
9. ✔ enforcedrm_bridge_addbeforedrm_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_bridge_enter/exit() to protect device resources (v7.0) B. … protectprivate_objremoval from list
C. ✔ Adddrm_bridge_clear_and_put()(v7.1)
3. … DSI host-device driver interaction
4. ✔ removing the need for the "always-disconnected" connector
5. ✔ Migrate i.MX LCDIF driver to bridge-connector (v7.2)
6. ➜ DRM bridge hotplug
A. ➜ Bridge hotplug management in the DRM core
1. ✔ bridge-connector: attach encoder to the connector (v7.2)
2. ➜ drm bridge hotplug
B. Device tree description[0] https://lore.kernel.org/lkml/[email protected]/#t
== Dependencies
This series depends on:
* "drm/atomic:
drm_atomic_private_obj_fini: protectprivate_objremoval
from list"
- https://lore.kernel.org/lkml/20260324-drm-bridge-atomic-vs-remove-private_obj-v3-1-64deefe84044@bootlin.com/
- Reason: avoid sporadic deadlockSigned-off-by Luca Ceresoli <[email protected]>---
Luca Ceresoli (37):
drm/connector: splitdrmm_connector_hdmi_init()in 3 parts
drm/connector: adddrm_connector_hdmi_dynamic_init()
drm/display: bridge-connector: rename variable for consistency
drm/display: bridge-connector: store thedrm_devicepointer
drm/display: bridge-connector: split code creating the connector to a subfunction
drm/display: bridge-connector: use adrm_bridge_connectorinternally, not adrm_connectordrm/display: bridge-connector: extractdrm_bridge_connector_get_bridges()
drm/display: bridge-connector: return int fromdrm_bridge_connector_get_bridges()
drm/display: bridge-connector: extractdrm_bridge_connector_init_hdmi_audio_cec()
drm/display: bridge-connector: return int fromdrm_bridge_connector_init_hdmi_audio_cec()drm/display: bridge-connector: return int fromdrm_bridge_connector_add_connector()
drm/display: bridge-connector: hoist error management to common code
drm/display: bridge-connector: movedrm_bridge_connector_put_bridges()definition eariler drm/display: bridge-connector: add non-drmm variant ofdrm_bridge_connector_put_bridges()drm/display: bridge-connector: allocate the connector dynamically
drm/display: bridge-connector: move per-connector fields to the dynamic connector
drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
drm/bridge: samsung-dsim: remove thepanel_bridgeonhost_detach
drm/bridge: samsung-dsim: movedrm_bridge_add()call to probe
drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available drm/bridge: initializechain_nodelist head on allocation
drm/bridge: initializechain_nodelist head on detach and attach errors
drm/encoder: adddrm_encoder_cleanup_from()
drm/atomic: movedrm_atomic_helper_disable_all()anddrm_atomic_helper_shutdown()fromdrm_atomic_helpertodrm_atomicdrm/bridge: shutdown and cleanup on bridge unplug
drm: event-notifier: add mechanism to notify about hotplug events
drm/bridge: notify about detached bridges
drm/mipi-dsi: turnDRM_MIPI_DSIinto a tristate
drm/mipi-dsi: notify about DSI attach
drm/bridge: adddrm_bridge_is_tail()to know whether a bridge completes the pipeline
drm/bridge: panel: implement .is_tail
drm/bridge: display-connector: implement .is_tail
drm/bridge: samsung-dsim: implement .is_tail
drm/bridge: ti-sn65dsi83: implement .is_tail
drm/bridge:drm_bridge_attach(): don't fail on -EPROBE_DEFER
drm/display: bridge-connector: handle bridge hotplug
drm/mxsfb/lcdif: enable bridge hotplugdrivers/gpu/drm/Kconfig | 7 +- drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/bridge/display-connector.c | 7 + drivers/gpu/drm/bridge/panel.c | 8 +- drivers/gpu/drm/bridge/samsung-dsim.c | 36 +- drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 + drivers/gpu/drm/display/drm_bridge_connector.c | 835 +++++++++++++++++-------- drivers/gpu/drm/drm_atomic.c | 115 ++++ drivers/gpu/drm/drm_atomic_helper.c | 76 +-- drivers/gpu/drm/drm_bridge.c | 47 +- drivers/gpu/drm/drm_connector.c | 155 +++-- drivers/gpu/drm/drm_encoder.c | 38 ++ drivers/gpu/drm/drm_event_notifier.c | 58 ++ drivers/gpu/drm/drm_mipi_dsi.c | 3 + drivers/gpu/drm/mxsfb/lcdif_drv.c | 8 +- include/drm/bridge/samsung-dsim.h | 2 + include/drm/drm_atomic.h | 3 + include/drm/drm_bridge.h | 19 + include/drm/drm_bridge_connector.h | 2 + include/drm/drm_connector.h | 9 + include/drm/drm_encoder.h | 1 + include/drm/drm_event_notifier.h | 36 ++ 22 files changed, 1078 insertions(+), 396 deletions(-)---
base-commit:289b9a790d52a6865db3006f07922a9191faa54e
change-id: 20260515-drm-bridge-hotplug-46265d3a2f85
Quoted 5 lines
Best regards,
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Luca Ceresoli
reviewerHello,
Quoted 4 lines · Luca Ceresoli
Hello,
I presented this series last Friday during the Display Next Hackfest 2026. Here's a summary of the discussion.
For the records, the presentation slides are available at
https://bootlin.com/pub/conferences/2026/display-next-hackfest/ceresoli-drm-bridge-hotplug.pdf
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com