blob: 907f8144813c31a467eae81b04ee6db8a8f481f2 [file] [log] [blame]
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +01001/*
2 * u_f.c -- USB function utilities for Gadget stack
3 *
4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 *
7 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010014#include "u_f.h"
Felipe F. Tonelloe0466152016-08-08 21:30:06 +010015#include <linux/usb/ch9.h>
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010016
Felipe F. Tonello69bb9972016-08-08 21:30:05 +010017struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len, int default_len)
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010018{
19 struct usb_request *req;
20
21 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
22 if (req) {
23 req->length = len ?: default_len;
Felipe F. Tonelloe0466152016-08-08 21:30:06 +010024 if (usb_endpoint_dir_out(ep->desc))
25 req->length = usb_ep_align(ep, req->length);
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010026 req->buf = kmalloc(req->length, GFP_ATOMIC);
27 if (!req->buf) {
28 usb_ep_free_request(ep, req);
29 req = NULL;
30 }
31 }
32 return req;
33}
Felipe Balbi0700faa2014-04-01 13:19:32 -050034EXPORT_SYMBOL_GPL(alloc_ep_req);