diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-09-17 10:30:17 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-09-20 17:38:56 -0400 |
commit | 99f333c64f13c3f9a62b9f5e184ae87f053bf65a (patch) | |
tree | d4c31cd346cc13b173965d56df8041613baa9ab2 /firmware | |
parent | 483563a1b2cd5d463557580498d75a693dd79077 (diff) |
usb_hid: fix accidental fallthrough
Successful SET REPORT requests would spuriously fail because of the
fall through to GET REPORT.
Change-Id: I8e7d1a1120afc6975d07d47b11c12c9e9ca51dd2
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/usbstack/usb_hid.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/firmware/usbstack/usb_hid.c b/firmware/usbstack/usb_hid.c index 5885b60e32..885ae4c24a 100644 --- a/firmware/usbstack/usb_hid.c +++ b/firmware/usbstack/usb_hid.c @@ -785,27 +785,39 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest) (req->bRequest == USB_HID_SET_IDLE) ? "set idle" : ((req->bRequest == USB_HID_SET_REPORT) ? "set report" : ((req->bRequest == USB_HID_GET_REPORT) ? "get report" : ""))); + + int rc; switch (req->bRequest) { case USB_HID_SET_REPORT: - if (usb_hid_set_report(req)) - break; + rc = usb_hid_set_report(req); + break; case USB_HID_GET_REPORT: - if (usb_hid_get_report(req, &dest)) - break; + rc = usb_hid_get_report(req, &dest); + break; case USB_HID_SET_IDLE: - if (dest != orig_dest) - { - usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ - usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); - } - else - { - usb_drv_send(EP_CONTROL, NULL, 0); /* ack */ - } - return true; + rc = 0; + break; + default: + /* all other requests are errors */ + rc = -1; + break; } - break; + + if(rc != 0) + break; + + if (dest != orig_dest) + { + usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ + usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); + } + else + { + usb_drv_send(EP_CONTROL, NULL, 0); /* ack */ + } + + return true; } case USB_TYPE_VENDOR: |