* [PATCH 0/2] Bugs fixing for USB composite gadget driver @ 2009-01-07 16:21 Bryan Wu 2009-01-07 16:21 ` [PATCH 1/2] usb: composite: Fix bug: should test set_alt function pointer before use it Bryan Wu 2009-01-07 16:21 ` [PATCH 2/2] usb: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index Bryan Wu 0 siblings, 2 replies; 5+ messages in thread From: Bryan Wu @ 2009-01-07 16:21 UTC (permalink / raw) To: gregkh; +Cc: linux-usb, linux-kernel Hi Greg, I found 2 issues when I was developing USB Audio gadget driver. Please take a look. Thanks -Bryan ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] usb: composite: Fix bug: should test set_alt function pointer before use it 2009-01-07 16:21 [PATCH 0/2] Bugs fixing for USB composite gadget driver Bryan Wu @ 2009-01-07 16:21 ` Bryan Wu 2009-01-24 5:59 ` David Brownell 2009-01-07 16:21 ` [PATCH 2/2] usb: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index Bryan Wu 1 sibling, 1 reply; 5+ messages in thread From: Bryan Wu @ 2009-01-07 16:21 UTC (permalink / raw) To: gregkh; +Cc: linux-usb, linux-kernel, Bryan Wu Signed-off-by: Bryan Wu <cooloney@kernel.org> --- drivers/usb/gadget/composite.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index f2da026..363951e 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -772,7 +772,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) f = cdev->config->interface[w_index]; if (!f) break; - if (w_value && !f->get_alt) + if (w_value && !f->set_alt) break; value = f->set_alt(f, w_index, w_value); break; -- 1.5.6 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] usb: composite: Fix bug: should test set_alt function pointer before use it 2009-01-07 16:21 ` [PATCH 1/2] usb: composite: Fix bug: should test set_alt function pointer before use it Bryan Wu @ 2009-01-24 5:59 ` David Brownell 0 siblings, 0 replies; 5+ messages in thread From: David Brownell @ 2009-01-24 5:59 UTC (permalink / raw) To: Bryan Wu; +Cc: gregkh, linux-usb, linux-kernel On Wednesday 07 January 2009, Bryan Wu wrote: > Signed-off-by: Bryan Wu <cooloney@kernel.org> Include a real patch comment -- "test the *correct* function pointer" would suffice, and: Acked-by: David Brownell <dbrownell@users.sourceforge.net> > --- > drivers/usb/gadget/composite.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c > index f2da026..363951e 100644 > --- a/drivers/usb/gadget/composite.c > +++ b/drivers/usb/gadget/composite.c > @@ -772,7 +772,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) > f = cdev->config->interface[w_index]; > if (!f) > break; > - if (w_value && !f->get_alt) > + if (w_value && !f->set_alt) > break; > value = f->set_alt(f, w_index, w_value); > break; > -- > 1.5.6 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] usb: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index 2009-01-07 16:21 [PATCH 0/2] Bugs fixing for USB composite gadget driver Bryan Wu 2009-01-07 16:21 ` [PATCH 1/2] usb: composite: Fix bug: should test set_alt function pointer before use it Bryan Wu @ 2009-01-07 16:21 ` Bryan Wu 2009-01-24 6:00 ` David Brownell 1 sibling, 1 reply; 5+ messages in thread From: Bryan Wu @ 2009-01-07 16:21 UTC (permalink / raw) To: gregkh; +Cc: linux-usb, linux-kernel, Bryan Wu 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: Bryan Wu <cooloney@kernel.org> --- drivers/usb/gadget/composite.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 363951e..5d11c29 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -683,6 +683,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) struct usb_request *req = cdev->req; int value = -EOPNOTSUPP; u16 w_index = le16_to_cpu(ctrl->wIndex); + u8 intf = w_index & 0xFF; u16 w_value = le16_to_cpu(ctrl->wValue); u16 w_length = le16_to_cpu(ctrl->wLength); struct usb_function *f = NULL; @@ -769,7 +770,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) goto unknown; if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) break; - f = cdev->config->interface[w_index]; + f = cdev->config->interface[intf]; if (!f) break; if (w_value && !f->set_alt) @@ -781,7 +782,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) goto unknown; if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) break; - f = cdev->config->interface[w_index]; + f = cdev->config->interface[intf]; if (!f) break; /* lots of interfaces only need altsetting zero... */ @@ -808,7 +809,7 @@ unknown: */ if ((ctrl->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { - f = cdev->config->interface[w_index]; + f = cdev->config->interface[intf]; if (f && f->setup) value = f->setup(f, ctrl); else -- 1.5.6 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] usb: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index 2009-01-07 16:21 ` [PATCH 2/2] usb: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index Bryan Wu @ 2009-01-24 6:00 ` David Brownell 0 siblings, 0 replies; 5+ messages in thread From: David Brownell @ 2009-01-24 6:00 UTC (permalink / raw) To: Bryan Wu; +Cc: gregkh, linux-usb, linux-kernel On Wednesday 07 January 2009, Bryan Wu wrote: > 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: Bryan Wu <cooloney@kernel.org> Acked-by: David Brownell <dbrownell@users.sourceforge.net> > --- > drivers/usb/gadget/composite.c | 7 ++++--- > 1 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c > index 363951e..5d11c29 100644 > --- a/drivers/usb/gadget/composite.c > +++ b/drivers/usb/gadget/composite.c > @@ -683,6 +683,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) > struct usb_request *req = cdev->req; > int value = -EOPNOTSUPP; > u16 w_index = le16_to_cpu(ctrl->wIndex); > + u8 intf = w_index & 0xFF; > u16 w_value = le16_to_cpu(ctrl->wValue); > u16 w_length = le16_to_cpu(ctrl->wLength); > struct usb_function *f = NULL; > @@ -769,7 +770,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) > goto unknown; > if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) > break; > - f = cdev->config->interface[w_index]; > + f = cdev->config->interface[intf]; > if (!f) > break; > if (w_value && !f->set_alt) > @@ -781,7 +782,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) > goto unknown; > if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) > break; > - f = cdev->config->interface[w_index]; > + f = cdev->config->interface[intf]; > if (!f) > break; > /* lots of interfaces only need altsetting zero... */ > @@ -808,7 +809,7 @@ unknown: > */ > if ((ctrl->bRequestType & USB_RECIP_MASK) > == USB_RECIP_INTERFACE) { > - f = cdev->config->interface[w_index]; > + f = cdev->config->interface[intf]; > if (f && f->setup) > value = f->setup(f, ctrl); > else > -- > 1.5.6 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-01-24 6:00 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-01-07 16:21 [PATCH 0/2] Bugs fixing for USB composite gadget driver Bryan Wu 2009-01-07 16:21 ` [PATCH 1/2] usb: composite: Fix bug: should test set_alt function pointer before use it Bryan Wu 2009-01-24 5:59 ` David Brownell 2009-01-07 16:21 ` [PATCH 2/2] usb: composite: Fix bug: low byte of w_index is the usb interface number not the whole 2 bytes of w_index Bryan Wu 2009-01-24 6:00 ` David Brownell
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox