Skip to content

Commit

Permalink
Merge "USB: f_fs: Move ep completion out of stack"
Browse files Browse the repository at this point in the history
  • Loading branch information
Linux Build Service Account authored and Gerrit - the friendly Code Review server committed Oct 27, 2014
2 parents a37b1d3 + e378daf commit 0131938
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions drivers/usb/gadget/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ struct ffs_data {
struct usb_request *ep0req; /* P: mutex */
struct completion ep0req_completion; /* P: mutex */
int ep0req_status; /* P: mutex */
struct completion epin_completion;
struct completion epout_completion;

/* reference counter */
atomic_t ref;
Expand Down Expand Up @@ -749,8 +751,11 @@ static const struct file_operations ffs_ep0_operations = {

static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
{
struct ffs_ep *ep = _ep->driver_data;
ENTER();
if (likely(req->context)) {

/* req may be freed during unbind */
if (ep && ep->req && likely(req->context)) {
struct ffs_ep *ep = _ep->driver_data;
ep->status = req->status ? req->status : req->actual;
complete(req->context);
Expand All @@ -762,6 +767,7 @@ static ssize_t ffs_epfile_io(struct file *file,
{
struct ffs_epfile *epfile = file->private_data;
struct ffs_ep *ep;
struct ffs_data *ffs = epfile->ffs;
char *data = NULL;
ssize_t ret;
int halt;
Expand Down Expand Up @@ -860,21 +866,27 @@ static ssize_t ffs_epfile_io(struct file *file,
ret = -EBADMSG;
} else {
/* Fire the request */
DECLARE_COMPLETION_ONSTACK(done);
struct completion *done;

struct usb_request *req = ep->req;
req->context = &done;
req->complete = ffs_epfile_io_complete;
req->buf = data;
req->length = buffer_len;

if (read) {
INIT_COMPLETION(ffs->epout_completion);
req->context = done = &ffs->epout_completion;
} else {
INIT_COMPLETION(ffs->epin_completion);
req->context = done = &ffs->epin_completion;
}
ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);

spin_unlock_irq(&epfile->ffs->eps_lock);

if (unlikely(ret < 0)) {
ret = -EIO;
} else if (unlikely(wait_for_completion_interruptible(&done))) {
} else if (unlikely(wait_for_completion_interruptible(done))) {
spin_lock_irq(&epfile->ffs->eps_lock);
/*
* While we were acquiring lock endpoint got disabled
Expand Down Expand Up @@ -1365,6 +1377,8 @@ static struct ffs_data *ffs_data_new(void)
spin_lock_init(&ffs->eps_lock);
init_waitqueue_head(&ffs->ev.waitq);
init_completion(&ffs->ep0req_completion);
init_completion(&ffs->epout_completion);
init_completion(&ffs->epin_completion);

/* XXX REVISIT need to update it in some places, or do we? */
ffs->ev.can_stall = 1;
Expand Down

0 comments on commit 0131938

Please sign in to comment.