aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2015-10-14 17:03:34 -0400
committerFelipe Balbi <balbi@ti.com>2015-10-15 10:29:38 -0400
commit3e9d992f93fecc746baa9d4854acc026d422094f (patch)
tree0c6a0b9cc9ea29facd7da7e86d075baaaaae85d0
parent897ee0e85e5fad3109264af5b517a1ebb82912c3 (diff)
usb: gadget: loopback: fix: Don't share qlen and buflen between instances
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>
-rw-r--r--drivers/usb/gadget/function/f_loopback.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c
index abfdb92bde64..79e284bba059 100644
--- a/drivers/usb/gadget/function/f_loopback.c
+++ b/drivers/usb/gadget/function/f_loopback.c
@@ -34,6 +34,9 @@ struct f_loopback {
34 34
35 struct usb_ep *in_ep; 35 struct usb_ep *in_ep;
36 struct usb_ep *out_ep; 36 struct usb_ep *out_ep;
37
38 unsigned qlen;
39 unsigned buflen;
37}; 40};
38 41
39static inline struct f_loopback *func_to_loop(struct usb_function *f) 42static inline struct f_loopback *func_to_loop(struct usb_function *f)
@@ -41,13 +44,10 @@ static inline struct f_loopback *func_to_loop(struct usb_function *f)
41 return container_of(f, struct f_loopback, function); 44 return container_of(f, struct f_loopback, function);
42} 45}
43 46
44static unsigned qlen;
45static unsigned buflen;
46
47/*-------------------------------------------------------------------------*/ 47/*-------------------------------------------------------------------------*/
48 48
49static struct usb_interface_descriptor loopback_intf = { 49static struct usb_interface_descriptor loopback_intf = {
50 .bLength = sizeof loopback_intf, 50 .bLength = sizeof(loopback_intf),
51 .bDescriptorType = USB_DT_INTERFACE, 51 .bDescriptorType = USB_DT_INTERFACE,
52 52
53 .bNumEndpoints = 2, 53 .bNumEndpoints = 2,
@@ -251,7 +251,7 @@ static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
251 } 251 }
252 252
253 /* queue the buffer for some later OUT packet */ 253 /* queue the buffer for some later OUT packet */
254 req->length = buflen; 254 req->length = loop->buflen;
255 status = usb_ep_queue(ep, req, GFP_ATOMIC); 255 status = usb_ep_queue(ep, req, GFP_ATOMIC);
256 if (status == 0) 256 if (status == 0)
257 return; 257 return;
@@ -288,7 +288,9 @@ static void disable_loopback(struct f_loopback *loop)
288 288
289static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len) 289static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len)
290{ 290{
291 return alloc_ep_req(ep, len, buflen); 291 struct f_loopback *loop = ep->driver_data;
292
293 return alloc_ep_req(ep, len, loop->buflen);
292} 294}
293 295
294static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback *loop, 296static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback *loop,
@@ -315,7 +317,7 @@ static int enable_endpoint(struct usb_composite_dev *cdev, struct f_loopback *lo
315 * we buffer at most 'qlen' transfers; fewer if any need more 317 * we buffer at most 'qlen' transfers; fewer if any need more
316 * than 'buflen' bytes each. 318 * than 'buflen' bytes each.
317 */ 319 */
318 for (i = 0; i < qlen && result == 0; i++) { 320 for (i = 0; i < loop->qlen && result == 0; i++) {
319 req = lb_alloc_ep_req(ep, 0); 321 req = lb_alloc_ep_req(ep, 0);
320 if (!req) 322 if (!req)
321 goto fail1; 323 goto fail1;
@@ -388,10 +390,10 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi)
388 lb_opts->refcnt++; 390 lb_opts->refcnt++;
389 mutex_unlock(&lb_opts->lock); 391 mutex_unlock(&lb_opts->lock);
390 392
391 buflen = lb_opts->bulk_buflen; 393 loop->buflen = lb_opts->bulk_buflen;
392 qlen = lb_opts->qlen; 394 loop->qlen = lb_opts->qlen;
393 if (!qlen) 395 if (!loop->qlen)
394 qlen = 32; 396 loop->qlen = 32;
395 397
396 loop->function.name = "loopback"; 398 loop->function.name = "loopback";
397 loop->function.bind = loopback_bind; 399 loop->function.bind = loopback_bind;