Skip to content

Commit

Permalink
usb: typec: altmode: Fix typec_altmode_get_partner sometimes returnin…
Browse files Browse the repository at this point in the history
…g 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: stable@vger.kernel.org
Signed-off-by: Naoki Kiryu <naonaokiryu2@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20200422144345.43262-1-hdegoede@redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Naoki Kiryu authored and Greg Kroah-Hartman committed Apr 22, 2020
1 parent 8f97250 commit 0df9433
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/usb/typec/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm);
const struct typec_altmode *
typec_altmode_get_partner(struct typec_altmode *adev)
{
return adev ? &to_altmode(adev)->partner->adev : NULL;
if (!adev || !to_altmode(adev)->partner)
return NULL;

return &to_altmode(adev)->partner->adev;
}
EXPORT_SYMBOL_GPL(typec_altmode_get_partner);

Expand Down

0 comments on commit 0df9433

Please sign in to comment.