diff mbox series

usb: gadget: ffs: ffs_aio_cancel(): Save/restore IRQ flags

Message ID 20191106120219.15028-1-alexandru.ardelean@analog.com (mailing list archive)
State Mainlined
Commit 43d565727a3a6fd24e37c7c2116475106af71806
Headers show
Series usb: gadget: ffs: ffs_aio_cancel(): Save/restore IRQ flags | expand

Commit Message

Alexandru Ardelean Nov. 6, 2019, 12:02 p.m. UTC
From: Lars-Peter Clausen <lars@metafoo.de>

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.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/usb/gadget/function/f_fs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Alexandru Ardelean Jan. 16, 2020, 11:13 a.m. UTC | #1
On Wed, 2019-11-06 at 14:02 +0200, Alexandru Ardelean wrote:
> From: Lars-Peter Clausen <lars@metafoo.de>
> 
> 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.

Hey,

This is a patch-ping.

Thanks
Alex

> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
>  drivers/usb/gadget/function/f_fs.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c
> b/drivers/usb/gadget/function/f_fs.c
> index 59d9d512dcda..ed3bcbb84b95 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -1160,18 +1160,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;
>  }
Felipe Balbi Jan. 16, 2020, 1:04 p.m. UTC | #2
Hi,

"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> writes:

> On Wed, 2019-11-06 at 14:02 +0200, Alexandru Ardelean wrote:
>> From: Lars-Peter Clausen <lars@metafoo.de>
>> 
>> 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.
>
> Hey,
>
> This is a patch-ping.

Please read:

https://lore.kernel.org/linux-usb/875zhd6pw0.fsf@kernel.org/T/#u

We're gonna need a resend, sorry
Alexandru Ardelean Jan. 16, 2020, 1:05 p.m. UTC | #3
On Thu, 2020-01-16 at 15:04 +0200, Felipe Balbi wrote:
> [External]
> 
> 
> Hi,
> 
> "Ardelean, Alexandru" <alexandru.Ardelean@analog.com> writes:
> 
> > On Wed, 2019-11-06 at 14:02 +0200, Alexandru Ardelean wrote:
> > > From: Lars-Peter Clausen <lars@metafoo.de>
> > > 
> > > 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.
> > 
> > Hey,
> > 
> > This is a patch-ping.
> 
> Please read:
> 
> https://lore.kernel.org/linux-usb/875zhd6pw0.fsf@kernel.org/T/#u
> 
> We're gonna need a resend, sorry
> 

Ack.

Thanks for the reply.
Will re-send.
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 59d9d512dcda..ed3bcbb84b95 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -1160,18 +1160,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;
 }