aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/gadget/file_storage.c19
-rw-r--r--drivers/usb/gadget/gmidi.c8
-rw-r--r--drivers/usb/gadget/inode.c4
-rw-r--r--drivers/usb/gadget/zero.c9
-rw-r--r--include/linux/usb_gadget.h41
5 files changed, 11 insertions, 70 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 7e650d015585..8712ef987179 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3733,19 +3733,12 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3733 } 3733 }
3734 3734
3735 /* Free the data buffers */ 3735 /* Free the data buffers */
3736 for (i = 0; i < NUM_BUFFERS; ++i) { 3736 for (i = 0; i < NUM_BUFFERS; ++i)
3737 struct fsg_buffhd *bh = &fsg->buffhds[i]; 3737 kfree(fsg->buffhds[i].buf);
3738
3739 if (bh->buf)
3740 usb_ep_free_buffer(fsg->bulk_in, bh->buf, bh->dma,
3741 mod_data.buflen);
3742 }
3743 3738
3744 /* Free the request and buffer for endpoint 0 */ 3739 /* Free the request and buffer for endpoint 0 */
3745 if (req) { 3740 if (req) {
3746 if (req->buf) 3741 kfree(req->buf);
3747 usb_ep_free_buffer(fsg->ep0, req->buf,
3748 req->dma, EP0_BUFSIZE);
3749 usb_ep_free_request(fsg->ep0, req); 3742 usb_ep_free_request(fsg->ep0, req);
3750 } 3743 }
3751 3744
@@ -3972,8 +3965,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3972 fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL); 3965 fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
3973 if (!req) 3966 if (!req)
3974 goto out; 3967 goto out;
3975 req->buf = usb_ep_alloc_buffer(fsg->ep0, EP0_BUFSIZE, 3968 req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
3976 &req->dma, GFP_KERNEL);
3977 if (!req->buf) 3969 if (!req->buf)
3978 goto out; 3970 goto out;
3979 req->complete = ep0_complete; 3971 req->complete = ep0_complete;
@@ -3985,8 +3977,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3985 /* Allocate for the bulk-in endpoint. We assume that 3977 /* Allocate for the bulk-in endpoint. We assume that
3986 * the buffer will also work with the bulk-out (and 3978 * the buffer will also work with the bulk-out (and
3987 * interrupt-in) endpoint. */ 3979 * interrupt-in) endpoint. */
3988 bh->buf = usb_ep_alloc_buffer(fsg->bulk_in, mod_data.buflen, 3980 bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
3989 &bh->dma, GFP_KERNEL);
3990 if (!bh->buf) 3981 if (!bh->buf)
3991 goto out; 3982 goto out;
3992 bh->next = bh + 1; 3983 bh->next = bh + 1;
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index d08a8d0e6427..1c5aa49d7432 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -1248,17 +1248,11 @@ autoconf_fail:
1248 tasklet_init(&dev->tasklet, gmidi_in_tasklet, (unsigned long)dev); 1248 tasklet_init(&dev->tasklet, gmidi_in_tasklet, (unsigned long)dev);
1249 1249
1250 /* preallocate control response and buffer */ 1250 /* preallocate control response and buffer */
1251 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); 1251 dev->req = alloc_ep_req(gadget->ep0, USB_BUFSIZ);
1252 if (!dev->req) { 1252 if (!dev->req) {
1253 err = -ENOMEM; 1253 err = -ENOMEM;
1254 goto fail; 1254 goto fail;
1255 } 1255 }
1256 dev->req->buf = usb_ep_alloc_buffer(gadget->ep0, USB_BUFSIZ,
1257 &dev->req->dma, GFP_KERNEL);
1258 if (!dev->req->buf) {
1259 err = -ENOMEM;
1260 goto fail;
1261 }
1262 1256
1263 dev->req->complete = gmidi_setup_complete; 1257 dev->req->complete = gmidi_setup_complete;
1264 1258
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index f723e083c9d0..e60745ffaf8e 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -923,7 +923,7 @@ static void clean_req (struct usb_ep *ep, struct usb_request *req)
923 struct dev_data *dev = ep->driver_data; 923 struct dev_data *dev = ep->driver_data;
924 924
925 if (req->buf != dev->rbuf) { 925 if (req->buf != dev->rbuf) {
926 usb_ep_free_buffer (ep, req->buf, req->dma, req->length); 926 kfree(req->buf);
927 req->buf = dev->rbuf; 927 req->buf = dev->rbuf;
928 req->dma = DMA_ADDR_INVALID; 928 req->dma = DMA_ADDR_INVALID;
929 } 929 }
@@ -963,7 +963,7 @@ static int setup_req (struct usb_ep *ep, struct usb_request *req, u16 len)
963 return -EBUSY; 963 return -EBUSY;
964 } 964 }
965 if (len > sizeof (dev->rbuf)) 965 if (len > sizeof (dev->rbuf))
966 req->buf = usb_ep_alloc_buffer (ep, len, &req->dma, GFP_ATOMIC); 966 req->buf = kmalloc(len, GFP_ATOMIC);
967 if (req->buf == 0) { 967 if (req->buf == 0) {
968 req->buf = dev->rbuf; 968 req->buf = dev->rbuf;
969 return -ENOMEM; 969 return -ENOMEM;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 7078374d0b79..a2e6e3fc8c8d 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -481,8 +481,7 @@ alloc_ep_req (struct usb_ep *ep, unsigned length)
481 req = usb_ep_alloc_request (ep, GFP_ATOMIC); 481 req = usb_ep_alloc_request (ep, GFP_ATOMIC);
482 if (req) { 482 if (req) {
483 req->length = length; 483 req->length = length;
484 req->buf = usb_ep_alloc_buffer (ep, length, 484 req->buf = kmalloc(length, GFP_ATOMIC);
485 &req->dma, GFP_ATOMIC);
486 if (!req->buf) { 485 if (!req->buf) {
487 usb_ep_free_request (ep, req); 486 usb_ep_free_request (ep, req);
488 req = NULL; 487 req = NULL;
@@ -493,8 +492,7 @@ alloc_ep_req (struct usb_ep *ep, unsigned length)
493 492
494static void free_ep_req (struct usb_ep *ep, struct usb_request *req) 493static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
495{ 494{
496 if (req->buf) 495 kfree(req->buf);
497 usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
498 usb_ep_free_request (ep, req); 496 usb_ep_free_request (ep, req);
499} 497}
500 498
@@ -1199,8 +1197,7 @@ autoconf_fail:
1199 dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); 1197 dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
1200 if (!dev->req) 1198 if (!dev->req)
1201 goto enomem; 1199 goto enomem;
1202 dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ, 1200 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
1203 &dev->req->dma, GFP_KERNEL);
1204 if (!dev->req->buf) 1201 if (!dev->req->buf)
1205 goto enomem; 1202 goto enomem;
1206 1203
diff --git a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h
index e17186dbcdca..703fd84c46fc 100644
--- a/include/linux/usb_gadget.h
+++ b/include/linux/usb_gadget.h
@@ -235,47 +235,6 @@ usb_ep_free_request (struct usb_ep *ep, struct usb_request *req)
235} 235}
236 236
237/** 237/**
238 * usb_ep_alloc_buffer - allocate an I/O buffer
239 * @ep:the endpoint associated with the buffer
240 * @len:length of the desired buffer
241 * @dma:pointer to the buffer's DMA address; must be valid
242 * @gfp_flags:GFP_* flags to use
243 *
244 * Returns a new buffer, or null if one could not be allocated.
245 * The buffer is suitably aligned for dma, if that endpoint uses DMA,
246 * and the caller won't have to care about dma-inconsistency
247 * or any hidden "bounce buffer" mechanism. No additional per-request
248 * DMA mapping will be required for such buffers.
249 * Free it later with usb_ep_free_buffer().
250 *
251 * You don't need to use this call to allocate I/O buffers unless you
252 * want to make sure drivers don't incur costs for such "bounce buffer"
253 * copies or per-request DMA mappings.
254 */
255static inline void *
256usb_ep_alloc_buffer (struct usb_ep *ep, unsigned len, dma_addr_t *dma,
257 gfp_t gfp_flags)
258{
259 return ep->ops->alloc_buffer (ep, len, dma, gfp_flags);
260}
261
262/**
263 * usb_ep_free_buffer - frees an i/o buffer
264 * @ep:the endpoint associated with the buffer
265 * @buf:CPU view address of the buffer
266 * @dma:the buffer's DMA address
267 * @len:length of the buffer
268 *
269 * reverses the effect of usb_ep_alloc_buffer().
270 * caller guarantees the buffer will no longer be accessed
271 */
272static inline void
273usb_ep_free_buffer (struct usb_ep *ep, void *buf, dma_addr_t dma, unsigned len)
274{
275 ep->ops->free_buffer (ep, buf, dma, len);
276}
277
278/**
279 * usb_ep_queue - queues (submits) an I/O request to an endpoint. 238 * usb_ep_queue - queues (submits) an I/O request to an endpoint.
280 * @ep:the endpoint associated with the request 239 * @ep:the endpoint associated with the request
281 * @req:the request being submitted 240 * @req:the request being submitted