From 232f9b2f8f666cd0bccbd9ce786c4fe3a23ce6be Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Fri, 15 Mar 2013 23:59:58 -0400 Subject: [PATCH] f4 usb hid: use static data for dummy report Tx This code was previously passing a pointer to stack data into PIOS_USBHOOK_CtrlTx() which may be sending this data asynchronously. Now pass a pointer to static data so that the asynchronous send doesn't tx random stack contents. --- flight/pios/stm32f4xx/pios_usb_hid.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/flight/pios/stm32f4xx/pios_usb_hid.c b/flight/pios/stm32f4xx/pios_usb_hid.c index 8e54c859f..84669630b 100644 --- a/flight/pios/stm32f4xx/pios_usb_hid.c +++ b/flight/pios/stm32f4xx/pios_usb_hid.c @@ -350,6 +350,7 @@ static void PIOS_USB_HID_IF_DeInit(uint32_t usb_hid_id) static uint8_t hid_protocol; static uint8_t hid_altset; +static uint8_t dummy_report[2]; static bool PIOS_USB_HID_IF_Setup(uint32_t usb_hid_id, struct usb_setup_request *req) { @@ -405,15 +406,12 @@ static bool PIOS_USB_HID_IF_Setup(uint32_t usb_hid_id, struct usb_setup_request PIOS_USBHOOK_CtrlTx(&hid_protocol, 1); break; case USB_HID_REQ_GET_REPORT: - { /* Give back a dummy input report */ - uint8_t dummy_report[2] = { - [0] = req->wValue >> 8, /* Report ID */ - [1] = 0x00, - }; - PIOS_USBHOOK_CtrlTx(dummy_report, sizeof(dummy_report)); - } - break; + dummy_report[0] = req->wValue >> 8; /* Report ID */ + dummy_report[1] = 0x00; /* dummy value */ + PIOS_USBHOOK_CtrlTx(dummy_report, + MIN(sizeof(dummy_report), req->wLength)); + break; default: /* Unhandled class request */ return false;