platform/chrome: cros_ec_typec: Stop altmode work before unregistering ports
Subsystems (4)
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.
---
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
@@ -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
@@ -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
@@ -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
Quoted 14 lines · Myeonghun Pak
DisplayPort and Thunderbolt port altmodes queue work to deliver VDM responses to their partners. Port teardown only cancels
port_workand 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 LLMCo-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>
- Jameson
Tzung-Bi Shih
maintainerQuoted 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@@ -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.
Andrei Kuchynski
maintainerQuoted 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@@ -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
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@@ -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 incros_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