From 5fb72d405d5dbc587f3da5c03bc8aacf99c02c24 Mon Sep 17 00:00:00 2001 From: Sriharsha Allenki Date: Thu, 3 Sep 2020 15:22:35 +0530 Subject: [PATCH] usb: typec: Fix setting of invalid value of opmode Setting opmode to invalid values would lead to a paging fault failure when there is an access to the power_operation_mode. Prevent this by checking the validity of the value that the opmode is being set. Change-Id: I9ada1ad4aeeca08d3072a5738f5fa48537a2cecf Signed-off-by: Sriharsha Allenki --- drivers/usb/typec/class.c | 3 ++- include/linux/usb/typec.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 6fc8d44a3c23..46348591c3b4 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1378,7 +1378,8 @@ void typec_set_pwr_opmode(struct typec_port *port, { struct device *partner_dev; - if (port->pwr_opmode == opmode) + if ((port->pwr_opmode == opmode) || (opmode < TYPEC_PWR_MODE_USB) || + (opmode > TYPEC_PWR_MODE_MAX)) return; port->pwr_opmode = opmode; diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 27a6fc7c35ea..fab39d44abc7 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -53,6 +53,7 @@ enum typec_pwr_opmode { TYPEC_PWR_MODE_1_5A, TYPEC_PWR_MODE_3_0A, TYPEC_PWR_MODE_PD, + TYPEC_PWR_MODE_MAX = TYPEC_PWR_MODE_PD, }; enum typec_accessory {