Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed923f30 authored by ChandanaKishori Chiluveru's avatar ChandanaKishori Chiluveru Committed by Gerrit - the friendly Code Review server
Browse files

USB: f_fs: Increase the IN endpoint buffer allocation



Some UDC may require allocation of some extra bytes for
TX buffer due to hardware requirement. Add necessary
changes for the same.

Change-Id: I186cfc876f52e694113b895dfc4044948cb1fb2d
Signed-off-by: default avatarSujeet Kumar <ksujeet@codeaurora.org>
Signed-off-by: default avatarChandanaKishori Chiluveru <cchilu@codeaurora.org>
Signed-off-by: default avatarAjay Agarwal <ajaya@codeaurora.org>
parent 14681b57
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -281,7 +281,8 @@ static void ffs_closed(struct ffs_data *ffs);

static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
	__attribute__((warn_unused_result, nonnull));
static char *ffs_prepare_buffer(const char __user *buf, size_t len)
static char *ffs_prepare_buffer(const char __user *buf, size_t len,
	size_t extra_buf_alloc)
	__attribute__((warn_unused_result, nonnull));


@@ -357,6 +358,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
			     size_t len, loff_t *ptr)
{
	struct ffs_data *ffs = file->private_data;
	struct usb_gadget *gadget = ffs->gadget;
	ssize_t ret;
	char *data;

@@ -388,7 +390,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
			break;
		}

		data = ffs_prepare_buffer(buf, len);
		data = ffs_prepare_buffer(buf, len, 0);
		if (IS_ERR(data)) {
			ret = PTR_ERR(data);
			break;
@@ -460,7 +462,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,

		spin_unlock_irq(&ffs->ev.waitq.lock);

		data = ffs_prepare_buffer(buf, len);
		data = ffs_prepare_buffer(buf, len, gadget->extra_buf_alloc);
		if (IS_ERR(data)) {
			ret = PTR_ERR(data);
			break;
@@ -982,9 +984,11 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
	struct ffs_epfile *epfile = file->private_data;
	struct usb_request *req;
	struct ffs_ep *ep;
	struct ffs_data *ffs = epfile->ffs;
	char *data = NULL;
	ssize_t ret, data_len = -EINVAL;
	int halt;
	size_t extra_buf_alloc = 0;

	ffs_log("enter: epfile name %s epfile err %d (%s)", epfile->name,
		atomic_read(&epfile->error), io_data->read ? "READ" : "WRITE");
@@ -1075,6 +1079,11 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
			data_len = usb_ep_align_maybe(gadget, ep->ep, data_len);
		spin_unlock_irq(&epfile->ffs->eps_lock);

		extra_buf_alloc = ffs->gadget->extra_buf_alloc;
		if (io_data->read)
			data = kmalloc(data_len + extra_buf_alloc,
					GFP_KERNEL);
		else
			data = kmalloc(data_len, GFP_KERNEL);
		if (unlikely(!data)) {
			ret = -ENOMEM;
@@ -4370,14 +4379,23 @@ static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
		: mutex_lock_interruptible(mutex);
}

static char *ffs_prepare_buffer(const char __user *buf, size_t len)
/**
 * ffs_prepare_buffer() - copy userspace buffer into kernel.
 * @buf: userspace buffer
 * @len: length of the buffer
 * @extra_alloc_buf: Extra buffer allocation if required by UDC.
 *
 * This function returns pointer to the copied buffer
 */
static char *ffs_prepare_buffer(const char __user *buf, size_t len,
		size_t extra_buf_alloc)
{
	char *data;

	if (unlikely(!len))
		return NULL;

	data = kmalloc(len, GFP_KERNEL);
	data = kmalloc(len + extra_buf_alloc, GFP_KERNEL);
	if (unlikely(!data))
		return ERR_PTR(-ENOMEM);