From b38b8a0fa4443ef2b158324cd0bd9b91f79b94df Mon Sep 17 00:00:00 2001 From: Andreas Fernandez Date: Tue, 10 Nov 2026 13:18:45 +0100 Subject: [PATCH] usb: typec: take the altmode module reference when the mode is already active typec_altmode_update_active() takes a reference on the altmode driver's module when a mode becomes active and drops it when the mode is left. A mode that was entered before its driver bound, for example when the first plug autoloads typec_displayport, took no reference, but leaving it still drops one. The module refcount then ends up at -1, and every later replug warns in typec_altmode_update_active() and module_put(). Take the reference in typec_probe() when the mode is already active. Signed-off-by: Andreas Fernandez --- drivers/usb/typec/bus.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index e84b134a33813..2624bc27a9464 100644 --- a/drivers/usb/typec/bus.c +++ b/drivers/usb/typec/bus.c @@ -535,10 +535,19 @@ static int typec_probe(struct device *dev) } ret = drv->probe(adev); - if (ret) + if (ret) { typec_altmode_remove_links(altmode); + return ret; + } + + /* + * A mode entered before its driver bound took no reference on the + * driver's module, but leaving it drops one. Take it now. + */ + if (adev->active && !is_typec_port(adev->dev.parent)) + WARN_ON(!try_module_get(drv->driver.owner)); - return ret; + return 0; } static void typec_remove(struct device *dev)