Skip to content

Commit

Permalink
usb: gadget: ffs: ffs_aio_cancel(): Save/restore IRQ flags
Browse files Browse the repository at this point in the history
ffs_aio_cancel() can be called from both interrupt and thread context. Make
sure that the current IRQ state is saved and restored by using
spin_{un,}lock_irq{save,restore}().

Otherwise undefined behavior might occur.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
  • Loading branch information
Lars-Peter Clausen authored and Felipe Balbi committed Feb 11, 2020
1 parent 9a0d6f7 commit 43d5657
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/usb/gadget/function/f_fs.c
Original file line number Diff line number Diff line change
@@ -1162,18 +1162,19 @@ static int ffs_aio_cancel(struct kiocb *kiocb)
{
struct ffs_io_data *io_data = kiocb->private;
struct ffs_epfile *epfile = kiocb->ki_filp->private_data;
unsigned long flags;
int value;

ENTER();

spin_lock_irq(&epfile->ffs->eps_lock);
spin_lock_irqsave(&epfile->ffs->eps_lock, flags);

if (likely(io_data && io_data->ep && io_data->req))
value = usb_ep_dequeue(io_data->ep, io_data->req);
else
value = -EINVAL;

spin_unlock_irq(&epfile->ffs->eps_lock);
spin_unlock_irqrestore(&epfile->ffs->eps_lock, flags);

return value;
}

0 comments on commit 43d5657

Please sign in to comment.