提交 08889517 编写于 作者: B Bryan Wu 提交者: Greg Kroah-Hartman

USB: composite: Fix bug: low byte of w_index is the usb interface number not...

USB: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index

In some usb gadget driver, for example usb audio class device, the high
byte of w_index is the entity id and low byte is the interface number.
If we use the 2 bytes of w_index as the array number, we will get a
wrong pointer or NULL pointer.

This patch fixes this issue.
Signed-off-by: NBryan Wu <cooloney@kernel.org>
Acked-by: NDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 dd4dff8b
...@@ -683,6 +683,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -683,6 +683,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
struct usb_request *req = cdev->req; struct usb_request *req = cdev->req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
u16 w_index = le16_to_cpu(ctrl->wIndex); u16 w_index = le16_to_cpu(ctrl->wIndex);
u8 intf = w_index & 0xFF;
u16 w_value = le16_to_cpu(ctrl->wValue); u16 w_value = le16_to_cpu(ctrl->wValue);
u16 w_length = le16_to_cpu(ctrl->wLength); u16 w_length = le16_to_cpu(ctrl->wLength);
struct usb_function *f = NULL; struct usb_function *f = NULL;
...@@ -769,7 +770,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -769,7 +770,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
goto unknown; goto unknown;
if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
break; break;
f = cdev->config->interface[w_index]; f = cdev->config->interface[intf];
if (!f) if (!f)
break; break;
if (w_value && !f->set_alt) if (w_value && !f->set_alt)
...@@ -781,7 +782,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -781,7 +782,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
goto unknown; goto unknown;
if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES)
break; break;
f = cdev->config->interface[w_index]; f = cdev->config->interface[intf];
if (!f) if (!f)
break; break;
/* lots of interfaces only need altsetting zero... */ /* lots of interfaces only need altsetting zero... */
...@@ -808,7 +809,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -808,7 +809,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
*/ */
if ((ctrl->bRequestType & USB_RECIP_MASK) if ((ctrl->bRequestType & USB_RECIP_MASK)
== USB_RECIP_INTERFACE) { == USB_RECIP_INTERFACE) {
f = cdev->config->interface[w_index]; f = cdev->config->interface[intf];
if (f && f->setup) if (f && f->setup)
value = f->setup(f, ctrl); value = f->setup(f, ctrl);
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册