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

Commit f6081cac authored by ChandanaKishori Chiluveru's avatar ChandanaKishori Chiluveru
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>
parent c42b6d72
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -188,7 +188,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));


@@ -254,6 +255,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;

@@ -278,7 +280,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;
@@ -351,7 +353,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;
@@ -710,9 +712,11 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
{
	struct ffs_epfile *epfile = file->private_data;
	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;

	pr_debug("%s: len %zu, read %d\n", __func__, io_data->len,
			io_data->read);
@@ -786,6 +790,11 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
			   io_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))
			return -ENOMEM;
@@ -3547,14 +3556,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);