Commit 8704fd73 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

USB: gadget: f_fs: remove likely/unlikely

They are used way too often in this file, in some ways that are actually
wrong.  Almost all of these are already known by the compiler and CPU so
just remove them all as none of these should be on any "hot paths" where
it actually matters.

Cc: Felipe Balbi <balbi@kernel.org>
Reported-by: default avatarPeter Chen <peter.chen@nxp.com>
Reviewed-by: default avatarPeter Chen <peter.chen@nxp.com>
Link: https://lore.kernel.org/r/20201127140559.381351-6-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a353397b
...@@ -296,11 +296,11 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) ...@@ -296,11 +296,11 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
reinit_completion(&ffs->ep0req_completion); reinit_completion(&ffs->ep0req_completion);
ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
if (unlikely(ret < 0)) if (ret < 0)
return ret; return ret;
ret = wait_for_completion_interruptible(&ffs->ep0req_completion); ret = wait_for_completion_interruptible(&ffs->ep0req_completion);
if (unlikely(ret)) { if (ret) {
usb_ep_dequeue(ffs->gadget->ep0, req); usb_ep_dequeue(ffs->gadget->ep0, req);
return -EINTR; return -EINTR;
} }
...@@ -337,7 +337,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, ...@@ -337,7 +337,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
/* Acquire mutex */ /* Acquire mutex */
ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
if (unlikely(ret < 0)) if (ret < 0)
return ret; return ret;
/* Check state */ /* Check state */
...@@ -345,7 +345,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, ...@@ -345,7 +345,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
case FFS_READ_DESCRIPTORS: case FFS_READ_DESCRIPTORS:
case FFS_READ_STRINGS: case FFS_READ_STRINGS:
/* Copy data */ /* Copy data */
if (unlikely(len < 16)) { if (len < 16) {
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
...@@ -360,7 +360,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, ...@@ -360,7 +360,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
if (ffs->state == FFS_READ_DESCRIPTORS) { if (ffs->state == FFS_READ_DESCRIPTORS) {
pr_info("read descriptors\n"); pr_info("read descriptors\n");
ret = __ffs_data_got_descs(ffs, data, len); ret = __ffs_data_got_descs(ffs, data, len);
if (unlikely(ret < 0)) if (ret < 0)
break; break;
ffs->state = FFS_READ_STRINGS; ffs->state = FFS_READ_STRINGS;
...@@ -368,11 +368,11 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, ...@@ -368,11 +368,11 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
} else { } else {
pr_info("read strings\n"); pr_info("read strings\n");
ret = __ffs_data_got_strings(ffs, data, len); ret = __ffs_data_got_strings(ffs, data, len);
if (unlikely(ret < 0)) if (ret < 0)
break; break;
ret = ffs_epfiles_create(ffs); ret = ffs_epfiles_create(ffs);
if (unlikely(ret)) { if (ret) {
ffs->state = FFS_CLOSING; ffs->state = FFS_CLOSING;
break; break;
} }
...@@ -381,7 +381,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, ...@@ -381,7 +381,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
mutex_unlock(&ffs->mutex); mutex_unlock(&ffs->mutex);
ret = ffs_ready(ffs); ret = ffs_ready(ffs);
if (unlikely(ret < 0)) { if (ret < 0) {
ffs->state = FFS_CLOSING; ffs->state = FFS_CLOSING;
return ret; return ret;
} }
...@@ -495,7 +495,7 @@ static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf, ...@@ -495,7 +495,7 @@ static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
spin_unlock_irq(&ffs->ev.waitq.lock); spin_unlock_irq(&ffs->ev.waitq.lock);
mutex_unlock(&ffs->mutex); mutex_unlock(&ffs->mutex);
return unlikely(copy_to_user(buf, events, size)) ? -EFAULT : size; return copy_to_user(buf, events, size) ? -EFAULT : size;
} }
static ssize_t ffs_ep0_read(struct file *file, char __user *buf, static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
...@@ -514,7 +514,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, ...@@ -514,7 +514,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
/* Acquire mutex */ /* Acquire mutex */
ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
if (unlikely(ret < 0)) if (ret < 0)
return ret; return ret;
/* Check state */ /* Check state */
...@@ -536,7 +536,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, ...@@ -536,7 +536,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
case FFS_NO_SETUP: case FFS_NO_SETUP:
n = len / sizeof(struct usb_functionfs_event); n = len / sizeof(struct usb_functionfs_event);
if (unlikely(!n)) { if (!n) {
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
...@@ -567,9 +567,9 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, ...@@ -567,9 +567,9 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
spin_unlock_irq(&ffs->ev.waitq.lock); spin_unlock_irq(&ffs->ev.waitq.lock);
if (likely(len)) { if (len) {
data = kmalloc(len, GFP_KERNEL); data = kmalloc(len, GFP_KERNEL);
if (unlikely(!data)) { if (!data) {
ret = -ENOMEM; ret = -ENOMEM;
goto done_mutex; goto done_mutex;
} }
...@@ -586,7 +586,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf, ...@@ -586,7 +586,7 @@ static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
/* unlocks spinlock */ /* unlocks spinlock */
ret = __ffs_ep0_queue_wait(ffs, data, len); ret = __ffs_ep0_queue_wait(ffs, data, len);
if (likely(ret > 0) && unlikely(copy_to_user(buf, data, len))) if ((ret > 0) && (copy_to_user(buf, data, len)))
ret = -EFAULT; ret = -EFAULT;
goto done_mutex; goto done_mutex;
...@@ -608,7 +608,7 @@ static int ffs_ep0_open(struct inode *inode, struct file *file) ...@@ -608,7 +608,7 @@ static int ffs_ep0_open(struct inode *inode, struct file *file)
ENTER(); ENTER();
if (unlikely(ffs->state == FFS_CLOSING)) if (ffs->state == FFS_CLOSING)
return -EBUSY; return -EBUSY;
file->private_data = ffs; file->private_data = ffs;
...@@ -657,7 +657,7 @@ static __poll_t ffs_ep0_poll(struct file *file, poll_table *wait) ...@@ -657,7 +657,7 @@ static __poll_t ffs_ep0_poll(struct file *file, poll_table *wait)
poll_wait(file, &ffs->ev.waitq, wait); poll_wait(file, &ffs->ev.waitq, wait);
ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK); ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
if (unlikely(ret < 0)) if (ret < 0)
return mask; return mask;
switch (ffs->state) { switch (ffs->state) {
...@@ -708,7 +708,7 @@ static const struct file_operations ffs_ep0_operations = { ...@@ -708,7 +708,7 @@ static const struct file_operations ffs_ep0_operations = {
static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
{ {
ENTER(); ENTER();
if (likely(req->context)) { if (req->context) {
struct ffs_ep *ep = _ep->driver_data; struct ffs_ep *ep = _ep->driver_data;
ep->status = req->status ? req->status : req->actual; ep->status = req->status ? req->status : req->actual;
complete(req->context); complete(req->context);
...@@ -718,10 +718,10 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) ...@@ -718,10 +718,10 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
static ssize_t ffs_copy_to_iter(void *data, int data_len, struct iov_iter *iter) static ssize_t ffs_copy_to_iter(void *data, int data_len, struct iov_iter *iter)
{ {
ssize_t ret = copy_to_iter(data, data_len, iter); ssize_t ret = copy_to_iter(data, data_len, iter);
if (likely(ret == data_len)) if (ret == data_len)
return ret; return ret;
if (unlikely(iov_iter_count(iter))) if (iov_iter_count(iter))
return -EFAULT; return -EFAULT;
/* /*
...@@ -887,7 +887,7 @@ static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile, ...@@ -887,7 +887,7 @@ static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile,
return ret; return ret;
} }
if (unlikely(iov_iter_count(iter))) { if (iov_iter_count(iter)) {
ret = -EFAULT; ret = -EFAULT;
} else { } else {
buf->length -= ret; buf->length -= ret;
...@@ -908,10 +908,10 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile, ...@@ -908,10 +908,10 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile,
struct ffs_buffer *buf; struct ffs_buffer *buf;
ssize_t ret = copy_to_iter(data, data_len, iter); ssize_t ret = copy_to_iter(data, data_len, iter);
if (likely(data_len == ret)) if (data_len == ret)
return ret; return ret;
if (unlikely(iov_iter_count(iter))) if (iov_iter_count(iter))
return -EFAULT; return -EFAULT;
/* See ffs_copy_to_iter for more context. */ /* See ffs_copy_to_iter for more context. */
...@@ -932,7 +932,7 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile, ...@@ -932,7 +932,7 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile,
* in struct ffs_epfile for full read_buffer pointer synchronisation * in struct ffs_epfile for full read_buffer pointer synchronisation
* story. * story.
*/ */
if (unlikely(cmpxchg(&epfile->read_buffer, NULL, buf))) if (cmpxchg(&epfile->read_buffer, NULL, buf))
kfree(buf); kfree(buf);
return ret; return ret;
...@@ -970,7 +970,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -970,7 +970,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
/* We will be using request and read_buffer */ /* We will be using request and read_buffer */
ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK);
if (unlikely(ret)) if (ret)
goto error; goto error;
/* Allocate & copy */ /* Allocate & copy */
...@@ -1015,7 +1015,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -1015,7 +1015,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
spin_unlock_irq(&epfile->ffs->eps_lock); spin_unlock_irq(&epfile->ffs->eps_lock);
data = ffs_alloc_buffer(io_data, data_len); data = ffs_alloc_buffer(io_data, data_len);
if (unlikely(!data)) { if (!data) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_mutex; goto error_mutex;
} }
...@@ -1035,7 +1035,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -1035,7 +1035,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
ret = usb_ep_set_halt(ep->ep); ret = usb_ep_set_halt(ep->ep);
if (!ret) if (!ret)
ret = -EBADMSG; ret = -EBADMSG;
} else if (unlikely(data_len == -EINVAL)) { } else if (data_len == -EINVAL) {
/* /*
* Sanity Check: even though data_len can't be used * Sanity Check: even though data_len can't be used
* uninitialized at the time I write this comment, some * uninitialized at the time I write this comment, some
...@@ -1070,12 +1070,12 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -1070,12 +1070,12 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
req->complete = ffs_epfile_io_complete; req->complete = ffs_epfile_io_complete;
ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
if (unlikely(ret < 0)) if (ret < 0)
goto error_lock; goto error_lock;
spin_unlock_irq(&epfile->ffs->eps_lock); spin_unlock_irq(&epfile->ffs->eps_lock);
if (unlikely(wait_for_completion_interruptible(&done))) { if (wait_for_completion_interruptible(&done)) {
/* /*
* To avoid race condition with ffs_epfile_io_complete, * To avoid race condition with ffs_epfile_io_complete,
* dequeue the request first then check * dequeue the request first then check
...@@ -1117,7 +1117,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -1117,7 +1117,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
req->complete = ffs_epfile_async_io_complete; req->complete = ffs_epfile_async_io_complete;
ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
if (unlikely(ret)) { if (ret) {
io_data->req = NULL; io_data->req = NULL;
usb_ep_free_request(ep->ep, req); usb_ep_free_request(ep->ep, req);
goto error_lock; goto error_lock;
...@@ -1168,7 +1168,7 @@ static int ffs_aio_cancel(struct kiocb *kiocb) ...@@ -1168,7 +1168,7 @@ static int ffs_aio_cancel(struct kiocb *kiocb)
spin_lock_irqsave(&epfile->ffs->eps_lock, flags); spin_lock_irqsave(&epfile->ffs->eps_lock, flags);
if (likely(io_data && io_data->ep && io_data->req)) if (io_data && io_data->ep && io_data->req)
value = usb_ep_dequeue(io_data->ep, io_data->req); value = usb_ep_dequeue(io_data->ep, io_data->req);
else else
value = -EINVAL; value = -EINVAL;
...@@ -1187,7 +1187,7 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from) ...@@ -1187,7 +1187,7 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from)
if (!is_sync_kiocb(kiocb)) { if (!is_sync_kiocb(kiocb)) {
p = kzalloc(sizeof(io_data), GFP_KERNEL); p = kzalloc(sizeof(io_data), GFP_KERNEL);
if (unlikely(!p)) if (!p)
return -ENOMEM; return -ENOMEM;
p->aio = true; p->aio = true;
} else { } else {
...@@ -1224,7 +1224,7 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to) ...@@ -1224,7 +1224,7 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to)
if (!is_sync_kiocb(kiocb)) { if (!is_sync_kiocb(kiocb)) {
p = kzalloc(sizeof(io_data), GFP_KERNEL); p = kzalloc(sizeof(io_data), GFP_KERNEL);
if (unlikely(!p)) if (!p)
return -ENOMEM; return -ENOMEM;
p->aio = true; p->aio = true;
} else { } else {
...@@ -1388,7 +1388,7 @@ ffs_sb_make_inode(struct super_block *sb, void *data, ...@@ -1388,7 +1388,7 @@ ffs_sb_make_inode(struct super_block *sb, void *data,
inode = new_inode(sb); inode = new_inode(sb);
if (likely(inode)) { if (inode) {
struct timespec64 ts = current_time(inode); struct timespec64 ts = current_time(inode);
inode->i_ino = get_next_ino(); inode->i_ino = get_next_ino();
...@@ -1420,11 +1420,11 @@ static struct dentry *ffs_sb_create_file(struct super_block *sb, ...@@ -1420,11 +1420,11 @@ static struct dentry *ffs_sb_create_file(struct super_block *sb,
ENTER(); ENTER();
dentry = d_alloc_name(sb->s_root, name); dentry = d_alloc_name(sb->s_root, name);
if (unlikely(!dentry)) if (!dentry)
return NULL; return NULL;
inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms);
if (unlikely(!inode)) { if (!inode) {
dput(dentry); dput(dentry);
return NULL; return NULL;
} }
...@@ -1471,12 +1471,11 @@ static int ffs_sb_fill(struct super_block *sb, struct fs_context *fc) ...@@ -1471,12 +1471,11 @@ static int ffs_sb_fill(struct super_block *sb, struct fs_context *fc)
&simple_dir_inode_operations, &simple_dir_inode_operations,
&data->perms); &data->perms);
sb->s_root = d_make_root(inode); sb->s_root = d_make_root(inode);
if (unlikely(!sb->s_root)) if (!sb->s_root)
return -ENOMEM; return -ENOMEM;
/* EP0 file */ /* EP0 file */
if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs, if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations))
&ffs_ep0_operations)))
return -ENOMEM; return -ENOMEM;
return 0; return 0;
...@@ -1564,13 +1563,13 @@ static int ffs_fs_get_tree(struct fs_context *fc) ...@@ -1564,13 +1563,13 @@ static int ffs_fs_get_tree(struct fs_context *fc)
return invalf(fc, "No source specified"); return invalf(fc, "No source specified");
ffs = ffs_data_new(fc->source); ffs = ffs_data_new(fc->source);
if (unlikely(!ffs)) if (!ffs)
return -ENOMEM; return -ENOMEM;
ffs->file_perms = ctx->perms; ffs->file_perms = ctx->perms;
ffs->no_disconnect = ctx->no_disconnect; ffs->no_disconnect = ctx->no_disconnect;
ffs->dev_name = kstrdup(fc->source, GFP_KERNEL); ffs->dev_name = kstrdup(fc->source, GFP_KERNEL);
if (unlikely(!ffs->dev_name)) { if (!ffs->dev_name) {
ffs_data_put(ffs); ffs_data_put(ffs);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1656,7 +1655,7 @@ static int functionfs_init(void) ...@@ -1656,7 +1655,7 @@ static int functionfs_init(void)
ENTER(); ENTER();
ret = register_filesystem(&ffs_fs_type); ret = register_filesystem(&ffs_fs_type);
if (likely(!ret)) if (!ret)
pr_info("file system registered\n"); pr_info("file system registered\n");
else else
pr_err("failed registering file system (%d)\n", ret); pr_err("failed registering file system (%d)\n", ret);
...@@ -1701,7 +1700,7 @@ static void ffs_data_put(struct ffs_data *ffs) ...@@ -1701,7 +1700,7 @@ static void ffs_data_put(struct ffs_data *ffs)
{ {
ENTER(); ENTER();
if (unlikely(refcount_dec_and_test(&ffs->ref))) { if (refcount_dec_and_test(&ffs->ref)) {
pr_info("%s(): freeing\n", __func__); pr_info("%s(): freeing\n", __func__);
ffs_data_clear(ffs); ffs_data_clear(ffs);
BUG_ON(waitqueue_active(&ffs->ev.waitq) || BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
...@@ -1743,7 +1742,7 @@ static void ffs_data_closed(struct ffs_data *ffs) ...@@ -1743,7 +1742,7 @@ static void ffs_data_closed(struct ffs_data *ffs)
static struct ffs_data *ffs_data_new(const char *dev_name) static struct ffs_data *ffs_data_new(const char *dev_name)
{ {
struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL);
if (unlikely(!ffs)) if (!ffs)
return NULL; return NULL;
ENTER(); ENTER();
...@@ -1833,11 +1832,11 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) ...@@ -1833,11 +1832,11 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
return -EBADFD; return -EBADFD;
first_id = usb_string_ids_n(cdev, ffs->strings_count); first_id = usb_string_ids_n(cdev, ffs->strings_count);
if (unlikely(first_id < 0)) if (first_id < 0)
return first_id; return first_id;
ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
if (unlikely(!ffs->ep0req)) if (!ffs->ep0req)
return -ENOMEM; return -ENOMEM;
ffs->ep0req->complete = ffs_ep0_complete; ffs->ep0req->complete = ffs_ep0_complete;
ffs->ep0req->context = ffs; ffs->ep0req->context = ffs;
...@@ -1893,7 +1892,7 @@ static int ffs_epfiles_create(struct ffs_data *ffs) ...@@ -1893,7 +1892,7 @@ static int ffs_epfiles_create(struct ffs_data *ffs)
epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name,
epfile, epfile,
&ffs_epfile_operations); &ffs_epfile_operations);
if (unlikely(!epfile->dentry)) { if (!epfile->dentry) {
ffs_epfiles_destroy(epfiles, i - 1); ffs_epfiles_destroy(epfiles, i - 1);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1931,7 +1930,7 @@ static void ffs_func_eps_disable(struct ffs_function *func) ...@@ -1931,7 +1930,7 @@ static void ffs_func_eps_disable(struct ffs_function *func)
spin_lock_irqsave(&func->ffs->eps_lock, flags); spin_lock_irqsave(&func->ffs->eps_lock, flags);
while (count--) { while (count--) {
/* pending requests get nuked */ /* pending requests get nuked */
if (likely(ep->ep)) if (ep->ep)
usb_ep_disable(ep->ep); usb_ep_disable(ep->ep);
++ep; ++ep;
...@@ -1965,7 +1964,7 @@ static int ffs_func_eps_enable(struct ffs_function *func) ...@@ -1965,7 +1964,7 @@ static int ffs_func_eps_enable(struct ffs_function *func)
} }
ret = usb_ep_enable(ep->ep); ret = usb_ep_enable(ep->ep);
if (likely(!ret)) { if (!ret) {
epfile->ep = ep; epfile->ep = ep;
epfile->in = usb_endpoint_dir_in(ep->ep->desc); epfile->in = usb_endpoint_dir_in(ep->ep->desc);
epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc); epfile->isoc = usb_endpoint_xfer_isoc(ep->ep->desc);
...@@ -2038,12 +2037,12 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len, ...@@ -2038,12 +2037,12 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len,
#define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK) #define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK)
#define __entity(type, val) do { \ #define __entity(type, val) do { \
pr_vdebug("entity " #type "(%02x)\n", (val)); \ pr_vdebug("entity " #type "(%02x)\n", (val)); \
if (unlikely(!__entity_check_ ##type(val))) { \ if (!__entity_check_ ##type(val)) { \
pr_vdebug("invalid entity's value\n"); \ pr_vdebug("invalid entity's value\n"); \
return -EINVAL; \ return -EINVAL; \
} \ } \
ret = entity(FFS_ ##type, &val, _ds, priv); \ ret = entity(FFS_ ##type, &val, _ds, priv); \
if (unlikely(ret < 0)) { \ if (ret < 0) { \
pr_debug("entity " #type "(%02x); ret = %d\n", \ pr_debug("entity " #type "(%02x); ret = %d\n", \
(val), ret); \ (val), ret); \
return ret; \ return ret; \
...@@ -2168,7 +2167,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, ...@@ -2168,7 +2167,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
/* Record "descriptor" entity */ /* Record "descriptor" entity */
ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv);
if (unlikely(ret < 0)) { if (ret < 0) {
pr_debug("entity DESCRIPTOR(%02lx); ret = %d\n", pr_debug("entity DESCRIPTOR(%02lx); ret = %d\n",
num, ret); num, ret);
return ret; return ret;
...@@ -2179,7 +2178,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, ...@@ -2179,7 +2178,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
ret = ffs_do_single_desc(data, len, entity, priv, ret = ffs_do_single_desc(data, len, entity, priv,
&current_class); &current_class);
if (unlikely(ret < 0)) { if (ret < 0) {
pr_debug("%s returns %d\n", __func__, ret); pr_debug("%s returns %d\n", __func__, ret);
return ret; return ret;
} }
...@@ -2285,7 +2284,7 @@ static int __must_check ffs_do_single_os_desc(char *data, unsigned len, ...@@ -2285,7 +2284,7 @@ static int __must_check ffs_do_single_os_desc(char *data, unsigned len,
/* loop over all ext compat/ext prop descriptors */ /* loop over all ext compat/ext prop descriptors */
while (feature_count--) { while (feature_count--) {
ret = entity(type, h, data, len, priv); ret = entity(type, h, data, len, priv);
if (unlikely(ret < 0)) { if (ret < 0) {
pr_debug("bad OS descriptor, type: %d\n", type); pr_debug("bad OS descriptor, type: %d\n", type);
return ret; return ret;
} }
...@@ -2325,7 +2324,7 @@ static int __must_check ffs_do_os_descs(unsigned count, ...@@ -2325,7 +2324,7 @@ static int __must_check ffs_do_os_descs(unsigned count,
return -EINVAL; return -EINVAL;
ret = __ffs_do_os_desc_header(&type, desc); ret = __ffs_do_os_desc_header(&type, desc);
if (unlikely(ret < 0)) { if (ret < 0) {
pr_debug("entity OS_DESCRIPTOR(%02lx); ret = %d\n", pr_debug("entity OS_DESCRIPTOR(%02lx); ret = %d\n",
num, ret); num, ret);
return ret; return ret;
...@@ -2346,7 +2345,7 @@ static int __must_check ffs_do_os_descs(unsigned count, ...@@ -2346,7 +2345,7 @@ static int __must_check ffs_do_os_descs(unsigned count,
*/ */
ret = ffs_do_single_os_desc(data, len, type, ret = ffs_do_single_os_desc(data, len, type,
feature_count, entity, priv, desc); feature_count, entity, priv, desc);
if (unlikely(ret < 0)) { if (ret < 0) {
pr_debug("%s returns %d\n", __func__, ret); pr_debug("%s returns %d\n", __func__, ret);
return ret; return ret;
} }
...@@ -2578,20 +2577,20 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, ...@@ -2578,20 +2577,20 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
ENTER(); ENTER();
if (unlikely(len < 16 || if (len < 16 ||
get_unaligned_le32(data) != FUNCTIONFS_STRINGS_MAGIC || get_unaligned_le32(data) != FUNCTIONFS_STRINGS_MAGIC ||
get_unaligned_le32(data + 4) != len)) get_unaligned_le32(data + 4) != len)
goto error; goto error;
str_count = get_unaligned_le32(data + 8); str_count = get_unaligned_le32(data + 8);
lang_count = get_unaligned_le32(data + 12); lang_count = get_unaligned_le32(data + 12);
/* if one is zero the other must be zero */ /* if one is zero the other must be zero */
if (unlikely(!str_count != !lang_count)) if (!str_count != !lang_count)
goto error; goto error;
/* Do we have at least as many strings as descriptors need? */ /* Do we have at least as many strings as descriptors need? */
needed_count = ffs->strings_count; needed_count = ffs->strings_count;
if (unlikely(str_count < needed_count)) if (str_count < needed_count)
goto error; goto error;
/* /*
...@@ -2615,7 +2614,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, ...@@ -2615,7 +2614,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL);
if (unlikely(!vlabuf)) { if (!vlabuf) {
kfree(_data); kfree(_data);
return -ENOMEM; return -ENOMEM;
} }
...@@ -2642,7 +2641,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, ...@@ -2642,7 +2641,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
do { /* lang_count > 0 so we can use do-while */ do { /* lang_count > 0 so we can use do-while */
unsigned needed = needed_count; unsigned needed = needed_count;
if (unlikely(len < 3)) if (len < 3)
goto error_free; goto error_free;
t->language = get_unaligned_le16(data); t->language = get_unaligned_le16(data);
t->strings = s; t->strings = s;
...@@ -2655,7 +2654,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, ...@@ -2655,7 +2654,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
do { /* str_count > 0 so we can use do-while */ do { /* str_count > 0 so we can use do-while */
size_t length = strnlen(data, len); size_t length = strnlen(data, len);
if (unlikely(length == len)) if (length == len)
goto error_free; goto error_free;
/* /*
...@@ -2663,7 +2662,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, ...@@ -2663,7 +2662,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
* if that's the case we simply ignore the * if that's the case we simply ignore the
* rest * rest
*/ */
if (likely(needed)) { if (needed) {
/* /*
* s->id will be set while adding * s->id will be set while adding
* function to configuration so for * function to configuration so for
...@@ -2685,7 +2684,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, ...@@ -2685,7 +2684,7 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
} while (--lang_count); } while (--lang_count);
/* Some garbage left? */ /* Some garbage left? */
if (unlikely(len)) if (len)
goto error_free; goto error_free;
/* Done! */ /* Done! */
...@@ -2832,7 +2831,7 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, ...@@ -2832,7 +2831,7 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
ffs_ep = func->eps + idx; ffs_ep = func->eps + idx;
if (unlikely(ffs_ep->descs[ep_desc_id])) { if (ffs_ep->descs[ep_desc_id]) {
pr_err("two %sspeed descriptors for EP %d\n", pr_err("two %sspeed descriptors for EP %d\n",
speed_names[ep_desc_id], speed_names[ep_desc_id],
ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
...@@ -2863,12 +2862,12 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, ...@@ -2863,12 +2862,12 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
wMaxPacketSize = ds->wMaxPacketSize; wMaxPacketSize = ds->wMaxPacketSize;
pr_vdebug("autoconfig\n"); pr_vdebug("autoconfig\n");
ep = usb_ep_autoconfig(func->gadget, ds); ep = usb_ep_autoconfig(func->gadget, ds);
if (unlikely(!ep)) if (!ep)
return -ENOTSUPP; return -ENOTSUPP;
ep->driver_data = func->eps + idx; ep->driver_data = func->eps + idx;
req = usb_ep_alloc_request(ep, GFP_KERNEL); req = usb_ep_alloc_request(ep, GFP_KERNEL);
if (unlikely(!req)) if (!req)
return -ENOMEM; return -ENOMEM;
ffs_ep->ep = ep; ffs_ep->ep = ep;
...@@ -2910,7 +2909,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, ...@@ -2910,7 +2909,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
idx = *valuep; idx = *valuep;
if (func->interfaces_nums[idx] < 0) { if (func->interfaces_nums[idx] < 0) {
int id = usb_interface_id(func->conf, &func->function); int id = usb_interface_id(func->conf, &func->function);
if (unlikely(id < 0)) if (id < 0)
return id; return id;
func->interfaces_nums[idx] = id; func->interfaces_nums[idx] = id;
} }
...@@ -2931,7 +2930,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, ...@@ -2931,7 +2930,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
return 0; return 0;
idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1; idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1;
if (unlikely(!func->eps[idx].ep)) if (!func->eps[idx].ep)
return -EINVAL; return -EINVAL;
{ {
...@@ -3114,12 +3113,12 @@ static int _ffs_func_bind(struct usb_configuration *c, ...@@ -3114,12 +3113,12 @@ static int _ffs_func_bind(struct usb_configuration *c,
ENTER(); ENTER();
/* Has descriptors only for speeds gadget does not support */ /* Has descriptors only for speeds gadget does not support */
if (unlikely(!(full | high | super))) if (!(full | high | super))
return -ENOTSUPP; return -ENOTSUPP;
/* Allocate a single chunk, less management later on */ /* Allocate a single chunk, less management later on */
vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL); vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL);
if (unlikely(!vlabuf)) if (!vlabuf)
return -ENOMEM; return -ENOMEM;
ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop); ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop);
...@@ -3148,13 +3147,13 @@ static int _ffs_func_bind(struct usb_configuration *c, ...@@ -3148,13 +3147,13 @@ static int _ffs_func_bind(struct usb_configuration *c,
* endpoints first, so that later we can rewrite the endpoint * endpoints first, so that later we can rewrite the endpoint
* numbers without worrying that it may be described later on. * numbers without worrying that it may be described later on.
*/ */
if (likely(full)) { if (full) {
func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs);
fs_len = ffs_do_descs(ffs->fs_descs_count, fs_len = ffs_do_descs(ffs->fs_descs_count,
vla_ptr(vlabuf, d, raw_descs), vla_ptr(vlabuf, d, raw_descs),
d_raw_descs__sz, d_raw_descs__sz,
__ffs_func_bind_do_descs, func); __ffs_func_bind_do_descs, func);
if (unlikely(fs_len < 0)) { if (fs_len < 0) {
ret = fs_len; ret = fs_len;
goto error; goto error;
} }
...@@ -3162,13 +3161,13 @@ static int _ffs_func_bind(struct usb_configuration *c, ...@@ -3162,13 +3161,13 @@ static int _ffs_func_bind(struct usb_configuration *c,
fs_len = 0; fs_len = 0;
} }
if (likely(high)) { if (high) {
func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs);
hs_len = ffs_do_descs(ffs->hs_descs_count, hs_len = ffs_do_descs(ffs->hs_descs_count,
vla_ptr(vlabuf, d, raw_descs) + fs_len, vla_ptr(vlabuf, d, raw_descs) + fs_len,
d_raw_descs__sz - fs_len, d_raw_descs__sz - fs_len,
__ffs_func_bind_do_descs, func); __ffs_func_bind_do_descs, func);
if (unlikely(hs_len < 0)) { if (hs_len < 0) {
ret = hs_len; ret = hs_len;
goto error; goto error;
} }
...@@ -3176,14 +3175,14 @@ static int _ffs_func_bind(struct usb_configuration *c, ...@@ -3176,14 +3175,14 @@ static int _ffs_func_bind(struct usb_configuration *c,
hs_len = 0; hs_len = 0;
} }
if (likely(super)) { if (super) {
func->function.ss_descriptors = func->function.ssp_descriptors = func->function.ss_descriptors = func->function.ssp_descriptors =
vla_ptr(vlabuf, d, ss_descs); vla_ptr(vlabuf, d, ss_descs);
ss_len = ffs_do_descs(ffs->ss_descs_count, ss_len = ffs_do_descs(ffs->ss_descs_count,
vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len, vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len,
d_raw_descs__sz - fs_len - hs_len, d_raw_descs__sz - fs_len - hs_len,
__ffs_func_bind_do_descs, func); __ffs_func_bind_do_descs, func);
if (unlikely(ss_len < 0)) { if (ss_len < 0) {
ret = ss_len; ret = ss_len;
goto error; goto error;
} }
...@@ -3201,7 +3200,7 @@ static int _ffs_func_bind(struct usb_configuration *c, ...@@ -3201,7 +3200,7 @@ static int _ffs_func_bind(struct usb_configuration *c,
(super ? ffs->ss_descs_count : 0), (super ? ffs->ss_descs_count : 0),
vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz,
__ffs_func_bind_do_nums, func); __ffs_func_bind_do_nums, func);
if (unlikely(ret < 0)) if (ret < 0)
goto error; goto error;
func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table); func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table);
...@@ -3222,7 +3221,7 @@ static int _ffs_func_bind(struct usb_configuration *c, ...@@ -3222,7 +3221,7 @@ static int _ffs_func_bind(struct usb_configuration *c,
d_raw_descs__sz - fs_len - hs_len - d_raw_descs__sz - fs_len - hs_len -
ss_len, ss_len,
__ffs_func_bind_do_os_desc, func); __ffs_func_bind_do_os_desc, func);
if (unlikely(ret < 0)) if (ret < 0)
goto error; goto error;
} }
func->function.os_desc_n = func->function.os_desc_n =
...@@ -3273,7 +3272,7 @@ static int ffs_func_set_alt(struct usb_function *f, ...@@ -3273,7 +3272,7 @@ static int ffs_func_set_alt(struct usb_function *f,
if (alt != (unsigned)-1) { if (alt != (unsigned)-1) {
intf = ffs_func_revmap_intf(func, interface); intf = ffs_func_revmap_intf(func, interface);
if (unlikely(intf < 0)) if (intf < 0)
return intf; return intf;
} }
...@@ -3298,7 +3297,7 @@ static int ffs_func_set_alt(struct usb_function *f, ...@@ -3298,7 +3297,7 @@ static int ffs_func_set_alt(struct usb_function *f,
ffs->func = func; ffs->func = func;
ret = ffs_func_eps_enable(func); ret = ffs_func_eps_enable(func);
if (likely(ret >= 0)) if (ret >= 0)
ffs_event_add(ffs, FUNCTIONFS_ENABLE); ffs_event_add(ffs, FUNCTIONFS_ENABLE);
return ret; return ret;
} }
...@@ -3340,13 +3339,13 @@ static int ffs_func_setup(struct usb_function *f, ...@@ -3340,13 +3339,13 @@ static int ffs_func_setup(struct usb_function *f,
switch (creq->bRequestType & USB_RECIP_MASK) { switch (creq->bRequestType & USB_RECIP_MASK) {
case USB_RECIP_INTERFACE: case USB_RECIP_INTERFACE:
ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex)); ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex));
if (unlikely(ret < 0)) if (ret < 0)
return ret; return ret;
break; break;
case USB_RECIP_ENDPOINT: case USB_RECIP_ENDPOINT:
ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex));
if (unlikely(ret < 0)) if (ret < 0)
return ret; return ret;
if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
ret = func->ffs->eps_addrmap[ret]; ret = func->ffs->eps_addrmap[ret];
...@@ -3601,7 +3600,7 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi) ...@@ -3601,7 +3600,7 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi)
ENTER(); ENTER();
func = kzalloc(sizeof(*func), GFP_KERNEL); func = kzalloc(sizeof(*func), GFP_KERNEL);
if (unlikely(!func)) if (!func)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
func->function.name = "Function FS Gadget"; func->function.name = "Function FS Gadget";
...@@ -3816,7 +3815,7 @@ static void ffs_closed(struct ffs_data *ffs) ...@@ -3816,7 +3815,7 @@ static void ffs_closed(struct ffs_data *ffs)
static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
{ {
return nonblock return nonblock
? likely(mutex_trylock(mutex)) ? 0 : -EAGAIN ? mutex_trylock(mutex) ? 0 : -EAGAIN
: mutex_lock_interruptible(mutex); : mutex_lock_interruptible(mutex);
} }
...@@ -3824,14 +3823,14 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len) ...@@ -3824,14 +3823,14 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)
{ {
char *data; char *data;
if (unlikely(!len)) if (!len)
return NULL; return NULL;
data = kmalloc(len, GFP_KERNEL); data = kmalloc(len, GFP_KERNEL);
if (unlikely(!data)) if (!data)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (unlikely(copy_from_user(data, buf, len))) { if (copy_from_user(data, buf, len)) {
kfree(data); kfree(data);
return ERR_PTR(-EFAULT); return ERR_PTR(-EFAULT);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment