From: Fei Yang Date: Wed, 20 Apr 2016 06:08:43 +0000 (+0300) Subject: UPSTREAM: usb: dwc3: ep0: sanity check test mode selector X-Git-Tag: firefly_0821_release~1849 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=fd219f74f1fe1cddf84aac1e902f61e7df2b6de5;p=firefly-linux-kernel-4.4.55.git UPSTREAM: usb: dwc3: ep0: sanity check test mode selector In case host sends us an unsupported test mode, we *must* stall this request. This will tell the host that the selector is invalid and we won't put the controller in unsupported test modes which could have undetermined side-effects. Change-Id: Iaf6a0ae78864efa342a514fdd5e6fc7f2e94e314 Signed-off-by: Fei Yang Signed-off-by: Felipe Balbi Signed-off-by: Wu Liang feng (cherry picked from commit ae411413760785a0a2ce6cb44d5afe95115aa24d) --- diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 12b0ec2b2712..e153e0262f81 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -460,8 +460,18 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, if (!set) return -EINVAL; - dwc->test_mode_nr = wIndex >> 8; - dwc->test_mode = true; + switch (wIndex >> 8) { + case TEST_J: + case TEST_K: + case TEST_SE0_NAK: + case TEST_PACKET: + case TEST_FORCE_EN: + dwc->test_mode_nr = wIndex >> 8; + dwc->test_mode = true; + break; + default: + return -EINVAL; + } break; default: return -EINVAL;