This series is split from the v15 "Add Type-C DP support for RK3399 EVB
Subsystems (6)
v4 cover This series is split from the v15 "Add Type-C DP support for RK3399 EVB
From: Chaoyi Chen <[email protected]>
[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 generic USB Type-C DP HPD bridge (Dmitry, Heikki). Patch 2 adds new API drm_aux_bridge_register_from_node() (Neil). Patch 3 adds DRM AUX bridge support for RK3399 USBDP PHY (Neil). Patch 4 drops CDN-DP's extcon dependency when Type-C is present (Dmitry). Patch 5 adds multiple bridges to support PHY port selection (Dmitry, Luca).
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 (5):
drm/bridge: Implement generic USB Type-C DP HPD bridge 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 +- .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c | 64 ++++ drivers/gpu/drm/rockchip/Kconfig | 1 + drivers/gpu/drm/rockchip/cdn-dp-core.c | 358 ++++++++++++++---- 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 | 6 + 10 files changed, 428 insertions(+), 71 deletions(-) create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
Signature · 1 line
2.53.0
PATCH v4 1/5 drm/bridge: Implement generic USB Type-C DP HPD bridge
From: 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.
---
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 | 64 +++++++++++++++++++ 3 files changed, 75 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 +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 2/5 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
PATCH v4 3/5 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
PATCH v4 4/5 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
PATCH v4 5/5 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.
---
(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 | 333 ++++++++++++++++++++----- drivers/gpu/drm/rockchip/cdn-dp-core.h | 18 +- 3 files changed, 294 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 +277 -56
491 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 v4 2/5] drm/bridge: aux: Add drm_aux_bridge_register_from_node()
In reply to Chaoyi ChenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing of_node_get() when setting the device node from `np` in…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing of_node_get() when setting the device node from np in drm_aux_bridge_register_from_node() leads to a reference count underflow, as cleanup and release paths unconditionally drop the reference. --
--- Patch [2]: [PATCH v4 2/5] drm/bridge: aux: Add drm_aux_bridge_register_from_node() --- commit d7b1eb76e37cb91bfdbe4b86349165417e109776
Author: Chaoyi Chen <[email protected]>
drm/bridge: aux: Add drm_aux_bridge_register_from_node()
This commit introduces drm_aux_bridge_register_from_node() to allow specifying the of_node corresponding to the bridge when registering an auxiliary 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 68
Quoted 7 lines
drivers/gpu/drm/bridge/aux-bridge.c +2
-1@@ -63,7 +64,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]
When np is provided, device_set_node() is used. Unlike device_set_of_node_from_dev(), device_set_node() does not appear to increment the reference count of the target node.
drivers/gpu/drm/bridge/aux-bridge.c int drm_aux_bridge_register(struct device *parent) · line 72
Quoted 5 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) {
Could this lead to a reference count underflow for the provided np?
The error path here unconditionally calls of_node_put(adev->dev.of_node). Additionally, the drm_aux_bridge_release() callback also unconditionally drops a reference to the device's of_node when the device is destroyed.
Since device_set_node() doesn't take an initial reference on np, will these put operations result in a use-after-free for the device tree node?
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
[email protected]
AI reviewRe: [PATCH v4 4/5] drm/rockchip: cdn-dp: Support handle lane info without extcon
In reply to Chaoyi ChenThank 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:
- [High] The error-handling condition PTR_ERR(extcon) != -ENODEV incorrectly evaluates to true for all valid extcon pointers, completely skipping port initialization for platforms with an extcon.
Pre-existing issues:
- [High] The driver incorrectly uses devm_ APIs inside a component bind function, leading to lingering notifiers and use-after-free upon component unbind.
- [High] cdn_dp_pd_event_work drops and reacquires a lock during execution but fails to re-evaluate the hardware's suspend state, potentially accessing powered-down hardware. --
--- Patch [4]: [PATCH v4 4/5] drm/rockchip: cdn-dp: Support handle lane info without extcon --- commit 7d9954b4a176d603a3c1df5fb3c1b4c9ddaa5b21
Author: Chaoyi Chen <[email protected]>
drm/rockchip: cdn-dp: Support handle lane info without extcon
This patch adds support for getting PHY lane info without the help of extcon. If a Type-C controller is present, the lane info can be obtained from the PHY instead of extcon. The extcon device is still supported if the Type-C controller is not present.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0
[ ... ]
Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3
-0@@ -1030,6 +1036,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,
&port->event_nb);
[Severity: High]
This isn't a bug introduced by this patch, but does using devm_ APIs in a component bind function lead to lingering notifiers?
When the DRM master is unbound, cdn_dp_unbind() is called. However, resources allocated with devm_ (like this extcon notifier and the DRM bridge) are tied to the platform device's lifetime, not the component.
If a user unbinds the DRM master device via sysfs, and then plugs or unplugs the DisplayPort cable, could the active notifier fire and schedule the driver's workqueue on destroyed state, causing a use-after-free?
[ ... ]
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_probe(struct platform_device *pdev) · line 1134
Quoted 6 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1
-1@@ -1122,14 +1131,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 )
[Severity: High]
Does this error-handling condition evaluate to true for all valid extcon pointers?
When the driver probes on a platform with an extcon, extcon_get_edev_by_phandle() returns a valid pointer. This condition then checks if the valid pointer's address is not equal to -ENODEV, which is always true.
Could this skip port initialization for all valid extcon devices, leaving dp->ports = 0 and causing the driver to unconditionally fail with -EINVAL?
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_probe(struct platform_device *pdev) · line 1134
Quoted 3 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0continue ; port =devm_kzalloc (dev,sizeof (*port),GFP_KERNEL );
[Severity: High]
This is a pre-existing issue, but is there a race condition between the workqueue and system suspend?
In cdn_dp_pd_event_work(), dp->lock is held and dp->suspended is verified. Then, cdn_dp_request_firmware() is called:
drivers/gpu/drm/rockchip/cdn-dp-core.c:cdn_dp_request_firmware() {
...
/* Drop the lock before getting the firmware to avoid blocking boot */
mutex_unlock(&dp->lock);
...
}During this window, if the system suspends, cdn_dp_suspend() acquires dp->lock, sets dp->suspended = true, and powers off the hardware. When cdn_dp_request_firmware() finishes, it reacquires the lock and returns to cdn_dp_pd_event_work().
Execution then resumes without rechecking if the system suspended in the meantime:
drivers/gpu/drm/rockchip/cdn-dp-core.c:cdn_dp_pd_event_work() {
...
ret = cdn_dp_request_firmware(dp);
if (ret)
goto out;
dp->connected = true;
if (!cdn_dp_connected_port(dp)) {
...
} else if (!dp->active) {
...
ret = cdn_dp_enable(dp);
...
}Could this cause the worker thread to call cdn_dp_enable() and access hardware registers that have been powered down?
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
[email protected]
AI reviewRe: [PATCH v4 1/5] drm/bridge: Implement generic USB Type-C DP HPD bridge
In reply to Chaoyi ChenThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Module load/unload cycles and dynamic Type-C port removals leak devm-managed bridges, resulting in…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Module load/unload cycles and dynamic Type-C port removals leak devm-managed bridges, resulting in duplicates and potential UAF.
- [High] A race condition between bus notifier registration and bus iteration causes duplicate DP HPD bridge registrations.
- [High] Unconditional bridge registration creates duplicate bridges for controllers that already register their own HPD bridge. --
--- Patch [1]: [PATCH v4 1/5] drm/bridge: Implement generic USB Type-C DP HPD bridge --- commit 8ca96a8d5692c2b3ff148f7a6803323281488779
Author: Chaoyi Chen <[email protected]>
drm/bridge: Implement generic USB Type-C DP HPD bridge
This commit implements a generic DP HPD bridge based on aux-hpd-bridge.c. It monitors Type-C bus events and automatically creates an HPD bridge when a Type-C port device containing the DP svid is registered.
Quoted 5 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +0
-0
[ ... ]
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 20
Quoted 8 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +8
-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); + +if (action !=BUS_NOTIFY_ADD_DEVICE ) +return NOTIFY_OK ;
[Severity: High]
Does this code leak devm-managed bridges when a Type-C altmode device is dynamically removed?
It looks like BUS_NOTIFY_DEL_DEVICE is not handled here, so the bridge might linger and pin of_node references indefinitely after port removal.
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 28
Quoted 8 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +8
-0+ +/* +* 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 ) +drm_dp_hpd_bridge_register (alt->dev.parent->parent, +to_of_node (alt->dev.parent->fwnode));
[Severity: High]
What happens if the USB-C controller driver (like fusb302 or qcom_pmic_typec) has already explicitly registered its own HPD bridge?
Will this unconditional registration create a second duplicate bridge? If so, could this break of_drm_find_bridge() resolution, causing the display driver to miss hotplug events fired on the controller's own bridge?
Additionally, because drm_dp_hpd_bridge_register() ties the devm allocation to the external USB-C controller (alt->dev.parent->parent), will unloading this module leave those devres allocations behind? Reloading the module might then register duplicates.
Quoted 3 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +3
-0+ +return NOTIFY_OK ; +}
[ ... ]
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 55
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: High]
Is there a race condition between the notifier registration and the bus iteration here?
If a Type-C altmode device is added concurrently (for example, via an async probe of the controller) right after bus_register_notifier() but before or during the bus_for_each_dev() iteration, could it trigger both the notifier and the check_device_already_added callback?
Would this result in duplicate HPD bridges being registered for a single Type-C port?
Quoted 2 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +2
-0+return 0 ; +}
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
[email protected]
AI reviewRe: [PATCH v4 5/5] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection
In reply to Chaoyi ChenThank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
New issues:
- [High] cdn_dp_connected_port unconditionally returns the first port on legacy or extcon devices, breaking hotplug detection.
- [High] The driver erroneously skips valid extcon devices during probe due to a flawed error pointer check.
- [High] cdn_dp_switch_port performs full video configuration during an EDID read, breaking port switching and EDID detection.
- [High] Multiple encoders are registered without an atomic_check callback to enforce mutual exclusion, enabling hardware corruption.
- [High] Dangling pointers in dp->next_bridge_list cause a double-put Use-After-Free during component rebinds or deferred probes.
- [High] Dangling pointers in dp->edid_cache cause a double-free memory corruption during component rebinds.
- [High] Lack of bounds validation between DT endpoints (bridge_count) and probed PHYs (ports) leads to NULL pointer dereferences and uninitialized memory access.
- [High] cdn_dp_bridge_atomic_enable bypasses PHY switching if the CDN-DP controller is already active.
- [High] Failed PHY switching in cdn_dp_switch_port leaves the device in an inconsistent state.
- [Medium] Out-of-bounds write in cdn_dp_parse_next_bridge_dt when parsing device tree endpoints.
- [Medium] Data race on the connected flag of the bridges.
Pre-existing issues:
- [Critical] devm_ allocations inside the component bind callback cause resource leaks, duplicate registrations, and Use-After-Free vulnerabilities. --
--- Patch [5]: [PATCH v4 5/5] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection --- commit ae89dd4402c4e98ab965c5bd29f2eb19fa5d48bc
Author: Chaoyi Chen <[email protected]>
drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection
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.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0
[ ... ]
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0@@ -191,14 +192,27 @@ static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count)static struct cdn_dp_port *cdn_dp_connected_port (struct cdn_dp_device *dp) {struct cdn_dp_port *port;
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 201
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3
-3-int i, lanes; +int i, lanes[MAX_PHY ];for (i =0 ; i < dp->ports; i++) { port = dp->port[i]; - lanes =cdn_dp_get_port_lanes (port); -if (lanes) + lanes[i] =cdn_dp_get_port_lanes (port); +if (!dp->next_bridge_valid)return port;
[Severity: High]
What happens here for legacy or extcon devices where next_bridge_valid is false?
If !dp->next_bridge_valid evaluates to true, the loop immediately returns dp->port[0] on the very first iteration. This seems to completely ignore the physical connection state in lanes[i], always falsely reporting the port as connected, which could break DP hotplug detection entirely.
Quoted 3 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2
-0} + +if (dp->next_bridge_valid) {
[ ... ]
drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 271
Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2
-1@@ -253,12 +267,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];
[Severity: High]
Is it possible for a device tree to define more endpoints than probed PHYs?
There doesn't seem to be a bounds check ensuring dp->bridge_count is less than or equal to dp->ports. If a misconfiguration causes dp_bridge->id to index beyond dp->ports, dp->port[dp_bridge->id] would return NULL. This would cause a kernel panic when checking !port->phy_enabled below.
Quoted 14 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +12
-0+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 */ +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)
drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 296
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10
-0+ prev_port = dp->port[i]; + } + +/* Switch to current port */ +if (prev_port) { + ret =cdn_dp_switch_port (dp, prev_port, port); +if (ret) + goto get_cache; + } + }
[Severity: High]
Are we trying to perform full video configuration during an EDID read?
When switching the PHY, cdn_dp_switch_port internally calls cdn_dp_config_video(dp). However, during an EDID read operation, no display mode is committed yet, meaning mode->clock may be 0. Since cdn_dp_config_video uses mode->clock in a timing loop, this will fail.
This forces cdn_dp_switch_port to fail, resulting in a fallback to a stale or NULL EDID cache, completely breaking output detection on secondary ports.
drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 301
Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-0+ drm_edid =drm_edid_read_custom (connector, cdn_dp_get_edid_block, dp); +/* replace edid cache */ +if (dp->edid_cache[dp_bridge->id]) +drm_edid_free (dp->edid_cache[dp_bridge->id]);
[Severity: High]
Could this result in a double-free on a dangling pointer?
In cdn_dp_unbind(), the cached EDIDs are freed but the pointers in dp->edid_cache are not set to NULL. Since the dp context survives a component unbind/rebind cycle, if the component is rebound, this check will evaluate to true and attempt to free the dangling pointer again.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3
-0+ dp->edid_cache[dp_bridge->id] =drm_edid_dup (drm_edid); +mutex_unlock (&dp->lock); +return drm_edid;
[ ... ]
Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +7
-0@@ -550,6 +598,50 @@ static bool cdn_dp_check_link_status(struct cdn_dp_device *dp)return drm_dp_channel_eq_ok (link_status,min (port->lanes, sink_lanes)); } +static int cdn_dp_switch_port (struct cdn_dp_device *dp,struct cdn_dp_port *prev_port, +struct cdn_dp_port *port) +{ +int ret; + + ret =cdn_dp_disable_phy (dp, prev_port); +if (ret)
drivers/gpu/drm/rockchip/cdn-dp-core.c static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) · line 617
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10
-0+ goto out; + ret =cdn_dp_enable_phy (dp, port); +if (ret) + goto out; + + ret =cdn_dp_get_sink_capability (dp); +if (ret) { +cdn_dp_disable_phy (dp, port); + goto out; + }
[Severity: High]
Does this error path leave the driver in an inconsistent state?
If cdn_dp_get_sink_capability fails, the code disables both the previous and target PHYs and returns an error. However, it fails to update the controller's internal state machine, leaving dp->active as true.
Because dp->active is true but no PHY is actually enabled, any subsequent hardware operations will assume the hardware is active, potentially leading to bus errors or hardware timeouts.
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-0+ + dp->lanes = port->lanes; + +if (!cdn_dp_check_link_status (dp)) {
[ ... ]
drivers/gpu/drm/rockchip/cdn-dp-core.c static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at · line 698
Quoted 8 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3
-0@@ -599,6 +692,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);
[Severity: High]
Will cdn_dp_enable actually switch the PHY if one is already active?
The driver sets dp->active_port = dp_bridge->id and calls cdn_dp_enable(dp). However, cdn_dp_enable contains an early return if dp->active is already true.
If Port A is active and an atomic commit requests enabling Port B, cdn_dp_enable will return immediately without powering on Port B's PHY. Subsequent video configuration and link training commands will then be sent while the target PHY is powered off.
Quoted 2 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0if (ret) { DRM_DEV_ERROR(dp->dev, "Failed to enable bridge %d\n",
[ ... ]
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_audio_mute_stream(struct drm_bridge *bridge, · line 940
Quoted 12 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +8
-0@@ -831,6 +930,17 @@ static int cdn_dp_audio_mute_stream(struct drm_bridge *bridge,return ret; } +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;
[Severity: Medium]
Could this assignment cause a data race?
This writes to dp->bridge_list[dp_bridge->id]->connected without holding dp->lock. Concurrently, this flag is read by cdn_dp_pd_event_work inside a loop (after releasing dp->lock), and by cdn_dp_bridge_mode_valid without holding any locks. This unsynchronized access might lead to stale reads across cores.
drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_bridge_funcs cdn_dp_bridge_funcs = { · line 954
Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-0+schedule_work (&dp->event_work); +} +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,@@ -841,6 +951,7 @@ static const struct drm_bridge_funcs cdn_dp_bridge_funcs = { .atomic_disable = cdn_dp_bridge_atomic_disable, .mode_valid = cdn_dp_bridge_mode_valid, .mode_set = cdn_dp_bridge_mode_set, + .hpd_notify = cdn_dp_bridge_hpd_notify,
[Severity: High]
Should this bridge implement an atomic_check callback to enforce mutual exclusion?
The RK3399 CDN-DP controller can only drive one port at a time. By registering multiple encoders without an atomic_check to prevent both outputs from being enabled simultaneously, userspace could commit an atomic state that enables both.
This would cause concurrent calls to cdn_dp_bridge_atomic_enable, overwriting shared registers and leading to hardware corruption or kernel timeouts.
Quoted 3 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-0.dp_audio_prepare = cdn_dp_audio_prepare, .dp_audio_mute_stream = cdn_dp_audio_mute_stream,
[ ... ]
Quoted 33 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +29
-0@@ -1033,6 +1145,101 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)return ret; } +if (last_bridge) { +fwnode_handle_put (connector->fwnode); + connector->fwnode =fwnode_handle_get (of_fwnode_handle (last_bridge->of_node)); + } + +return 0 ; +} + +static int cdn_dp_parse_next_bridge_dt (struct cdn_dp_device *dp) +{ +struct device_node *np = dp->dev->of_node; + struct device_node *port __free(device_node) = of_graph_get_port_by_id(np, 1); +struct drm_bridge *bridge; +int count =0 ; +int ret =0 ; +int i; + +/* If device use extcon, do not use hpd bridge */ +for (i =0 ; i < dp->ports; i++) { +if (dp->port[i]->extcon) { + dp->bridge_count =1 ; +return 0 ; + } + } + +/* One endpoint may correspond to one next bridge. */ +for_each_of_graph_port_endpoint (port, dp_ep) { + struct device_node *next_bridge_node __free(device_node) = +of_graph_get_remote_port_parent (dp_ep);
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1186
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10
-0+ + bridge =of_drm_find_bridge (next_bridge_node); +if (!bridge) { + ret = -EPROBE_DEFER ; + goto out; + } + + dp->next_bridge_valid = true; + dp->next_bridge_list[count] =drm_bridge_get (bridge); + count++;
[Severity: Medium]
What prevents an out-of-bounds write here if there are more than 2 endpoints?
The dp->next_bridge_list array is statically sized to MAX_PHY (2). The loop blindly increments count and writes to the array without bounds checking. A misconfigured device tree could easily overflow this array.
Quoted 9 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +9
-0+ } + +out: + dp->bridge_count = count ? count :1 ; +return ret; +} + +static int cdn_dp_bind (struct device *dev,struct device *master,void *data) +{
[ ... ]
Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3
-0+ +INIT_WORK (&dp->event_work, cdn_dp_pd_event_work); +for (i =0 ; i < dp->ports; i++) { port = dp->port[i];
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1258
Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1
-1@@ -1046,7 +1253,7 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)if (ret) {DRM_DEV_ERROR (dev,"register EXTCON_DISP_DP notifier err\n" ); -return ret; + goto out; } }
[Severity: Critical]
This is a pre-existing issue, but won't these devm_ allocations cause memory leaks and Use-After-Free during component unbind?
The driver uses devm_drm_bridge_alloc, devm_drm_bridge_add, and devm_extcon_register_notifier inside cdn_dp_bind. These tie resources to the platform device (dp->dev), not the component lifecycle.
Upon unbind, these allocations aren't freed, leaking memory on every rebind. Critically, the extcon notifier is never unregistered. If an event fires after unbind, cdn_dp_pd_event_work is executed, discovering dp->fw_loaded == true and attempting to dereference dp->fw->data which was released in unbind, leading to a kernel panic.
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1268
Quoted 9 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-0@@ -1055,15 +1262,29 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)schedule_work (&dp->event_work);return 0 ; + +out: +for (i =0 ; i <MAX_PHY ; i++) +drm_bridge_put (dp->next_bridge_list[i]);
[Severity: High]
Does leaving these pointers in the array cause a Use-After-Free on rebind?
The array elements aren't set to NULL after calling drm_bridge_put(). Since dp persists across component bind/unbind cycles, a subsequent bind failure would iterate over this array and put the dangling pointers a second time, corrupting the bridge refcounts.
Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-1+ +return ret; }static void cdn_dp_unbind (struct device *dev,struct device *master,void *data) {struct cdn_dp_device *dp =dev_get_drvdata (dev); -struct drm_encoder *encoder = &dp->encoder.encoder; +struct drm_encoder *encoder; +int i;
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1284
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +8
-1cancel_work_sync (&dp->event_work); - encoder->funcs->destroy (encoder); +for (i =0 ; i < dp->bridge_count; i++) { + encoder = &dp->bridge_list[i]->encoder.encoder; + encoder->funcs->destroy (encoder); +drm_bridge_put (dp->next_bridge_list[i]); + } + +for (i =0 ; i <MAX_PHY ; i++) +drm_edid_free (dp->edid_cache[i]);
[Severity: High]
Same as above, should dp->edid_cache[i] and dp->next_bridge_list[i] be cleared to NULL after freeing?
These dangling pointers will cause double-frees during a subsequent bind cycle or EDID read if the component is rebound.
Quoted 8 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0
-1pm_runtime_disable (dev);if (dp->fw_loaded)@@ -1114,10 +1335,10 @@ static int cdn_dp_probe(struct platform_device *pdev)int ret;int i; - dp = devm_drm_bridge_alloc(dev, struct cdn_dp_device, bridge,
drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_probe(struct platform_device *pdev) · line 1344
Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4
-3- &cdn_dp_bridge_funcs); -if (IS_ERR (dp)) -return PTR_ERR (dp); + dp =devm_kzalloc (dev,sizeof (*dp),GFP_KERNEL ); +if (!dp) +return -ENOMEM ; + dp->dev = dev; match =of_match_node (cdn_dp_dt_ids, pdev->dev.of_node);
[Severity: High]
This isn't a bug introduced by this patch, but does the probe fail to recognize valid extcon devices?
Just below this in cdn_dp_probe, there is a check:
if (IS_ERR(phy) || PTR_ERR(extcon) != -ENODEV)
continue;If extcon_get_edev_by_phandle() successfully returns a valid pointer, its address is evaluated against -ENODEV, which is always true. This skips the valid extcon port and leaves dp->ports as 0, failing the probe with -EINVAL.
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
[email protected]
AI reviewRe: [PATCH v4 3/5] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge
In reply to Chaoyi ChenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing of_node_get() causes refcount underflow (double-put) and potential use-after-free of the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing of_node_get() causes refcount underflow (double-put) and potential use-after-free of the device node. --
--- Patch [3]: [PATCH v4 3/5] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge --- commit 01ab2260169a9897f73395bd29f9342205424c05
Author: Chaoyi Chen <[email protected]>
phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge
This commit uses the DRM_AUX_BRIDGE helper to create a transparent DRM bridge device for the display port on Rockchip Type-C PHYs.
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 need to call of_node_get(child_np) before passing it to drm_aux_bridge_register_from_node()?
The iterator macro for_each_available_child_of_node() holds a reference during the loop that it automatically drops when advancing. However, the auxiliary device created by drm_aux_bridge_register_from_node() will unconditionally call of_node_put() in its release function.
If we don't increment the reference count here, couldn't this result in a refcount underflow and use-after-free when the bridge is unregistered or destroyed?
Quoted 15 lines
drivers/phy/rockchip/phy-rockchip-typec.c +7
-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); +return ret; + } +if (IS_ERR (phy)) {dev_err (dev,"failed to create phy: %pOFn\n" , child_np);
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Hello Chaoyi,
Quoted 29 lines · Chaoyi Chen
From: Chaoyi Chen <[email protected]>
[1] https://lore.kernel.org/all/[email protected]/
====
1. Generic Type-C DP HPD bridgeCurrently, 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 generic USB Type-C DP HPD bridge (Dmitry, Heikki). Patch 2 adds new APIdrm_aux_bridge_register_from_node()(Neil). Patch 3 adds DRM AUX bridge support for RK3399 USBDP PHY (Neil). Patch 4 drops CDN-DP's extcon dependency when Type-C is present (Dmitry). Patch 5 adds multiple bridges to support PHY port selection (Dmitry, Luca).
Quoted 4 lines
Changes in v4:
- Link to v3: https://lore.kernel.org/all/[email protected]/
- Scan the entiretypec_busand attempt to register the hpd bridge, so as not to miss devices that were already added during initialization.
While that may help with the module being loaded late, it does not help with triggering the module load in the first place.
The module does not have any MODULE_DEVICE_TABLE() helping with that. So basically any system relying on the automatic hpd bridge registration and using a modular kernel (e.g. the arm64 defconfig or the kernels usually provided by Linux distributions) requires manually loading that module to get any graphical output.
Greetings,
-- Sebastian
Quoted 43 lines
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 todrm_connector_attach_encoder()
- Rebase to v7.2-rc2Changes 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 fordp->active_port(0 is valid).
- Fix the uninitializedprev_port.
- Remove duplicate logic fromcdn_dp_switch_port().
- Fix the prototype ofcdn_dp_bridge_hpd_notify().
- Properly releaseconnector->fwnode.
- Properly releasenext_bridge.Chaoyi Chen (5):
drm/bridge: Implement generic USB Type-C DP HPD bridge drm/bridge: aux: Adddrm_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
selectiondrivers/gpu/drm/bridge/Kconfig | 10 + drivers/gpu/drm/bridge/Makefile | 1 + drivers/gpu/drm/bridge/aux-bridge.c | 26 +- .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c | 64 ++++ drivers/gpu/drm/rockchip/Kconfig | 1 + drivers/gpu/drm/rockchip/cdn-dp-core.c | 358 ++++++++++++++---- 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 | 6 + 10 files changed, 428 insertions(+), 71 deletions(-) create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.cSignature · 1 line
2.53.0
Hi Sebastian,
Quoted 37 lines · Sebastian Reichel
Hello Chaoyi,
Quoted 29 lines · Chaoyi Chen
From: Chaoyi Chen <[email protected]>
[1] https://lore.kernel.org/all/[email protected]/
====
1. Generic Type-C DP HPD bridgeCurrently, 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 generic USB Type-C DP HPD bridge (Dmitry, Heikki). Patch 2 adds new APIdrm_aux_bridge_register_from_node()(Neil). Patch 3 adds DRM AUX bridge support for RK3399 USBDP PHY (Neil). Patch 4 drops CDN-DP's extcon dependency when Type-C is present (Dmitry). Patch 5 adds multiple bridges to support PHY port selection (Dmitry, Luca).Quoted 4 lines
Changes in v4:
- Link to v3: https://lore.kernel.org/all/[email protected]/
- Scan the entiretypec_busand attempt to register the hpd bridge, so as not to miss devices that were already added during initialization.
Quoted 9 lines
While that may help with the module being loaded late, it does not help with triggering the module load in the first place.
The module does not have any
MODULE_DEVICE_TABLE()helping with that. So basically any system relying on the automatic hpd bridge registration and using a modular kernel (e.g. the arm64 defconfig or the kernels usually provided by Linux distributions) requires manually loading that module to get any graphical output.
Thank you for pointing this out. I will add it in v5.
Quoted 47 lines
Greetings,
-- Sebastian
Quoted 43 lines
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 todrm_connector_attach_encoder()
- Rebase to v7.2-rc2Changes 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 fordp->active_port(0 is valid).
- Fix the uninitializedprev_port.
- Remove duplicate logic fromcdn_dp_switch_port().
- Fix the prototype ofcdn_dp_bridge_hpd_notify().
- Properly releaseconnector->fwnode.
- Properly releasenext_bridge.Chaoyi Chen (5):
drm/bridge: Implement generic USB Type-C DP HPD bridge drm/bridge: aux: Adddrm_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
selectiondrivers/gpu/drm/bridge/Kconfig | 10 + drivers/gpu/drm/bridge/Makefile | 1 + drivers/gpu/drm/bridge/aux-bridge.c | 26 +- .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c | 64 ++++ drivers/gpu/drm/rockchip/Kconfig | 1 + drivers/gpu/drm/rockchip/cdn-dp-core.c | 358 ++++++++++++++---- 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 | 6 + 10 files changed, 428 insertions(+), 71 deletions(-) create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.cSignature · 1 line
2.53.0
Signature · 2 lines
Best, Chaoyi
Hello Chaoyi,
Quoted 8 lines · Chaoyi Chen
Quoted 8 lines
Quoted 4 lines
Changes in v4:
- Link to v3: https://lore.kernel.org/all/[email protected]/
- Scan the entiretypec_busand attempt to register the hpd bridge, so as not to miss devices that were already added during initialization.While that may help with the module being loaded late, it does not help with triggering the module load in the first place.
Quoted 8 lines
Quoted 6 lines
The module does not have any
MODULE_DEVICE_TABLE()helping with that. So basically any system relying on the automatic hpd bridge registration and using a modular kernel (e.g. the arm64 defconfig or the kernels usually provided by Linux distributions) requires manually loading that module to get any graphical output.Thank you for pointing this out. I will add it in v5.
Add what exactly? As this code is quite generic, you don't have anything for a MODULE_DEVICE_TABLE() (i.e. no OF, no I2C, ...).
One solution I see to keep the notifier design would be to add
MODULE_SOFTDEP("pre: aux-hpd-typec-dp-bridge")
to some other module and piggy-back on it. Alternatively integrate it directly to some other module, such as "drm_display_helper", which already has DRM_DISPLAY_DP_HELPER and DRM_DISPLAY_DP_TUNNEL. Adding TypeC DP AltMode as part of it seems sensible to me.
FWIW I suggest you test booting your patches work with the arm64 defconfig before your next submission ;)
Greetings,
-- Sebastian
Hi Sebastian,
Quoted 18 lines · Sebastian Reichel
Hello Chaoyi,
Quoted 15 lines · Chaoyi Chen
Quoted 14 lines
Quoted 4 lines
Changes in v4:
- Link to v3: https://lore.kernel.org/all/[email protected]/
- Scan the entiretypec_busand attempt to register the hpd bridge, so as not to miss devices that were already added during initialization.While that may help with the module being loaded late, it does not help with triggering the module load in the first place.
The module does not have any
MODULE_DEVICE_TABLE()helping with that. So basically any system relying on the automatic hpd bridge registration and using a modular kernel (e.g. the arm64 defconfig or the kernels usually provided by Linux distributions) requires manually loading that module to get any graphical output.
Quoted 5 lines
Quoted 1 line
Thank you for pointing this out. I will add it in v5.
Add what exactly? As this code is quite generic, you don't have anything for a
MODULE_DEVICE_TABLE()(i.e. no OF, no I2C, ...).
That is:
static const struct typec_device_id dp_typec_id[] = {
{ USB_TYPEC_DP_SID },
{ },
};MODULE_DEVICE_TABLE(typec, dp_typec_id);
Just like the modules in drivers/usb/typec/altmodes/ .
Quoted 9 lines
One solution I see to keep the notifier design would be to add
MODULE_SOFTDEP("pre: aux-hpd-typec-dp-bridge")to some other module and piggy-back on it. Alternatively integrate it directly to some other module, such as "
drm_display_helper", which already hasDRM_DISPLAY_DP_HELPERandDRM_DISPLAY_DP_TUNNEL. Adding TypeC DP AltMode as part of it seems sensible to me.
I agree, placing it on the DRM side looks more reasonable.
Quoted 3 lines
FWIW I suggest you test booting your patches work with the arm64 defconfig before your next submission ;)
Oh, I will. It's just that I've always been using buildroot. I'll check the situation with other distributions.
Quoted 3 lines
Greetings,
-- Sebastian
Signature · 2 lines
Best, Chaoyi