usb: typec: Make sure an alt mode exist before getting its partner
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Wed, 12 Jun 2019 14:15:40 +0000 (17:15 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 12 Jun 2019 15:13:02 +0000 (17:13 +0200)
Adding check to typec_altmode_get_partner() to prevent
potential NULL pointer dereference.

Reported-by: Vladimir Yerilov <openmindead@gmail.com>
Fixes: ad74b8649bea ("usb: typec: ucsi: Preliminary support for alternate modes")
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/bus.c

index 76299b6ff06dae4eb29e49960d7403b66c39e3d8..74cb3c2ecb3476a7c2ea9f66574c782d6018b712 100644 (file)
@@ -192,7 +192,7 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm);
 const struct typec_altmode *
 typec_altmode_get_partner(struct typec_altmode *adev)
 {
-       return &to_altmode(adev)->partner->adev;
+       return adev ? &to_altmode(adev)->partner->adev : NULL;
 }
 EXPORT_SYMBOL_GPL(typec_altmode_get_partner);