Skip to contentSkip to conversation

platform/chrome: cros_ec_typec: Stop altmode work before unregistering ports

PATCH In review Myeonghun Pak 4 participants 5 messages Sep 17 – Oct 2

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec_typec: Stop altmode work before unregistering ports

DisplayPort and Thunderbolt port altmodes queue work to deliver VDM responses to their partners. Port teardown only cancels port_work and then unregisters the partner and port altmodes, leaving the separate altmode work able to access released altmode data.

Disable and drain each port altmode's work before unregistering the partner altmodes. Disabling also prevents a partner callback from requeueing the work while its driver is being removed. Use the common port teardown path so probe error handling is covered as well.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes dbb3fc0ffa95 ("platform/chrome: cros_ec_typec: Displayport support")
Assisted-by LLM

---
Validated with static source review, apply checks and strict checkpatch. No build or runtime testing was performed.

 drivers/platform/chrome/cros_ec_typec.c      |  1 +
 drivers/platform/chrome/cros_typec_altmode.c | 15 +++++++++++++++
 drivers/platform/chrome/cros_typec_altmode.h |  6 ++++++
 3 files changed, 22 insertions(+)
drivers/platform/chrome/cros_ec_typec.c +1 -0
index 50a68819ceb7bbfbd888ca919d678d4c75237c26..e91bbc219c077067294935dd5602c1aec636cfa6 100644
@@ -378,6 +378,7 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
 		if (!typec->ports[i])
 			continue;
 
+		cros_typec_altmodes_stop(typec->ports[i]);
 		cros_typec_remove_partner(typec, i);
 		cros_typec_remove_cable(typec, i);
 
drivers/platform/chrome/cros_typec_altmode.c +15 -0
index 66c546bf89b532d3bae1de322a1cfb1205e0190f..2492058d98b8ef2a4a1a9bee87ce0574f4f0a736 100644
@@ -37,6 +37,21 @@ struct cros_typec_dp_data {
 	bool pending_status_update;
 };
 
+void cros_typec_altmodes_stop(struct cros_typec_port *port)
+{
+	struct cros_typec_altmode_data *adata;
+	int i;
+
+	for (i = 0; i < CROS_EC_ALTMODE_MAX; i++) {
+		if (!port->port_altmode[i])
+			continue;
+
+		adata = typec_altmode_get_drvdata(port->port_altmode[i]);
+		if (adata)
+			disable_work_sync(&adata->work);
+	}
+}
+
 static void cros_typec_altmode_work(struct work_struct *work)
 {
 	struct cros_typec_altmode_data *data =
drivers/platform/chrome/cros_typec_altmode.h +6 -0
index 3f2aa95d065af709643ad653df487a9987780da4..9e67f82ba031d67dfbe3a0549a7987386c33d120 100644
@@ -11,6 +11,12 @@ struct typec_altmode;
 struct typec_altmode_desc;
 struct typec_displayport_data;
 
+#if IS_ENABLED(CONFIG_CROS_EC_TYPEC_ALTMODES)
+void cros_typec_altmodes_stop(struct cros_typec_port *port);
+#else
+static inline void cros_typec_altmodes_stop(struct cros_typec_port *port) {}
+#endif
+
 #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
 struct typec_altmode *
 cros_typec_register_displayport(struct cros_typec_port *port,
Signature · 1 line
2.47.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Myeonghun Pak

DisplayPort and Thunderbolt port altmodes queue work to deliver VDM responses to their partners. Port teardown only cancels port_work and then unregisters the partner and port altmodes, leaving the separate altmode work able to access released altmode data.

Disable and drain each port altmode's work before unregistering the partner altmodes. Disabling also prevents a partner callback from requeueing the work while its driver is being removed. Use the common port teardown path so probe error handling is covered as well.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Quoted 6 lines
Fixes dbb3fc0ffa95 ("platform/chrome: cros_ec_typec: Displayport support")
Assisted-by LLM

- Jameson

maintainer
#2 lore raw
In reply to Myeonghun Pak
Quoted 2 lines · Myeonghun Pak

partner altmodes. Disabling also prevents a partner callback from requeueing the work while its driver is being removed. Use the common

Would the work be scheduled even if the driver is about to remove()?

drivers/platform/chrome/cros_ec_typec.c static void cros_unregister_ports(struct cros_typec_data *typec) · line 381

Quoted 9 lines
drivers/platform/chrome/cros_ec_typec.c +1 -0
index 50a68819ceb7bbfbd888ca919d678d4c75237c26..e91bbc219c077067294935dd5602c1aec636cfa6 100644
@@ -378,6 +378,7 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
 		if (!typec->ports[i])
 			continue;
 
+		cros_typec_altmodes_stop(typec->ports[i]);

Shouldn't this be called in cros_typec_unregister_port_altmodes()?

Quoted 1 line
drivers/platform/chrome/cros_typec_altmode.c +0 -0

...

drivers/platform/chrome/cros_typec_altmode.c struct cros_typec_dp_data { · line 51

Quoted 12 lines
drivers/platform/chrome/cros_typec_altmode.c +12 -0
+void cros_typec_altmodes_stop(struct cros_typec_port *port)
+{
+	struct cros_typec_altmode_data *adata;
+	int i;
+
+	for (i = 0; i < CROS_EC_ALTMODE_MAX; i++) {
+		if (!port->port_altmode[i])
+			continue;
+
+		adata = typec_altmode_get_drvdata(port->port_altmode[i]);
+		if (adata)
+			disable_work_sync(&adata->work);

This is a driver teardown path: cancel_work_sync() should be sufficient.

maintainer
#3 lore raw
Quoted 15 lines · Tzung-Bi Shih
Quoted 2 lines · Myeonghun Pak

partner altmodes. Disabling also prevents a partner callback from requeueing the work while its driver is being removed. Use the common

Would the work be scheduled even if the driver is about to remove()?

Quoted 8 lines
drivers/platform/chrome/cros_ec_typec.c +0 -0
index 50a68819ceb7bbfbd888ca919d678d4c75237c26..e91bbc219c077067294935dd5602c1aec636cfa6 100644
@@ -378,6 +378,7 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
              if (!typec->ports[i])
                      continue;
 
Quoted 3 lines

drivers/platform/chrome/cros_ec_typec.c static void cros_unregister_ports(struct cros_typec_data *typec) · line 381

Quoted 1 line
drivers/platform/chrome/cros_ec_typec.c +1 -0
+             cros_typec_altmodes_stop(typec->ports[i]);

Shouldn't this be called in cros_typec_unregister_port_altmodes()?

This should be called in the very beginning of cros_typec_remove_partner(), or even in cros_typec_unregister_altmodes(). The idea is to stop the queue when the partner no longer exists.
Partner disconnection rather than port teardown ought to trigger this.

Thanks,
Andrei

#4 lore raw

Thanks for the feedback. I've moved the work quiescing into cros_typec_unregister_altmodes() so partner disconnects are covered too.

Pending partner work can still queue responses during driver removal, so the port work stays disabled until that completes, then is reset and re-enabled for reconnection. Final port teardown now uses cancel_work_sync().

I'll send v2 with these changes.

2026년 10월 1일 (목) 오전 11:40, Andrei Kuchynski <[email protected]>님이 작성:

Quoted 28 lines · Tzung-Bi Shih
Quoted 15 lines · Myeonghun Pak
Quoted 2 lines

partner altmodes. Disabling also prevents a partner callback from requeueing the work while its driver is being removed. Use the common

Would the work be scheduled even if the driver is about to remove()?

Quoted 8 lines
drivers/platform/chrome/cros_ec_typec.c +0 -0
index 50a68819ceb7bbfbd888ca919d678d4c75237c26..e91bbc219c077067294935dd5602c1aec636cfa6 100644
@@ -378,6 +378,7 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
              if (!typec->ports[i])
                      continue;
 
Quoted 3 lines

drivers/platform/chrome/cros_ec_typec.c static void cros_unregister_ports(struct cros_typec_data *typec) · line 381

Quoted 1 line
drivers/platform/chrome/cros_ec_typec.c +1 -0
+             cros_typec_altmodes_stop(typec->ports[i]);

Shouldn't this be called in cros_typec_unregister_port_altmodes()?

This should be called in the very beginning of cros_typec_remove_partner(), or even in cros_typec_unregister_altmodes(). The idea is to stop the queue when the partner no longer exists.
Partner disconnection rather than port teardown ought to trigger this.

Thanks,
Andrei