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: I9863df1e84a947fb04e29d214c1dec61ccc5ee72
Signed-off-by: Sriharsha Allenki <sallenki@codeaurora.org>
This commit is contained in:
Sriharsha Allenki 2020-09-03 15:22:35 +05:30
commit c4e5ee5be1

View file

@ -1369,7 +1369,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_PD))
return;
port->pwr_opmode = opmode;