drm/bridge: Implement generic USB Type-C DP HPD bridge
Subsystems (6)
v7 cover drm/bridge: Implement generic USB Type-C DP HPD bridge
From: Chaoyi Chen <[email protected]>
This series is split from the v15 "Add Type-C DP support for RK3399 EVB IND board" series [1]. It focuses on the DRM bridge and Rockchip platform CDN-DP controller changes.
[1] https://lore.kernel.org/all/[email protected]/
====
1. Generic Type-C DP HPD bridge
Currently, several USB-C controller drivers register their own DP HPD bridge via aux-hpd-bridge.c, each duplicating the same logic. For devicetree based platforms, the USB-C controller may vary across boards, and not every USB-C controller driver implements this feature. Patch 1 implements a generic DP HPD bridge that monitors Type-C bus events and automatically creates an HPD bridge when a Type-C port device with DP SVID is registered.
2. Multiple bridge model for CDN-DP
The RK3399 has two USB/DP combo PHY and one CDN-DP controller. Patch 5 introduces a multi-bridge model where each PHY port gets a separate encoder and bridge, allowing flexible selection of the output PHY port. This is based on the DRM AUX HPD bridge rather than extcon.
====
Patch 1 adds new API to check whether a DisplayPort HPD bridge has
already been registered(Sebastian).
Patch 2 adds generic USB Type-C DP HPD bridge (Dmitry, Heikki). Patch 3 adds module soft depend for USB Type-C DP HPD bridge(Sebastian). Patch 4 adds new API drm_aux_bridge_register_from_node() (Neil). Patch 5 adds DRM AUX bridge support for RK3399 USBDP PHY (Neil). Patch 6 drops CDN-DP's extcon dependency when Type-C is present (Dmitry). Patch 7 adds multiple bridges to support PHY port selection (Dmitry, Luca).
Changes in v7:
- Link to v6: https://lore.kernel.org/all/[email protected]/
- Fix extcon HPD detection by checking lanes in cdn_dp_connected_port() (sashiko).
- Bound endpoint count by PHY ports to avoid overflow and uninitialized reads (sashiko).
- Use drm_bridge_clear_and_put() to clear next_bridge_list pointers (sashiko).
- Clear EDID cache pointers after free in unbind() (sashiko).
Changes in v6:
- Link to v5: https://lore.kernel.org/all/[email protected]/
- Avoid duplicate registration of the same DisplayPort HPD bridge.
Changes in v5:
- Link to v4: https://lore.kernel.org/all/[email protected]/
- Add module soft depend for USB Type-C DP HPD bridge.
Changes in v4:
- Link to v3: https://lore.kernel.org/all/[email protected]/
- Scan the entire typec_bus and attempt to register the hpd bridge, so as not to miss devices that were already added during initialization.
Changes in v3:
- Link to v2: https://lore.kernel.org/all/[email protected]/
(Sorry, I forgot to add the "v2" title, so it looks like v1.)
- Remove now-redundant call to drm_connector_attach_encoder()
- Rebase to v7.2-rc2
Changes in v2:
- Link to v1: https://lore.kernel.org/all/[email protected]/
- Add copyright text.
- Remove useless goto.
- Fix incorrect function names in the documentation comments.
- Fix the check logic for dp->active_port (0 is valid).
- Fix the uninitialized prev_port.
- Remove duplicate logic from cdn_dp_switch_port().
- Fix the prototype of cdn_dp_bridge_hpd_notify().
- Properly release connector->fwnode.
- Properly release next_bridge.
Chaoyi Chen (7):
drm/bridge: aux-hpd-bridge: Add drm_dev_has_dp_hpd_bridge() drm/bridge: Implement generic USB Type-C DP HPD bridge drm/display: Add soft depend for aux-hpd-typec-dp-bridge module drm/bridge: aux: Add drm_aux_bridge_register_from_node()
phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge drm/rockchip: cdn-dp: Support handle lane info without extcon drm/rockchip: cdn-dp: Add multiple bridges to support PHY port
selection
drivers/gpu/drm/bridge/Kconfig | 10 + drivers/gpu/drm/bridge/Makefile | 1 + drivers/gpu/drm/bridge/aux-bridge.c | 26 +- drivers/gpu/drm/bridge/aux-hpd-bridge.c | 42 +- .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c | 67 ++++ .../gpu/drm/display/drm_display_helper_mod.c | 1 + drivers/gpu/drm/rockchip/Kconfig | 1 + drivers/gpu/drm/rockchip/cdn-dp-core.c | 365 +++++++++++++++--- drivers/gpu/drm/rockchip/cdn-dp-core.h | 18 +- drivers/phy/rockchip/Kconfig | 2 + drivers/phy/rockchip/phy-rockchip-typec.c | 13 +- include/drm/bridge/aux-bridge.h | 12 + 12 files changed, 486 insertions(+), 72 deletions(-) create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
Signature · 1 line
2.53.0
PATCH v7 1/7 drm/bridge: aux-hpd-bridge: Add drm_dev_has_dp_hpd_bridge()
From: Chaoyi Chen <[email protected]>
Add a new API to check whether a DisplayPort HPD bridge has already been registered. This helps avoid duplicate registration of the same HPD bridge, although the current framework allows doing so.
---
(no changes since v7)
--- drivers/gpu/drm/bridge/aux-hpd-bridge.c | 42 ++++++++++++++++++++++++- include/drm/bridge/aux-bridge.h | 6 ++++ 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +41 -1
@@ -12,6 +12,8 @@#include <drm/drm_bridge.h> #include <drm/bridge/aux-bridge.h> +#define DRM_AUX_HPD_BRIDGE_NAME "dp_hpd_bridge" +static DEFINE_IDA (drm_aux_hpd_bridge_ida);struct drm_aux_hpd_bridge_data {
@@ -36,6 +38,44 @@ static void drm_aux_hpd_bridge_free_adev(void *_adev)auxiliary_device_uninit (_adev); } +static int hpd_bridge_match (struct device *dev,const void *data) +{ +const struct device_node *np = data; +struct auxiliary_device *adev; + +if (!dev_is_auxiliary (dev)) +return 0 ; + + adev =to_auxiliary_dev (dev); +if (strcmp (adev->name,DRM_AUX_HPD_BRIDGE_NAME )) +return 0 ; + +return adev->dev.platform_data == np; +} + +/** +* drm_dev_has_dp_hpd_bridge - check whether a HPD DisplayPort bridge is registered +* @parent: device instance providing this bridge +* @np: device node pointer corresponding to this bridge instance +* +* Walk the children of @parent and check whether a HPD DisplayPort bridge for +* the given @np has already been registered via devm_drm_dp_hpd_bridge_add(). +* +* Return: true if a HPD bridge for @parent / @np already exists, false otherwise +*/ +bool drm_dev_has_dp_hpd_bridge (struct device *parent,struct device_node *np) +{ +struct device *child; + + child =device_find_child (parent, np, hpd_bridge_match); +if (child) { +put_device (child); +return true; + } +return false; +} +EXPORT_SYMBOL_GPL (drm_dev_has_dp_hpd_bridge); +/** * devm_drm_dp_hpd_bridge_alloc - allocate a HPD DisplayPort bridge * @parent: device instance providing this bridge
@@ -63,7 +103,7 @@ struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, str } adev->id = ret; - adev->name ="dp_hpd_bridge" ; + adev->name =DRM_AUX_HPD_BRIDGE_NAME ; adev->dev.parent = parent; adev->dev.release = drm_aux_hpd_bridge_release; adev->dev.platform_data =of_node_get (np);
include/drm/bridge/aux-bridge.h +6 -0
@@ -25,6 +25,7 @@ struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, strint devm_drm_dp_hpd_bridge_add (struct device *dev,struct auxiliary_device *adev);struct device *drm_dp_hpd_bridge_register (struct device *parent,struct device_node *np); +bool drm_dev_has_dp_hpd_bridge (struct device *parent,struct device_node *np);void drm_aux_hpd_bridge_notify (struct device *dev,enum drm_connector_status status);#else static inline struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent,
@@ -44,6 +45,11 @@ static inline struct device *drm_dp_hpd_bridge_register(struct device *parent,return NULL ; } +static inline bool drm_dev_has_dp_hpd_bridge (struct device *parent,struct device_node *np) +{ +return false; +} +static inline void drm_aux_hpd_bridge_notify (struct device *dev,enum drm_connector_status status) { }
Signature · 1 line
2.53.0
PATCH v7 2/7 drm/bridge: Implement generic USB Type-C DP HPD bridge
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
The HPD function of Type-C DP is implemented through drm_connector_oob_hotplug_event(). For embedded DP, it is required that the DRM connector fwnode corresponds to the Type-C port fwnode.
To describe the relationship between the DP controller and the Type-C port device, we usually using drm_bridge to build a bridge chain.
Now several USB-C controller drivers have already implemented the DP HPD bridge function provided by aux-hpd-bridge.c, it will build a DP HPD bridge on USB-C connector port device.
But this requires the USB-C controller driver to manually register the HPD bridge. If the driver does not implement this feature, the bridge will not be create.
So this patch implements a generic DP HPD bridge based on aux-hpd-bridge.c. It will monitor Type-C bus events, and when a Type-C port device containing the DP svid is registered, it will create an HPD bridge for it without the need for the USB-C controller driver to implement it.
---
(no changes since v7)
Changes in v6:
- Avoid duplicate registration of the same DisplayPort HPD bridge.
(no changes since v5)
Changes in v4:
- Scan the entire typec_bus and attempt to register the hpd bridge, so as not to miss devices that were already added during initialization.
(no changes since v3)
Changes in v2:
- Add copyright text.
- Remove useless goto.
--- drivers/gpu/drm/bridge/Kconfig | 10 +++ drivers/gpu/drm/bridge/Makefile | 1 + .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c | 67 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
drivers/gpu/drm/bridge/Kconfig +10 -0
@@ -30,6 +30,16 @@ config DRM_AUX_HPD_BRIDGE Simple bridge that terminates the bridge chain and provides HPD support. +if DRM_AUX_HPD_BRIDGE +config DRM_AUX_HPD_TYPEC_BRIDGE + tristate + depends on TYPEC || !TYPEC + default TYPEC + help + Simple bridge that terminates the bridge chain and provides HPD + support. It build bridge on each USB-C connector device node. +endif + menu "Display Interface Bridges" depends on DRM && DRM_BRIDGE
drivers/gpu/drm/bridge/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DRM_AUX_BRIDGE) += aux-bridge.o obj-$(CONFIG_DRM_AUX_HPD_BRIDGE) += aux-hpd-bridge.o +obj-$(CONFIG_DRM_AUX_HPD_TYPEC_BRIDGE) += aux-hpd-typec-dp-bridge.o obj-$(CONFIG_DRM_CHIPONE_ICN6211) += chipone-icn6211.o obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o obj-$(CONFIG_DRM_CROS_EC_ANX7688) += cros-ec-anx7688.o
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Attaching devm actions to an unowned device without strict dependencies causes a use-after-free…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Attaching devm actions to an unowned device without strict dependencies causes a use-after-free panic on module unload.
- [Medium] Missing NULL check for the OF device node causes broken bridge registration on non-Device Tree systems for multi-port controllers.
- [Medium] Concurrent execution of bus iteration and notifier callback causes duplicate bridge registration.
- [Low] The Kconfig dependency allows the module to be built when CONFIG_TYPEC is disabled, causing a link error.
--
commit 9eab2892d2a7baba27c2d68547a8aad1b13a8541
Author: Chaoyi Chen <[email protected]>
drm/bridge: Implement generic USB Type-C DP HPD bridge
This commit implements a generic DisplayPort HPD bridge based on USB Type-C events. It registers a bus notifier on the typec_bus to automatically create HPD bridges for Type-C ports with the DP alternate mode. This removes the need for individual USB-C controller drivers to manually register the bridge.
Quoted 5 lines
drivers/gpu/drm/bridge/Kconfig +0
-0@@ -30,6 +30,16 @@ config DRM_AUX_HPD_BRIDGE
[ ... ]
drivers/gpu/drm/bridge/Kconfig config DRM_AUX_HPD_BRIDGE · line 36
Quoted 4 lines
drivers/gpu/drm/bridge/Kconfig +4
-0+if DRM_AUX_HPD_BRIDGE +config DRM_AUX_HPD_TYPEC_BRIDGE + tristate + depends on TYPEC || !TYPEC
[Severity: Low]
Will this dependency allow the module to be built when CONFIG_TYPEC is disabled?
If CONFIG_TYPEC=n, the condition "!TYPEC" evaluates to true. However, the source file unconditionally uses symbols from the Type-C subsystem, which would result in unresolved external symbols during linking.
Quoted 5 lines
drivers/gpu/drm/bridge/Kconfig +5
-0+ default TYPEC + help + Simple bridge that terminates the bridge chain and provides HPD + support. It build bridge on each USB-C connector device node. +endif
[ ... ]
Quoted 5 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +0
-0
[ ... ]
Quoted 7 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +7
-0+static int drm_typec_bus_event (struct notifier_block *nb,unsigned long action, +void *data) +{ +struct device *dev = (struct device *)data; +struct typec_altmode *alt =to_typec_altmode (dev); +struct device_node *np; +
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 29
Quoted 10 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +10
-0+if (action !=BUS_NOTIFY_ADD_DEVICE ) +return NOTIFY_OK ; + +/* +* alt->dev.parent->parent : USB-C controller device +* alt->dev.parent : USB-C connector device +*/ +if (is_typec_port_altmode (&alt->dev) && alt->svid ==USB_TYPEC_DP_SID ) { + np =to_of_node (alt->dev.parent->fwnode); +if (!drm_dev_has_dp_hpd_bridge (alt->dev.parent->parent, np))
[Severity: Medium]
What happens on non-Device Tree systems (like ACPI) where to_of_node() returns NULL?
It looks like np will be NULL, and if there are multiple ports on the same controller, they could all alias to the same NULL platform data. Does this mean only the first port gets a bridge and subsequent ports are skipped?
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 30
Quoted 1 line
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +1
-0+drm_dp_hpd_bridge_register (alt->dev.parent->parent, np);
[Severity: High]
Does attaching a devm-managed resource to the unowned USB-C controller device (alt->dev.parent->parent) risk a use-after-free on module unload?
Since the observer module doesn't clean these up on exit, the devm actions could outlive the module. This might crash the system when the controller is eventually unbound and devres executes the unmapped cleanup action.
Quoted 4 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +4
-0+ } + +return NOTIFY_OK ; +}
[ ... ]
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 58
Quoted 8 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +8
-0+static int __init drm_aux_hpd_typec_dp_bridge_module_init (void ) +{ +bus_register_notifier (&typec_bus, &drm_typec_event_nb); +/* +* Before module initialization, some devices may have already been added. +* Register the HPD bridge for these devices. +*/ +bus_for_each_dev (&typec_bus,NULL ,NULL , check_device_already_added);
[Severity: Medium]
Can a device be processed twice here?
By registering the bus notifier before iterating over existing devices, is there a race condition where a newly added device triggers the notifier concurrently while bus_for_each_dev() is evaluating it?
The check-and-register sequence in drm_typec_bus_event() doesn't appear to use locking, which might lead to duplicate bridge registrations.
Quoted 2 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +2
-0+return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v7 3/7 drm/display: Add soft depend for aux-hpd-typec-dp-bridge module
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
The aux-hpd-typec-dp-bridge module serves as a generic TypeC DisplayPort HPD bridge and is not required by any other module. Therefore, it will not be auto-loaded.
Given that the drm_display_helper module houses DisplayPort-related helper code, add a MODULE_SOFTDEP() within it to suggest loading the aux-hpd-typec-dp-bridge module beforehand.
---
(no changes since v6)
--- drivers/gpu/drm/display/drm_display_helper_mod.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/display/drm_display_helper_mod.c +1 -0
@@ -18,5 +18,6 @@ static void __exit drm_display_helper_module_exit(void)drm_dp_aux_dev_exit (); } +MODULE_SOFTDEP ("pre: aux-hpd-typec-dp-bridge" );module_init (drm_display_helper_module_init);module_exit (drm_display_helper_module_exit);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 3/7] drm/display: Add soft depend for aux-hpd-typec-dp-bridge module
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Dependency inversion unconditionally loads USB Type-C subsystem on all DP-capable systems --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Dependency inversion unconditionally loads USB Type-C subsystem on all DP-capable systems --
commit 18e75df5599eb3c3479dc1002547dcf5f6a1593b
Author: Chaoyi Chen <[email protected]>
drm/display: Add soft depend for aux-hpd-typec-dp-bridge module
This commit adds a soft dependency in the drm_display_helper module for the aux-hpd-typec-dp-bridge module. This ensures the bridge module is loaded early, as it serves as a generic Type-C DisplayPort HPD bridge that isn't directly required by any other module.
drivers/gpu/drm/display/drm_display_helper_mod.c static void __exit drm_display_helper_module_exit(void) · line 21
Quoted 9 lines
drivers/gpu/drm/display/drm_display_helper_mod.c +1
-0@@ -18,5 +18,6 @@ static void __exit drm_display_helper_module_exit(void)drm_dp_aux_dev_exit (); } +MODULE_SOFTDEP ("pre: aux-hpd-typec-dp-bridge" );
[Severity: Medium]
Does adding a soft dependency on aux-hpd-typec-dp-bridge to the core drm_display_helper module create an architectural dependency inversion?
The leaf bridge driver (aux-hpd-typec-dp-bridge) has a hard dependency on the typec core subsystem because it registers a bus notifier on typec_bus. As a result, when a system loads a DRM driver that utilizes generic display helpers (such as amdgpu, i915, or nouveau), won't this unconditionally pull the entire USB Type-C subsystem into memory?
This seems like it might waste memory resources on systems without Type-C hardware by automatically loading aux-hpd-typec-dp-bridge.ko (and consequently typec.ko) upon loading any standard DRM driver. Is there a better way to handle this without burdening all generic display helper users?
Quoted 2 lines
drivers/gpu/drm/display/drm_display_helper_mod.c +0
-0module_init (drm_display_helper_module_init);module_exit (drm_display_helper_module_exit);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v7 4/7 drm/bridge: aux: Add drm_aux_bridge_register_from_node()
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
The drm_aux_bridge_register() uses the device->of_node as the bridge->of_node.
This patch adds drm_aux_bridge_register_from_node() to allow specifying the of_node corresponding to the bridge.
---
(no changes since v3)
Changes in v2:
- Fix incorrect function names in the documentation comments.
--- drivers/gpu/drm/bridge/aux-bridge.c | 26 +++++++++++++++++++++++--- include/drm/bridge/aux-bridge.h | 6 ++++++ 2 files changed, 29 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/aux-bridge.c +23 -3
@@ -33,8 +33,9 @@ static void drm_aux_bridge_unregister_adev(void *_adev) }/** -* drm_aux_bridge_register - Create a simple bridge device to link the chain +* drm_aux_bridge_register_from_node - Create a simple bridge device to link the chain * @parent: device instance providing this bridge +* @np: device node pointer corresponding to this bridge instance * * Creates a simple DRM bridge that doesn't implement any drm_bridge * operations. Such bridges merely fill a place in the bridge chain linking
@@ -42,7 +43,7 @@ static void drm_aux_bridge_unregister_adev(void *_adev)* * Return: zero on success, negative error code on failure */ -int drm_aux_bridge_register (struct device *parent) +int drm_aux_bridge_register_from_node (struct device *parent,struct device_node *np) {struct auxiliary_device *adev;int ret;
@@ -62,7 +63,10 @@ int drm_aux_bridge_register(struct device *parent) adev->dev.parent = parent; adev->dev.release = drm_aux_bridge_release; -device_set_of_node_from_dev (&adev->dev, parent); +if (np) +device_set_node (&adev->dev,of_fwnode_handle (np)); +else +device_set_of_node_from_dev (&adev->dev, parent); ret =auxiliary_device_init (adev);if (ret) {
@@ -80,6 +84,22 @@ int drm_aux_bridge_register(struct device *parent)return devm_add_action_or_reset (parent, drm_aux_bridge_unregister_adev, adev); } +EXPORT_SYMBOL_GPL (drm_aux_bridge_register_from_node); + +/** +* drm_aux_bridge_register - Create a simple bridge device to link the chain +* @parent: device instance providing this bridge +* +* Creates a simple DRM bridge that doesn't implement any drm_bridge +* operations. Such bridges merely fill a place in the bridge chain linking +* surrounding DRM bridges. +* +* Return: zero on success, negative error code on failure +*/ +int drm_aux_bridge_register (struct device *parent) +{ +return drm_aux_bridge_register_from_node (parent,NULL ); +}EXPORT_SYMBOL_GPL (drm_aux_bridge_register);struct drm_aux_bridge_data {
include/drm/bridge/aux-bridge.h +6 -0
@@ -13,11 +13,17 @@ struct auxiliary_device;#if IS_ENABLED (CONFIG_DRM_AUX_BRIDGE )int drm_aux_bridge_register (struct device *parent); +int drm_aux_bridge_register_from_node (struct device *parent,struct device_node *np);#else static inline int drm_aux_bridge_register (struct device *parent) {return 0 ; } + +static inline int drm_aux_bridge_register_from_node (struct device *parent,struct device_node *np) +{ +return 0 ; +}#endif #if IS_ENABLED (CONFIG_DRM_AUX_HPD_BRIDGE )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 4/7] drm/bridge: aux: Add drm_aux_bridge_register_from_node()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing OF node reference acquisition for explicitly provided device_node `np`, leading to a…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing OF node reference acquisition for explicitly provided device_node np, leading to a reference count underflow when the device is destroyed or initialization fails. --
commit e57ae2f012dd4cdc820d51259b2a37d588d5c31d
Author: Chaoyi Chen <[email protected]>
drm/bridge: aux: Add drm_aux_bridge_register_from_node()
This commit adds a new function, drm_aux_bridge_register_from_node(), which allows specifying the of_node corresponding to the bridge when creating a simple DRM bridge device.
Quoted 4 lines
drivers/gpu/drm/bridge/aux-bridge.c +0
-0
[ ... ]
drivers/gpu/drm/bridge/aux-bridge.c int drm_aux_bridge_register(struct device *parent) · line 67
Quoted 7 lines
drivers/gpu/drm/bridge/aux-bridge.c +2
-1@@ -62,7 +63,10 @@ int drm_aux_bridge_register(struct device *parent) adev->dev.parent = parent; adev->dev.release = drm_aux_bridge_release; -device_set_of_node_from_dev (&adev->dev, parent); +if (np) +device_set_node (&adev->dev,of_fwnode_handle (np));
[Severity: High]
Does this miss a reference increment for the device node?
Looking at drivers/base/core.c, device_set_node() simply assigns the pointer without taking a reference, whereas device_set_of_node_from_dev() internally calls of_node_get(dev2->of_node).
Quoted 6 lines
drivers/gpu/drm/bridge/aux-bridge.c +2
-0+else +device_set_of_node_from_dev (&adev->dev, parent); ret =auxiliary_device_init (adev);if (ret) {of_node_put(adev->dev.of_node);
[Severity: High]
If np was provided and auxiliary_device_init() fails, won't this drop a reference that was never acquired?
The same reference count underflow appears to happen during normal teardown in drm_aux_bridge_release(), which will also unconditionally call of_node_put() on a node that didn't have its reference count incremented here. Should an explicit of_node_get(np) be used before assigning it?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v7 5/7 phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
Using the DRM_AUX_BRIDGE helper to create the transparent DRM bridge device.
---
(no changes since v1)
--- drivers/phy/rockchip/Kconfig | 2 ++ drivers/phy/rockchip/phy-rockchip-typec.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/phy/rockchip/Kconfig +2 -0
@@ -119,6 +119,8 @@ config PHY_ROCKCHIP_SNPS_PCIE3 config PHY_ROCKCHIP_TYPEC tristate "Rockchip TYPEC PHY Driver" depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST) + depends on DRM || DRM=n + select DRM_AUX_BRIDGE if DRM_BRIDGE select EXTCON select GENERIC_PHY select RESET_CONTROLLER
drivers/phy/rockchip/phy-rockchip-typec.c +11 -2
@@ -54,6 +54,7 @@#include <linux/mfd/syscon.h> #include <linux/phy/phy.h> +#include <drm/bridge/aux-bridge.h> #define CMN_SSM_BANDGAP (0x21 << 2)#define CMN_SSM_BIAS (0x22 << 2)
@@ -1162,16 +1163,24 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)for_each_available_child_of_node (np, child_np) {struct phy *phy; + ret =0 ; -if (of_node_name_eq (child_np,"dp-port" )) +if (of_node_name_eq (child_np,"dp-port" )) { phy =devm_phy_create (dev, child_np, &rockchip_dp_phy_ops); -else if (of_node_name_eq (child_np,"usb3-port" )) + ret =drm_aux_bridge_register_from_node (dev, child_np); + }else if (of_node_name_eq (child_np,"usb3-port" )) phy =devm_phy_create (dev, child_np, &rockchip_usb3_phy_ops);else continue ; +if (ret) { +pm_runtime_disable (dev); +of_node_put (child_np); +return ret; + } +if (IS_ERR (phy)) {dev_err (dev,"failed to create phy: %pOFn\n" , child_np);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 5/7] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Double-free and Use-After-Free of OF Node Reference - [Medium] Initialization Ordering and Error…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double-free and Use-After-Free of OF Node Reference
- [Medium] Initialization Ordering and Error Masking
--
commit 0733fab98743300c9bca39a083f1a901d4ff8cda
Author: Chaoyi Chen <[email protected]>
phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge
Using the DRM_AUX_BRIDGE helper to create the transparent DRM bridge device.
Quoted 4 lines
drivers/phy/rockchip/phy-rockchip-typec.c +0
-0
[ ... ]
drivers/phy/rockchip/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 1171
Quoted 12 lines
drivers/phy/rockchip/phy-rockchip-typec.c +3
-2@@ -1162,16 +1163,24 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)for_each_available_child_of_node (np, child_np) {struct phy *phy; + ret =0 ; -if (of_node_name_eq (child_np,"dp-port" )) +if (of_node_name_eq (child_np,"dp-port" )) { phy =devm_phy_create (dev, child_np, &rockchip_dp_phy_ops); -else if (of_node_name_eq (child_np,"usb3-port" )) + ret =drm_aux_bridge_register_from_node (dev, child_np);
[Severity: High]
Does this code cause a double-free of the OF node reference?
Since child_np is the loop iterator in for_each_available_child_of_node(), its reference is automatically dropped when advancing to the next iteration. However, drm_aux_bridge_register_from_node() assigns the OF node to the auxiliary device without incrementing the reference count, and drops a reference in its error paths and release function.
Will this lead to a use-after-free when the loop iterator automatically drops the reference, leaving the registered bridge pointing to a freed device node?
[Severity: Medium]
Also, does this sequence mask errors from devm_phy_create()?
The result of devm_phy_create() is not checked before calling drm_aux_bridge_register_from_node(). If devm_phy_create() returns an error pointer (such as -EPROBE_DEFER) and drm_aux_bridge_register_from_node() fails, the original error will be permanently lost when returning 'ret' below.
Additionally, if devm_phy_create() fails but bridge registration succeeds, an auxiliary device is registered only to be immediately unregistered via devres when returning PTR_ERR(phy) shortly after. Could this be avoided by checking IS_ERR(phy) before registering the bridge?
drivers/phy/rockchip/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 1180
Quoted 9 lines
drivers/phy/rockchip/phy-rockchip-typec.c +4
-0+ }else if (of_node_name_eq (child_np,"usb3-port" )) phy =devm_phy_create (dev, child_np, &rockchip_usb3_phy_ops);else continue ; +if (ret) { +pm_runtime_disable (dev); +of_node_put (child_np);
[Severity: High]
Since drm_aux_bridge_register_from_node() already dropped the OF node reference on its internal failure path, will calling of_node_put() here cause an immediate double-free?
Quoted 6 lines
drivers/phy/rockchip/phy-rockchip-typec.c +3
-0+return ret; + } +if (IS_ERR (phy)) {dev_err (dev,"failed to create phy: %pOFn\n" , child_np);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v7 6/7 drm/rockchip: cdn-dp: Support handle lane info without extcon
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
This patch add support for get PHY lane info without help of extcon.
There is no extcon needed if the Type-C controller is present. In this case, the lane info can be get from PHY instead of extcon.
The extcon device should still be supported if Type-C controller is not present.
---
(no changes since v1)
--- drivers/gpu/drm/rockchip/cdn-dp-core.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/gpu/drm/rockchip/cdn-dp-core.c +17 -8
@@ -157,6 +157,9 @@ static int cdn_dp_get_port_lanes(struct cdn_dp_port *port)int dptx;u8 lanes; +if (!edev) +return phy_get_bus_width (port->phy); + dptx =extcon_get_state (edev,EXTCON_DISP_DP );if (dptx >0 ) { extcon_get_property(edev, EXTCON_DISP_DP,
@@ -220,7 +223,7 @@ static bool cdn_dp_check_sink_connection(struct cdn_dp_device *dp)* some docks need more time to power up. */ while (time_before (jiffies, timeout)) { -if (!extcon_get_state (port->extcon,EXTCON_DISP_DP )) +if (port->extcon && !extcon_get_state (port->extcon,EXTCON_DISP_DP ))return false;if (!cdn_dp_get_sink_count (dp, &sink_count))
@@ -386,11 +389,14 @@ static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port) goto err_power_on; } - ret =extcon_get_property (port->extcon,EXTCON_DISP_DP , -EXTCON_PROP_USB_TYPEC_POLARITY , &property); -if (ret) { -DRM_DEV_ERROR (dp->dev,"get property failed\n" ); - goto err_power_on; + property.intval =0 ; +if (port->extcon) { + ret =extcon_get_property (port->extcon,EXTCON_DISP_DP , +EXTCON_PROP_USB_TYPEC_POLARITY , &property); +if (ret) { +DRM_DEV_ERROR (dp->dev,"get property failed\n" ); + goto err_power_on; + } } port->lanes =cdn_dp_get_port_lanes (port);
@@ -1027,6 +1033,9 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)for (i =0 ; i < dp->ports; i++) { port = dp->port[i]; +if (!port->extcon) +continue ; + port->event_nb.notifier_call = cdn_dp_pd_event; ret = devm_extcon_register_notifier(dp->dev, port->extcon, EXTCON_DISP_DP,
@@ -1119,14 +1128,14 @@ static int cdn_dp_probe(struct platform_device *pdev) PTR_ERR(phy) == -EPROBE_DEFER)return -EPROBE_DEFER ; -if (IS_ERR (extcon) ||IS_ERR (phy)) +if (IS_ERR (phy) ||PTR_ERR (extcon) != -ENODEV )continue ; port =devm_kzalloc (dev,sizeof (*port),GFP_KERNEL );if (!port)return -ENOMEM ; - port->extcon = extcon; + port->extcon =IS_ERR (extcon) ?NULL : extcon; port->phy = phy; port->dp = dp; port->id = i;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 6/7] drm/rockchip: cdn-dp: Support handle lane info without extcon
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Critical] The condition PTR_ERR(extcon) != -ENODEV incorrectly skips valid extcon pointers during probe, breaking backward compatibility for all existing devices with an extcon.
Pre-existing issues:
- [High] Extcon notifier registered using devres in component bind is not unregistered in component unbind, leading to Use-After-Free of released firmware.
- [High] Using devm_drm_bridge_add in component bind causes duplicate bridge registrations and devres corruption upon re-bind.
--
commit 30782eee380f850a10d083003cae3953c1e3c8d7
Author: Chaoyi Chen <[email protected]>
drm/rockchip: cdn-dp: Support handle lane info without extcon
This commit adds support for retrieving PHY lane information without relying on extcon. This is useful for setups where a Type-C controller is present and lane info can be acquired directly from the PHY.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0
[ ... ]
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1041
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3
-0@@ -1027,6 +1033,9 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)for (i =0 ; i < dp->ports; i++) { port = dp->port[i]; +if (!port->extcon) +continue ; + port->event_nb.notifier_call = cdn_dp_pd_event; ret = devm_extcon_register_notifier(dp->dev, port->extcon, EXTCON_DISP_DP,
[Severity: High]
This is a pre-existing issue, but does using devres for the notifier here cause a use-after-free upon component unbind?
Because devm_extcon_register_notifier() is tied to the platform device's remove lifecycle rather than component unbind, the notifier remains active after cdn_dp_unbind() completes. Since cdn_dp_unbind() frees the firmware via release_firmware(), a subsequent extcon state change could trigger the still-active notifier callback.
Could this lead to cdn_dp_pd_event_work() calling cdn_dp_firmware_init(), which then dereferences the freed firmware data?
[ ... ]
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_probe(struct platform_device *pdev) · line 1132
Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1
-1@@ -1119,14 +1128,14 @@ static int cdn_dp_probe(struct platform_device *pdev) PTR_ERR(phy) == -EPROBE_DEFER)return -EPROBE_DEFER ; -if (IS_ERR (extcon) ||IS_ERR (phy)) +if (IS_ERR (phy) ||PTR_ERR (extcon) != -ENODEV )continue ;
[Severity: Critical]
Does this condition inadvertently skip valid extcon pointers during probe?
When extcon_get_edev_by_phandle() returns a valid kernel pointer, PTR_ERR(extcon) casts that valid address to a long. Since a valid pointer will never equal -ENODEV, the condition PTR_ERR(extcon) != -ENODEV will evaluate to true.
Will this completely disable port allocation for existing setups with a valid extcon, resulting in a loss of display output?
[ ... ]
This is a pre-existing issue, but I also noticed a potential problem in cdn_bridge_add():
drivers/gpu/drm/rockchip/cdn-dp-core.c:cdn_bridge_add() {
...
ret = devm_drm_bridge_add(dev, bridge);
if (ret)
return ret;
...
}[Severity: High]
Does using devm_drm_bridge_add() in a component bind hook cause duplicate bridge registrations?
Because devres actions only execute on full driver remove, unbinding and rebinding the DRM component via sysfs appears to queue duplicate devres cleanup actions. This adds the exact same bridge structure to the global bridge_list repeatedly.
Could this corrupt the bridge list and lead to a double-free on removal?
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
PATCH v7 7/7 drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
The RK3399 has two USB/DP combo PHY and one CDN-DP controller. And the CDN-DP can be switched to output to one of the PHYs. If both ports are plugged into DP, DP will select the first port for output.
This patch adds support for multiple bridges, enabling users to flexibly select the output port. For each PHY port, a separate encoder and bridge are registered.
The change is based on the DRM AUX HPD bridge, rather than the extcon approach. This requires the DT to correctly describe the connections between the first bridge in bridge chain and DP controller. For example, the bridge chain may be like this:
PHY aux birdge -> fsa4480 analog audio switch bridge -> onnn,nb7vpq904m USB reminder bridge -> USB-C controller AUX HPD bridge
In this case, the connection relationships among the PHY aux bridge and the DP contorller need to be described in DT.
In addition, the cdn_dp_parse_next_bridge_dt() will parses it and determines whether to register one or two bridges.
Since there is only one DP controller, only one of the PHY ports can output at a time. The key is how to switch between different PHYs, which is handled by cdn_dp_switch_port() and cdn_dp_enable().
There are two cases:
1. Neither bridge is enabled. In this case, both bridges can independently read the EDID, and the PHY port may switch before reading the EDID.
2. One bridge is already enabled. In this case, other bridges are not allowed to read the EDID. So we will try to return the cached EDID.
Since the scenario of two ports plug in at the same time is rare, I don't have a board which support two TypeC connector to test this. Therefore, I tested forced switching on a single PHY port, as well as output using a fake PHY port alongside a real PHY port.
---
Changes in v7:
- Fix extcon HPD detection by checking lanes in cdn_dp_connected_port() (sashiko).
- Bound endpoint count by PHY ports to avoid overflow and uninitialized reads (sashiko).
- Use drm_bridge_clear_and_put() to clear next_bridge_list pointers (sashiko).
- Clear EDID cache pointers after free in unbind() (sashiko).
(no changes since v4)
Changes in v3:
- Remove now-redundant call to drm_connector_attach_encoder().
Changes in v2:
- Fix the check logic for dp->active_port (0 is valid).
- Fix the uninitialized prev_port.
- Remove duplicate logic from cdn_dp_switch_port().
- Fix the prototype of cdn_dp_bridge_hpd_notify().
- Properly release connector->fwnode.
- Properly release next_bridge.
--- drivers/gpu/drm/rockchip/Kconfig | 1 + drivers/gpu/drm/rockchip/cdn-dp-core.c | 340 +++++++++++++++++++++---- drivers/gpu/drm/rockchip/cdn-dp-core.h | 18 +- 3 files changed, 301 insertions(+), 58 deletions(-)
drivers/gpu/drm/rockchip/Kconfig +1 -0
@@ -60,6 +60,7 @@ config ROCKCHIP_CDN_DP select DRM_DISPLAY_HELPER select DRM_BRIDGE_CONNECTOR select DRM_DISPLAY_DP_HELPER + select DRM_AUX_HPD_BRIDGE help This selects support for Rockchip SoC specific extensions for the cdn DP driver. If you want to enable Dp on
drivers/gpu/drm/rockchip/cdn-dp-core.c +284 -56
498 lines not on this page · raw message
drivers/gpu/drm/rockchip/cdn-dp-core.h +16 -2
@@ -38,6 +38,8 @@ enum vic_pxl_encoding_format { Y_ONLY = 0x10, }; +struct cdn_dp_device ; +struct video_info {bool h_sync_polarity;bool v_sync_polarity;
@@ -63,16 +65,28 @@ struct cdn_dp_port {u8 id; }; +struct cdn_dp_bridge { +struct cdn_dp_device *parent; +struct drm_bridge bridge; +struct rockchip_encoder encoder; +bool connected; +bool enabled; +int id; +}; +struct cdn_dp_device {struct device *dev;struct drm_device *drm_dev; -struct drm_bridge bridge; -struct rockchip_encoder encoder; +int bridge_count; +struct cdn_dp_bridge *bridge_list[MAX_PHY ]; +struct drm_bridge *next_bridge_list[MAX_PHY ]; +const struct drm_edid *edid_cache[MAX_PHY ];struct drm_display_mode mode;struct platform_device *audio_pdev;struct work_struct event_work;struct mutex lock; +bool next_bridge_valid;bool connected;bool active;bool suspended;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 7/7] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Missing atomic_check to prevent concurrent enablement of mutually exclusive DP bridges. - [High]…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Missing atomic_check to prevent concurrent enablement of mutually exclusive DP bridges.
- [High] Hardware registers are accessed while DP clocks are disabled, leading to a synchronous external abort and kernel panic.
- [High] The driver fails to propagate internal hotplug state changes to userspace because its bridge no longer receives the HPD callback.
- [High] Video pipeline configuration is inappropriately executed during EDID read, leading to inevitable failure on secondary ports.
- [Medium] The connected status of bridges is updated and read concurrently without holding the necessary synchronization locks. --
commit a45588df990bb11f402ba98f56052bec1405db96
Author: Chaoyi Chen <[email protected]>
drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection
This commit adds support for multiple bridges to the Rockchip CDN-DP driver, allowing dynamic output port selection. It registers separate encoders and bridges for each PHY port and parses the device tree to describe connections. Port switching is handled dynamically during EDID reads or when enabling the DP block.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0
[ ... ]
Quoted 17 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10
-1@@ -254,12 +268,45 @@ static const struct drm_edid * cdn_dp_bridge_edid_read(struct drm_bridge *bridge, struct drm_connector *connector) { struct cdn_dp_device *dp = bridge_to_dp(bridge); -const struct drm_edid *drm_edid; +struct cdn_dp_bridge *dp_bridge =bridge_to_dp_bridge (bridge); +struct cdn_dp_port *port = dp->port[dp_bridge->id]; +struct cdn_dp_port *prev_port =NULL ; +const struct drm_edid *drm_edid =NULL ; +int i, ret;mutex_lock (&dp->lock); + +/* More than one port is available */ +if (dp->bridge_count >1 && !port->phy_enabled) { +for (i =0 ; i < dp->bridge_count; i++) { +/* Another port already enable */
drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 292
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10
-0+if (dp->bridge_list[i] != dp_bridge && dp->bridge_list[i]->enabled) + goto get_cache; +/* Find already enabled port */ +if (dp->port[i]->phy_enabled) + prev_port = dp->port[i]; + } + +/* Switch to current port */ +if (prev_port) { + ret =cdn_dp_switch_port (dp, prev_port, port);
[Severity: High]
Will this video pipeline configuration fail during an EDID read?
When reading the EDID on a secondary port, this switches the port and ultimately calls cdn_dp_config_video() via cdn_dp_switch_port(). Since this happens during connector probing, no atomic mode has been committed yet, meaning dp->mode.clock is either 0 or holds a stale value.
This will cause the timing calculation in cdn_dp_config_video() to return -EINVAL. The switch then fails, and this function falls back to returning the cache (which is NULL on the first plug), breaking secondary port detection.
drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 298
Quoted 6 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5
-0+if (ret) + goto get_cache; + } + } + drm_edid =drm_edid_read_custom (connector, cdn_dp_get_edid_block, dp);
[Severity: High]
Is there a risk of a synchronous external abort when accessing the DP hardware registers here?
Hotplug events from downstream bridges trigger cdn_dp_bridge_hpd_notify(), which schedules dp->event_work to enable the DP clocks and hardware via cdn_dp_enable(). At the same time, the DRM core processes the hotplug event and schedules output_poll_work, which initiates an EDID read here.
If the EDID read happens before the worker thread has enabled the clocks, it will bypass the port switch logic (since prev_port is NULL) and directly access the APB registers (like MAILBOX_EMPTY_ADDR) inside cdn_dp_get_edid_block(). Accessing these registers while pclk and core_clk are disabled causes a kernel panic.
Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +6
-0+/* replace edid cache */ +if (dp->edid_cache[dp_bridge->id]) +drm_edid_free (dp->edid_cache[dp_bridge->id]); + dp->edid_cache[dp_bridge->id] =drm_edid_dup (drm_edid); +mutex_unlock (&dp->lock); +return drm_edid;
[ ... ]
Quoted 19 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-0@@ -572,6 +664,7 @@ static void cdn_dp_display_info_update(struct cdn_dp_device *dp,static void cdn_dp_bridge_atomic_enable (struct drm_bridge *bridge,struct drm_atomic_commit *state) {struct cdn_dp_device *dp =bridge_to_dp (bridge); +struct cdn_dp_bridge *dp_bridge =bridge_to_dp_bridge (bridge);struct drm_connector *connector;int ret, val;@@ -600,6 +693,9 @@ static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_atmutex_lock (&dp->lock); +if (dp->next_bridge_valid) + dp->active_port = dp_bridge->id; + ret =cdn_dp_enable (dp);if (ret) { DRM_DEV_ERROR(dp->dev, "Failed to enable bridge %d\n",
drivers/gpu/drm/rockchip/cdn-dp-core.c static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at · line 731
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1
-0@@ -632,6 +728,7 @@ static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at goto out; } + dp_bridge->enabled = true;
[Severity: High]
What prevents userspace from enabling multiple CRTCs simultaneously on this single DP hardware block?
The driver registers multiple independent DRM bridges and encoders that share a single DP controller. Without a custom atomic_check to enforce mutual exclusion, the DRM core allows userspace to assign and enable multiple CRTCs to these encoders.
If multiple bridges are enabled concurrently, cdn_dp_bridge_atomic_enable() is called for both. The second call will see dp->active == true, skip the PHY enablement, and then proceed to call cdn_dp_train_link() and cdn_dp_config_video() here, which overrides the shared hardware registers and corrupts the active display.
Quoted 3 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0out:mutex_unlock (&dp->lock); }
[ ... ]
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0@@ -828,6 +927,17 @@ static int cdn_dp_audio_mute_stream(struct drm_bridge *bridge,return ret; }
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_audio_mute_stream(struct drm_bridge *bridge, · line 939
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10
-0+static void cdn_dp_bridge_hpd_notify (struct drm_bridge *bridge, +struct drm_connector *connector, +enum drm_connector_status status) +{ +struct cdn_dp_bridge *dp_bridge =bridge_to_dp_bridge (bridge); +struct cdn_dp_device *dp =bridge_to_dp (bridge); + + dp->bridge_list[dp_bridge->id]->connected = status == connector_status_connected; +schedule_work (&dp->event_work); +}
[Severity: Medium]
Is it safe to modify this connected state without acquiring dp->lock?
The boolean state dp->bridge_list[dp_bridge->id]->connected is written here directly, but cdn_dp_pd_event_work() reads this exact flag immediately after explicitly dropping dp->lock. This data race could cause the worker to process stale state if a concurrent HPD notification occurs.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1
-0+static const struct drm_bridge_funcs cdn_dp_bridge_funcs = { .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
[ ... ]
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0@@ -945,9 +1057,12 @@ static void cdn_dp_pd_event_work(struct work_struct *work) out:mutex_unlock (&dp->lock);
drivers/gpu/drm/rockchip/cdn-dp-core.c static void cdn_dp_pd_event_work(struct work_struct *work) · line 1066
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +6
-3-drm_bridge_hpd_notify (&dp->bridge, - dp->connected ? connector_status_connected - : connector_status_disconnected); +for (i =0 ; i < dp->bridge_count; i++) { + connected = dp->connected && dp->bridge_list[i]->connected; +drm_bridge_hpd_notify (&dp->bridge_list[i]->bridge, + connected ? connector_status_connected + : connector_status_disconnected); + } }
[Severity: High]
Will this HPD notification actually reach userspace?
The DRM bridge connector (drm_bridge_connector_init) only registers the hpd_cb on the last bridge in the chain that supports DRM_BRIDGE_OP_HPD. Because the downstream AUX HPD bridge supports HPD and is added to the chain, it becomes the designated HPD bridge and takes the hpd_cb.
As a result, this bridge's hpd_cb is never set, making this call to drm_bridge_hpd_notify() a silent no-op. If link training fails, userspace is never notified that the connection has dropped, permanently breaking the display state machine.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7