Skip to content

Commit 0df9433

Browse files
grainrigigregkh
authored andcommitted
usb: typec: altmode: Fix typec_altmode_get_partner sometimes returning an invalid pointer
Before this commit, typec_altmode_get_partner would return a const struct typec_altmode * pointing to address 0x08 when to_altmode(adev)->partner was NULL. Add a check for to_altmode(adev)->partner being NULL to fix this. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206365 BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1785972 Fixes: 5f54a85 ("usb: typec: Make sure an alt mode exist before getting its partner") Cc: [email protected] Signed-off-by: Naoki Kiryu <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8f97250 commit 0df9433

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/usb/typec/bus.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm);
198198
const struct typec_altmode *
199199
typec_altmode_get_partner(struct typec_altmode *adev)
200200
{
201-
return adev ? &to_altmode(adev)->partner->adev : NULL;
201+
if (!adev || !to_altmode(adev)->partner)
202+
return NULL;
203+
204+
return &to_altmode(adev)->partner->adev;
202205
}
203206
EXPORT_SYMBOL_GPL(typec_altmode_get_partner);
204207

0 commit comments

Comments
 (0)