Skip to content

Commit 5962ded

Browse files
RD Babieragregkh
authored andcommitted
usb: typec: class: fix typec_altmode_put_partner to put plugs
When typec_altmode_put_partner is called by a plug altmode upon release, the port altmode the plug belongs to will not remove its reference to the plug. The check to see if the altmode being released is a plug evaluates against the released altmode's partner instead of the calling altmode, so change adev in typec_altmode_put_partner to properly refer to the altmode being released. Because typec_altmode_set_partner calls get_device() on the port altmode, add partner_adev that points to the port altmode in typec_put_partner to call put_device() on. typec_altmode_set_partner is not called for port altmodes, so add a check in typec_altmode_release to prevent typec_altmode_put_partner() calls on port altmode release. Fixes: 8a37d87 ("usb: typec: Bus type for alternate modes") Cc: <stable@vger.kernel.org> Co-developed-by: Christian A. Ehrhardt <lk@c--e.de> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> Signed-off-by: RD Babiera <rdbabiera@google.com> Tested-by: Christian A. Ehrhardt <lk@c--e.de> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20240103181754.2492492-2-rdbabiera@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 79c58ab commit 5962ded

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/typec/class.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,13 @@ static void typec_altmode_put_partner(struct altmode *altmode)
263263
{
264264
struct altmode *partner = altmode->partner;
265265
struct typec_altmode *adev;
266+
struct typec_altmode *partner_adev;
266267

267268
if (!partner)
268269
return;
269270

270-
adev = &partner->adev;
271+
adev = &altmode->adev;
272+
partner_adev = &partner->adev;
271273

272274
if (is_typec_plug(adev->dev.parent)) {
273275
struct typec_plug *plug = to_typec_plug(adev->dev.parent);
@@ -276,7 +278,7 @@ static void typec_altmode_put_partner(struct altmode *altmode)
276278
} else {
277279
partner->partner = NULL;
278280
}
279-
put_device(&adev->dev);
281+
put_device(&partner_adev->dev);
280282
}
281283

282284
/**
@@ -497,7 +499,8 @@ static void typec_altmode_release(struct device *dev)
497499
{
498500
struct altmode *alt = to_altmode(to_typec_altmode(dev));
499501

500-
typec_altmode_put_partner(alt);
502+
if (!is_typec_port(dev->parent))
503+
typec_altmode_put_partner(alt);
501504

502505
altmode_id_remove(alt->adev.dev.parent, alt->id);
503506
kfree(alt);

0 commit comments

Comments
 (0)