diff options
author | Krzysztof Opasiak <kopasiak90@gmail.com> | 2015-03-27 04:35:44 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2015-04-27 15:44:23 -0400 |
commit | f286d487e9283a42a8844659bb5552b3f1bf6a7d (patch) | |
tree | 5b33ffcc7fe3e560b4f7faa2b001f46c2fc4436f /drivers/usb/gadget/function | |
parent | 903124fe1aa284f61745a9dd4fbfa0184e569fff (diff) |
usb: gadget: hid: Fix static variable usage
If we have multiple instances of hid function, each of
them may have different report descriptor, also their
length may be different.
Currently we are using static hidg_desc varable which
is being filled in hidg_bind(). Then we send its content
to host in hidg_setup() function. This content may
have been already overwriten if another instance
has executed hidg_bind().
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/function')
-rw-r--r-- | drivers/usb/gadget/function/f_hid.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index 13dfc9915b1d..f7f35a36c09a 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c | |||
@@ -437,12 +437,20 @@ static int hidg_setup(struct usb_function *f, | |||
437 | | USB_REQ_GET_DESCRIPTOR): | 437 | | USB_REQ_GET_DESCRIPTOR): |
438 | switch (value >> 8) { | 438 | switch (value >> 8) { |
439 | case HID_DT_HID: | 439 | case HID_DT_HID: |
440 | { | ||
441 | struct hid_descriptor hidg_desc_copy = hidg_desc; | ||
442 | |||
440 | VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n"); | 443 | VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n"); |
444 | hidg_desc_copy.desc[0].bDescriptorType = HID_DT_REPORT; | ||
445 | hidg_desc_copy.desc[0].wDescriptorLength = | ||
446 | cpu_to_le16(hidg->report_desc_length); | ||
447 | |||
441 | length = min_t(unsigned short, length, | 448 | length = min_t(unsigned short, length, |
442 | hidg_desc.bLength); | 449 | hidg_desc_copy.bLength); |
443 | memcpy(req->buf, &hidg_desc, length); | 450 | memcpy(req->buf, &hidg_desc_copy, length); |
444 | goto respond; | 451 | goto respond; |
445 | break; | 452 | break; |
453 | } | ||
446 | case HID_DT_REPORT: | 454 | case HID_DT_REPORT: |
447 | VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n"); | 455 | VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n"); |
448 | length = min_t(unsigned short, length, | 456 | length = min_t(unsigned short, length, |
@@ -632,6 +640,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f) | |||
632 | hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); | 640 | hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); |
633 | hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); | 641 | hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); |
634 | hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); | 642 | hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); |
643 | /* | ||
644 | * We can use hidg_desc struct here but we should not relay | ||
645 | * that its content won't change after returning from this function. | ||
646 | */ | ||
635 | hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT; | 647 | hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT; |
636 | hidg_desc.desc[0].wDescriptorLength = | 648 | hidg_desc.desc[0].wDescriptorLength = |
637 | cpu_to_le16(hidg->report_desc_length); | 649 | cpu_to_le16(hidg->report_desc_length); |