Commit e16828cf authored by Jerry Zhang's avatar Jerry Zhang Committed by Felipe Balbi

usb: gadget: function: f_fs: Move epfile waitqueue to ffs_data.

There were individual waitqueues for each epfile but eps_enable
would iterate through all of them, resulting in essentially the
same wakeup time.

The waitqueue represents the function being enabled, so a central
waitqueue in ffs_data makes more sense and is less redundant.

Also use wake_up_interruptible to reflect use of
wait_event_interruptible.
Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: default avatarJerry Zhang <zhangjerry@google.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 222155de
...@@ -127,7 +127,6 @@ struct ffs_ep { ...@@ -127,7 +127,6 @@ struct ffs_ep {
struct ffs_epfile { struct ffs_epfile {
/* Protects ep->ep and ep->req. */ /* Protects ep->ep and ep->req. */
struct mutex mutex; struct mutex mutex;
wait_queue_head_t wait;
struct ffs_data *ffs; struct ffs_data *ffs;
struct ffs_ep *ep; /* P: ffs->eps_lock */ struct ffs_ep *ep; /* P: ffs->eps_lock */
...@@ -889,7 +888,8 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ...@@ -889,7 +888,8 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_event_interruptible(epfile->wait, (ep = epfile->ep)); ret = wait_event_interruptible(
epfile->ffs->wait, (ep = epfile->ep));
if (ret) if (ret)
return -EINTR; return -EINTR;
} }
...@@ -1203,7 +1203,8 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code, ...@@ -1203,7 +1203,8 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_event_interruptible(epfile->wait, (ep = epfile->ep)); ret = wait_event_interruptible(
epfile->ffs->wait, (ep = epfile->ep));
if (ret) if (ret)
return -EINTR; return -EINTR;
} }
...@@ -1608,7 +1609,8 @@ static void ffs_data_put(struct ffs_data *ffs) ...@@ -1608,7 +1609,8 @@ static void ffs_data_put(struct ffs_data *ffs)
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) ||
waitqueue_active(&ffs->ep0req_completion.wait)); waitqueue_active(&ffs->ep0req_completion.wait) ||
waitqueue_active(&ffs->wait));
kfree(ffs->dev_name); kfree(ffs->dev_name);
kfree(ffs); kfree(ffs);
} }
...@@ -1655,6 +1657,7 @@ static struct ffs_data *ffs_data_new(void) ...@@ -1655,6 +1657,7 @@ static struct ffs_data *ffs_data_new(void)
mutex_init(&ffs->mutex); mutex_init(&ffs->mutex);
spin_lock_init(&ffs->eps_lock); spin_lock_init(&ffs->eps_lock);
init_waitqueue_head(&ffs->ev.waitq); init_waitqueue_head(&ffs->ev.waitq);
init_waitqueue_head(&ffs->wait);
init_completion(&ffs->ep0req_completion); init_completion(&ffs->ep0req_completion);
/* XXX REVISIT need to update it in some places, or do we? */ /* XXX REVISIT need to update it in some places, or do we? */
...@@ -1776,7 +1779,6 @@ static int ffs_epfiles_create(struct ffs_data *ffs) ...@@ -1776,7 +1779,6 @@ static int ffs_epfiles_create(struct ffs_data *ffs)
for (i = 1; i <= count; ++i, ++epfile) { for (i = 1; i <= count; ++i, ++epfile) {
epfile->ffs = ffs; epfile->ffs = ffs;
mutex_init(&epfile->mutex); mutex_init(&epfile->mutex);
init_waitqueue_head(&epfile->wait);
if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR)
sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]);
else else
...@@ -1801,8 +1803,7 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) ...@@ -1801,8 +1803,7 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
ENTER(); ENTER();
for (; count; --count, ++epfile) { for (; count; --count, ++epfile) {
BUG_ON(mutex_is_locked(&epfile->mutex) || BUG_ON(mutex_is_locked(&epfile->mutex));
waitqueue_active(&epfile->wait));
if (epfile->dentry) { if (epfile->dentry) {
d_delete(epfile->dentry); d_delete(epfile->dentry);
dput(epfile->dentry); dput(epfile->dentry);
...@@ -1889,11 +1890,11 @@ static int ffs_func_eps_enable(struct ffs_function *func) ...@@ -1889,11 +1890,11 @@ static int ffs_func_eps_enable(struct ffs_function *func)
break; break;
} }
wake_up(&epfile->wait);
++ep; ++ep;
++epfile; ++epfile;
} }
wake_up_interruptible(&ffs->wait);
spin_unlock_irqrestore(&func->ffs->eps_lock, flags); spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
return ret; return ret;
......
...@@ -216,6 +216,9 @@ struct ffs_data { ...@@ -216,6 +216,9 @@ struct ffs_data {
#define FFS_FL_CALL_CLOSED_CALLBACK 0 #define FFS_FL_CALL_CLOSED_CALLBACK 0
#define FFS_FL_BOUND 1 #define FFS_FL_BOUND 1
/* For waking up blocked threads when function is enabled. */
wait_queue_head_t wait;
/* Active function */ /* Active function */
struct ffs_function *func; struct ffs_function *func;
......
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