diff mbox series

usb: typec: Make sure an alt mode exist before getting its partner

Message ID 20190612141540.73603-1-heikki.krogerus@linux.intel.com (mailing list archive)
State Mainlined
Commit 5f54a85db5df67df8161739a4b2f9c2b7ab219fe
Headers show
Series usb: typec: Make sure an alt mode exist before getting its partner | expand

Commit Message

Heikki Krogerus June 12, 2019, 2:15 p.m. UTC
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>
---
 drivers/usb/typec/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
index eda4a45f0d0a..70072e3705ca 100644
--- a/drivers/usb/typec/bus.c
+++ b/drivers/usb/typec/bus.c
@@ -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);