Skip to content

Commit

Permalink
usb: gadget: loopback: fix: Don't share qlen and buflen between insta…
Browse files Browse the repository at this point in the history
…nces

Each instance of loopback function may have different qlen
and buflen attributes values. When linking function to
configuration those values had been assigned to global
variables. Linking other instance to config overwrites those
values.

This commit moves those values to f_loopback structure
to avoid overwriting. Now each function has its own instance
of those values.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Krzysztof Opasiak authored and Felipe Balbi committed Oct 15, 2015
1 parent 897ee0e commit 3e9d992
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions drivers/usb/gadget/function/f_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ struct f_loopback {

struct usb_ep *in_ep;
struct usb_ep *out_ep;

unsigned qlen;
unsigned buflen;
};

static inline struct f_loopback *func_to_loop(struct usb_function *f)
{
return container_of(f, struct f_loopback, function);
}

static unsigned qlen;
static unsigned buflen;

/*-------------------------------------------------------------------------*/

static struct usb_interface_descriptor loopback_intf = {
.bLength = sizeof loopback_intf,
.bLength = sizeof(loopback_intf),
.bDescriptorType = USB_DT_INTERFACE,

.bNumEndpoints = 2,
Expand Down Expand Up @@ -251,7 +251,7 @@ static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
}

/* queue the buffer for some later OUT packet */
req->length = buflen;
req->length = loop->buflen;
status = usb_ep_queue(ep, req, GFP_ATOMIC);
if (status == 0)
return;
Expand Down Expand Up @@ -288,7 +288,9 @@ static void disable_loopback(struct f_loopback *loop)

static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len)
{
return alloc_ep_req(ep, len, buflen);
struct f_loopback *loop = ep->driver_data;

return alloc_ep_req(ep, len, loop->buflen);
}

static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback *loop,
Expand All @@ -315,7 +317,7 @@ static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback *lo
* we buffer at most 'qlen' transfers; fewer if any need more
* than 'buflen' bytes each.
*/
for (i = 0; i < qlen && result == 0; i++) {
for (i = 0; i < loop->qlen && result == 0; i++) {
req = lb_alloc_ep_req(ep, 0);
if (!req)
goto fail1;
Expand Down Expand Up @@ -388,10 +390,10 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi)
lb_opts->refcnt++;
mutex_unlock(&lb_opts->lock);

buflen = lb_opts->bulk_buflen;
qlen = lb_opts->qlen;
if (!qlen)
qlen = 32;
loop->buflen = lb_opts->bulk_buflen;
loop->qlen = lb_opts->qlen;
if (!loop->qlen)
loop->qlen = 32;

loop->function.name = "loopback";
loop->function.bind = loopback_bind;
Expand Down

0 comments on commit 3e9d992

Please sign in to comment.