Skip to contentSkip to conversation

drm/bridge: Implement generic USB Type-C DP HPD bridge

PATCH Superseded Chaoyi Chen 4 participants 14 messages Jul 30 – Aug 3

Subsystems (6)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#5 lore raw

PATCH v5 2/6 drm/display: Add soft depend for aux-hpd-typec-dp-bridge module

In reply to Chaoyi Chen

From: 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.

---
 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
index d8a6e6228773..f0152d6b0b2d 100644
@@ -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
#6 lore raw

PATCH v5 3/6 drm/bridge: aux: Add drm_aux_bridge_register_from_node()

In reply to Chaoyi Chen

From: 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
index 1ed21a8713bf..06a1466f49bd 100644
@@ -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
index c2f5a855512f..7dd1f17a1354 100644
@@ -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
#0 lore raw

v5 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 generic USB Type-C DP HPD bridge (Dmitry, Heikki). Patch 2 add module soft depend for USB Type-C DP HPD bridge(Sebastian). Patch 3 adds new API drm_aux_bridge_register_from_node() (Neil). Patch 4 adds DRM AUX bridge support for RK3399 USBDP PHY (Neil). Patch 5 drops CDN-DP's extcon dependency when Type-C is present (Dmitry). Patch 6 adds multiple bridges to support PHY port selection (Dmitry, Luca).

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 (6):
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 +-
 .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c  |  64 ++++
 .../gpu/drm/display/drm_display_helper_mod.c  |   1 +
 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 +
 11 files changed, 429 insertions(+), 71 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
Signature · 7 lines
2.53.0


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#1 lore raw

PATCH v5 1/6 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.

---

(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  | 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
index 4a57d49b4c6d..9739b2a19758 100644
@@ -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
index 15cc821d85b7..d88a9e1ccc9a 100644
@@ -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
#8 lore raw

PATCH v5 4/6 phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

In reply to Chaoyi Chen

From: 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
index 14698571b607..9173d3b4fef4 100644
@@ -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
index d9701b6106d5..48070b50416e 100644
@@ -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
#10 lore raw

PATCH v5 5/6 drm/rockchip: cdn-dp: Support handle lane info without extcon

In reply to Chaoyi Chen

From: 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
index 190cce9530c8..74e1f5422a6e 100644
@@ -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
#12 lore raw

PATCH v5 6/6 drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

In reply to Chaoyi Chen

From: 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
index e7f49fe845ea..ce70f91c13e6 100644
@@ -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
index e9c30b9fd543..c10e423bbf06 100644
@@ -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
#7 lore raw

Re: [PATCH v5 3/6] drm/bridge: aux: Add drm_aux_bridge_register_from_node()

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unbalanced `of_node_put()` on the provided device node `np` leads to reference count underflow and…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unbalanced of_node_put() on the provided device node np leads to reference count underflow and potential use-after-free. --

--- Patch [3]: [PATCH v5 3/6] drm/bridge: aux: Add drm_aux_bridge_register_from_node() --- commit 73b014949499087c9b0b99c49dc18c4868428dcd
Author: Chaoyi Chen <[email protected]>

drm/bridge: aux: Add drm_aux_bridge_register_from_node()

This patch introduces a new function to register an auxiliary bridge using a specifically provided device node, instead of defaulting to the parent's device node.

Quoted 4 lines
drivers/gpu/drm/bridge/aux-bridge.c +0 -0
index 1ed21a8713bfd..06a1466f49bd2 100644

[ ... ]

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 path cause a reference count underflow on the provided device node?

When np is provided, device_set_node() simply assigns the node pointer without taking a reference via of_node_get(). In contrast, the fallback path device_set_of_node_from_dev() properly acquires a reference.

Both the error path below (when auxiliary_device_init() fails) and the normal device release callback drm_aux_bridge_release() unconditionally call of_node_put(adev->dev.of_node). This drops a reference that was never acquired in the np != NULL branch.

If the API intended to consume a reference from the caller, the error paths appear to be structurally broken: failure in ida_alloc() does not drop the reference, but failure in auxiliary_device_init() does, leaving the caller unable to know if it should clean up the reference.

Should we add an of_node_get() here?

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) {

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#11 lore raw

Re: [PATCH v5 5/6] drm/rockchip: cdn-dp: Support handle lane info without extcon

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Valid extcon devices are incorrectly skipped during probe due to a flawed pointer error check…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Valid extcon devices are incorrectly skipped during probe due to a flawed pointer error check, breaking all existing platforms that use extcon.
- [High] Hotplug detect (HPD) is completely broken when extcon is not present because no alternative notification mechanism is implemented.
- [High] Unchecked negative error code from phy_get_bus_width is implicitly truncated to u8 and used as a valid lane count, corrupting hardware configuration. --

--- Patch [5]: [PATCH v5 5/6] drm/rockchip: cdn-dp: Support handle lane info without extcon --- commit 4ff0e4c27809cca886c5ca372b54b8d927541018
Author: Chaoyi Chen <[email protected]>

drm/rockchip: cdn-dp: Support handle lane info without extcon

This commit adds support for getting PHY lane information directly from the PHY instead of relying on extcon when a Type-C controller is present. It preserves extcon support for cases where the Type-C controller is absent.

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_port_lanes(struct cdn_dp_port *port) · line 162

Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3 -0
index 190cce9530c82..74e1f5422a6e2 100644
@@ -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);
+

[Severity: High]
Can this return a negative error code (like -ENOSYS) that gets truncated?

In cdn_dp_enable_phy(), the return value is directly assigned to an 8-bit unsigned integer:

	port->lanes = cdn_dp_get_port_lanes(port);

If phy_get_bus_width() returns a negative error, will this result in a silently truncated out-of-bounds lane count being written to the hardware registers?

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1038

Quoted 7 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;
+

[Severity: High]
Does skipping the notifier registration permanently orphan the driver's hotplug detect state machine?

The driver's connection state machine is entirely driven by cdn_dp_pd_event_work(), which is only ever scheduled by the extcon notifier callback.

Without an alternative notification mechanism for non-extcon setups, will the display controller ever be notified of cable insertion?

[ ... ]

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: High]
Will this condition evaluate to true for all valid extcon pointers, skipping valid extcon devices entirely?

When a valid extcon device is found, PTR_ERR() will cast that pointer address to a long. Since a valid pointer address will not equal -ENODEV, this check seems to evaluate to true and skip the port setup for all existing functional extcon setups.

Should this include an IS_ERR() guard, such as
IS_ERR(extcon) && PTR_ERR(extcon) != -ENODEV?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#9 lore raw

Re: [PATCH v5 4/6] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Double-free of OF node reference resulting from borrowed node assignment - [Medium] Improper Error…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double-free of OF node reference resulting from borrowed node assignment
- [Medium] Improper Error Handling: Unconditional execution of bridge registration shadows PHY creation errors --

--- Patch [4]: [PATCH v5 4/6] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge --- commit c26cb3c5d012dc638272484e672dcad955d4a455
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
index d9701b6106d55..48070b50416e5 100644

[ ... ]

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: Medium]
If devm_phy_create() fails and returns an error pointer, the code still unconditionally calls drm_aux_bridge_register_from_node().

If the bridge registration fails, its error code will be stored in ret and returned below, which completely shadows the original error from devm_phy_create() (such as -EPROBE_DEFER).

Should devm_phy_create()'s return value be checked before attempting to register the bridge?

[Severity: High]
Does this cause a double-free of the child_np node reference?

The for_each_available_child_of_node() loop automatically holds a reference to child_np. When child_np is passed to drm_aux_bridge_register_from_node(), the bridge takes ownership of the node reference without the caller acquiring an additional reference via of_node_get().

If registration succeeds, the bridge will eventually call of_node_put() in its drm_aux_bridge_release() handler. Meanwhile, the iterator loop also automatically calls of_node_put() when advancing to the next node, leading to a double-free on the success path.

drivers/phy/rockchip/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 1182

Quoted 11 lines
drivers/phy/rockchip/phy-rockchip-typec.c +6 -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;
+		}

[Severity: High]
If drm_aux_bridge_register_from_node() fails, it calls of_node_put() internally. Because this error path explicitly calls of_node_put(child_np) again, would this result in an immediate double-free?

Would it be better to call of_node_get(child_np) before passing it to drm_aux_bridge_register_from_node() to ensure the bridge has its own reference?

Quoted 3 lines
drivers/phy/rockchip/phy-rockchip-typec.c +0 -0
 		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=4
#13 lore raw

Re: [PATCH v5 6/6] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:

New issues:
- [High] Stale pointers in dp->next_bridge_list cause a double free / refcount underflow on repeated or failed bind cycles.
- [High] cdn_dp_switch_port unconditionally configures video, breaking EDID reads for newly connected monitors.
- [High] Missing atomic_check allows simultaneous activation of multiple conflicting encoders.
- [High] cdn_dp_connected_port bypasses the physical lane check for extcon configurations, breaking hotplug detection.
- [High] Index mismatch between packed PHY ports and DT endpoints causes uninitialized memory reads and guaranteed NULL dereferences.
- [Medium] Device tree endpoint iteration lacks a bounds check against MAX_PHY, leading to a heap buffer overflow.

Pre-existing issues:
- [High] Extcon notifiers can schedule work after cancel_work_sync(), leading to Use-After-Free. --

--- Patch [6]: [PATCH v5 6/6] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection --- commit 8377956184d44f77846e2394e562e31ea5099865
Author: Chaoyi Chen <[email protected]>

drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

This commit adds support for multiple bridges in the Rockchip CDN-DP driver to enable PHY port selection via the DRM AUX HPD bridge framework. It parses device tree endpoints to register one or two bridges and handles switching the DP controller output between them based on plug states.

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
index 74e1f5422a6e2..5e513f6930cb9 100644

[ ... ]

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
@@ -192,14 +193,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 202

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]
Does this break hotplug detection for legacy extcon-based devices?

If dp->next_bridge_valid is false, this loop unconditionally returns dp->port[0] on the first iteration without verifying if the physical lanes are greater than zero. This causes the driver to perpetually report the display as connected.

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 213

Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10 -0
 	}
+
+	if (dp->next_bridge_valid) {
+		/* If more than one port is available, pick the last active port */
+		if (dp->active_port >= 0 && lanes[dp->active_port])
+			return dp->port[dp->active_port];
+
+		/* If the last active port is not available, pick an available port in order */
+		for (i = 0; i < dp->bridge_count; i++) {
+			if (lanes[i])
+				return dp->port[i];

[Severity: High]
Can this loop read uninitialized stack memory?

The lanes array is populated in the previous loop up to dp->ports, which tracks successfully probed PHYs. However, this loop iterates up to dp->bridge_count, which tracks DT endpoints. If a device tree specifies more endpoints than successfully probed PHYs, this will read out of bounds on the stack.

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3 -0
+		}
+	}
+
 	return NULL;
 }

[ ... ]

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -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;

drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 280

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +8 -0
+	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) {

[Severity: High]
Is there a risk of a NULL pointer dereference here?

If the device tree has more endpoints than successfully probed PHYs, dp_bridge->id could exceed the bounds of initialized dp->port pointers. In that scenario, port would be NULL, and evaluating !port->phy_enabled will crash.

drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 292

Quoted 12 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +12 -0
+		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)
+				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 sequence fail to read the EDID for a newly connected monitor?

Switching the port here calls cdn_dp_switch_port(), which unconditionally executes cdn_dp_config_video(dp). During EDID probing, no DRM display mode has been committed yet, so dp->mode.clock is 0.

This causes cdn_dp_config_video() to fail its bandwidth calculation loop and return -EINVAL, which aborts the port switch and forces the driver to fall back to a cached EDID.

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -0
+			if (ret)
+				goto get_cache;
+		}
+	}

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_bridge_funcs cdn_dp_bridge_funcs = { · line 953

Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1 -0
@@ -838,6 +948,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,
 
 	.dp_audio_prepare = cdn_dp_audio_prepare,

[Severity: High]
Because there is only a single DP hardware controller backing multiple potential bridges, is there a risk of hardware state corruption if userspace commits a state that maps CRTCs to both ports simultaneously?

Without an .atomic_check callback in cdn_dp_bridge_funcs to enforce mutual exclusivity, cdn_dp_bridge_atomic_enable() could execute for the second port and overwrite the video configuration while the first is active.

[ ... ]

Quoted 1 line
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
@@ -1030,6 +1142,101 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)

[ ... ]

Quoted 2 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -0
+static int cdn_dp_parse_next_bridge_dt(struct cdn_dp_device *dp)
+{

[ ... ]

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -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 1183

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]
Is there a potential heap buffer overflow here?

The count variable is incremented and used as an index for dp->next_bridge_list[count], but there is no bounds check against MAX_PHY. If a misconfigured device tree provides 3 or more endpoints, this will overwrite adjacent fields in the cdn_dp_device structure.

Quoted 1 line
drivers/gpu/drm/rockchip/cdn-dp-core.c +1 -0
+	}

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1265

Quoted 8 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -0
@@ -1052,15 +1259,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]
Can this result in a double free and refcount underflow?

If cdn_dp_bind() fails and executes this error path, it calls drm_bridge_put() but leaves the pointers intact in dp->next_bridge_list. If the master bind is retried later and fails again, it will perform another drm_bridge_put() on the same stale pointers.

The same pattern also appears below during unbind.

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1276

Quoted 12 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;
 
 	cancel_work_sync(&dp->event_work);

[Severity: High]
This is a pre-existing issue, but can this lead to a use-after-free during unbind?

Extcon notifiers are registered using devm_extcon_register_notifier(). While cancel_work_sync(&dp->event_work) cancels pending work here, the devm-managed notifier remains active until devres cleanup, which happens after unbind returns.

A hotplug event in this window could reschedule dp->event_work, executing it after the structures are freed.

Quoted 6 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -1
-	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]);
+	}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#2 lore raw
In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Resource leak and duplicate bridge registration on module reload due to lifecycle mismatch.…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Resource leak and duplicate bridge registration on module reload due to lifecycle mismatch.
- [High] Duplicate registration conflict with USB-C controller drivers that natively implement HPD bridges.
- [Medium] Race condition between bus notifier registration and device iteration leading to duplicate bridge registration. --

--- Patch [1]: [PATCH v5 1/6] drm/bridge: Implement generic USB Type-C DP HPD bridge --- commit 9877135b6e3e85a72f21170c14a083ad3e0308af
Author: Chaoyi Chen <[email protected]>

drm/bridge: Implement generic USB Type-C DP HPD bridge

This patch implements a generic USB Type-C DP HPD bridge that monitors the Type-C bus for devices containing the DP SVID. It automatically creates an HPD bridge for these devices without requiring the USB-C controller driver to implement it manually.

Quoted 6 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +0 -0
new file mode 100644
index 0000000000000..43af3ea20f201
@@ -0,0 +1,64 @@

[ ... ]

Quoted 6 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +6 -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);
+

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 28

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)
+		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
+					   to_of_node(alt->dev.parent->fwnode));

[Severity: High]
Does this unconditional registration create duplicate bridges for controller drivers (like fusb302 or qcom_pmic_typec) that already manually allocate their own HPD bridge for the same device node?

If the DRM subsystem binds to the generic bridge instead of the native one, could HPD events sent by the controller via drm_aux_hpd_bridge_notify() to its private bridge be lost?

[ ... ]

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 46

Quoted 4 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +4 -0
+static void drm_aux_hpd_typec_dp_bridge_module_exit(void)
+{
+	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
+}

[Severity: High]
Does this leak resources and create duplicate bridges if the module is unloaded and reloaded?

Since drm_dp_hpd_bridge_register() uses devm semantics tied to the USB-C controller device (alt->dev.parent->parent) rather than this observer module, the bridges will outlive the module. When the module is reloaded, it will iterate the bus and unconditionally allocate a second set of duplicate bridges.

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 55

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +9 -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]
Is there a race condition here between registering the bus notifier and iterating over the existing devices?

If a Type-C altmode device is added concurrently during module initialization, could it trigger the notifier callback and also be processed by the bus iteration loop? Since drm_dp_hpd_bridge_register() lacks deduplication logic, this TOCTOU race might result in duplicate bridge registrations.

Quoted 5 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +5 -0
+	return 0;
+}
+
+module_init(drm_aux_hpd_typec_dp_bridge_module_init);
+module_exit(drm_aux_hpd_typec_dp_bridge_module_exit);
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
#3 lore raw
In reply to Chaoyi Chen

Hi,

Quoted 103 lines · Chaoyi Chen

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.

---

(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  | 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
index 4a57d49b4c6d..9739b2a19758 100644
@@ -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
index 15cc821d85b7..d88a9e1ccc9a 100644
@@ -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 +18 -0
new file mode 100644
index 000000000000..43af3ea20f20
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Rockchip Electronics Co., Ltd.
+ *
+ * Author: Chaoyi Chen <[email protected]>
+ */
+#include <linux/of.h>
+#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_dp.h>
+
+#include <drm/bridge/aux-bridge.h>
+
+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);
+

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 28

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)
+		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
+					   to_of_node(alt->dev.parent->fwnode));

So there are 3 ways to end up with duplicated hpd bridges now:

1. TypeC controller driver already registered one manually
2. There is a race in drm_aux_hpd_typec_dp_bridge_module_init, if a device appears between registering the notifier and looping through all pre-existing devices
3. Reloading the aux-hpd-typec-dp-bridge module re-registers the bridges

It's not a huge problem as the system works with the duplicated HPD bridges, but it's also quite ugly.

I think it can be trivially avoided by adding this function to drivers/gpu/drm/bridge/aux-hpd-bridge.c and then making use of it here as an additional check (code untested):

bool drm_device_has_dp_hpd_bridge(struct device *parent)

{
	struct device *hpd_bridge = device_find_child_by_name(parent, "dp_hpd_bridge");

	if (!hpd_bridge)
		return false;

	put_device(hpd_bridge);
	return true;
}

EXPORT_SYMBOL_GPL(drm_dev_has_dp_hpd_bridge);

That would solve all of the above, but leaves one problem when this module races against manual device creation in a TypeC controller driver. That could be avoided by doing the check in devm_drm_dp_hpd_bridge_alloc() under a lock, but that's probably not worth the trouble (it would require updating all users to handle a new error code like -EEXIST) considering manual registration can be removed from all drivers anyways.

Greetings,

-- Sebastian

Quoted 39 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +36 -0
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block drm_typec_event_nb = {
+	.notifier_call = drm_typec_bus_event,
+};
+
+static int check_device_already_added(struct device *dev, void *data)
+{
+	drm_typec_bus_event(NULL, BUS_NOTIFY_ADD_DEVICE, dev);
+	return 0;
+}
+
+static void drm_aux_hpd_typec_dp_bridge_module_exit(void)
+{
+	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
+}
+
+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);
+	return 0;
+}
+
+module_init(drm_aux_hpd_typec_dp_bridge_module_init);
+module_exit(drm_aux_hpd_typec_dp_bridge_module_exit);
+
+MODULE_AUTHOR("Chaoyi Chen <[email protected]>");
+MODULE_DESCRIPTION("DRM TYPEC DP HPD BRIDGE");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.53.0
#4 lore raw

Hi Sebastian,

Quoted 143 lines · Sebastian Reichel

Hi,

Quoted 103 lines · Chaoyi Chen

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.

---

(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  | 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
index 4a57d49b4c6d..9739b2a19758 100644
@@ -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
index 15cc821d85b7..d88a9e1ccc9a 100644
@@ -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 +18 -0
new file mode 100644
index 000000000000..43af3ea20f20
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Rockchip Electronics Co., Ltd.
+ *
+ * Author: Chaoyi Chen <[email protected]>
+ */
+#include <linux/of.h>
+#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_dp.h>
+
+#include <drm/bridge/aux-bridge.h>
+
+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);
+

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 28

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)
+		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
+					   to_of_node(alt->dev.parent->fwnode));

So there are 3 ways to end up with duplicated hpd bridges now:

1. TypeC controller driver already registered one manually
2. There is a race in drm_aux_hpd_typec_dp_bridge_module_init, if a device appears between registering the notifier and looping through all pre-existing devices
3. Reloading the aux-hpd-typec-dp-bridge module re-registers the bridges

It's not a huge problem as the system works with the duplicated HPD bridges, but it's also quite ugly.

I think it can be trivially avoided by adding this function to drivers/gpu/drm/bridge/aux-hpd-bridge.c and then making use of it here as an additional check (code untested):

bool drm_device_has_dp_hpd_bridge(struct device *parent)

{
	struct device *hpd_bridge = device_find_child_by_name(parent, "dp_hpd_bridge");

	if (!hpd_bridge)
		return false;

	put_device(hpd_bridge);
	return true;
}
Quoted 2 lines

EXPORT_SYMBOL_GPL(drm_dev_has_dp_hpd_bridge);

I think deduplication during registration is a good idea. Detecting it during alloc seems a bit premature.

Thanks again for your suggestion. I'll try to add it in the next version.

Quoted 51 lines

That would solve all of the above, but leaves one problem when this module races against manual device creation in a TypeC controller driver. That could be avoided by doing the check in devm_drm_dp_hpd_bridge_alloc() under a lock, but that's probably not worth the trouble (it would require updating all users to handle a new error code like -EEXIST) considering manual registration can be removed from all drivers anyways.

Greetings,

-- Sebastian

Quoted 39 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +36 -0
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block drm_typec_event_nb = {
+	.notifier_call = drm_typec_bus_event,
+};
+
+static int check_device_already_added(struct device *dev, void *data)
+{
+	drm_typec_bus_event(NULL, BUS_NOTIFY_ADD_DEVICE, dev);
+	return 0;
+}
+
+static void drm_aux_hpd_typec_dp_bridge_module_exit(void)
+{
+	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
+}
+
+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);
+	return 0;
+}
+
+module_init(drm_aux_hpd_typec_dp_bridge_module_init);
+module_exit(drm_aux_hpd_typec_dp_bridge_module_exit);
+
+MODULE_AUTHOR("Chaoyi Chen <[email protected]>");
+MODULE_DESCRIPTION("DRM TYPEC DP HPD BRIDGE");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.53.0
Signature · 7 lines
Best, 
Chaoyi

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy