linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: udc: max3420_udc: fix serialized access
@ 2023-02-08 16:34 jassisinghbrar
  2023-02-08 17:23 ` Greg KH
  2023-02-08 17:23 ` Greg KH
  0 siblings, 2 replies; 4+ messages in thread
From: jassisinghbrar @ 2023-02-08 16:34 UTC (permalink / raw)
  To: linux-usb, linux-kernel; +Cc: gregkh, error27, stern, Jassi Brar

From: Jassi Brar <jaswinder.singh@linaro.org>

 The mutex 'spi_bus_mutex' should be used, instead of the spin-lock,
while changing the state of the kernel-thread. Also changing the
usb-gadget state need not be protected by a spin-lock.
 This should fix the Smatch static checker warning
    warn: sleeping in atomic context

Fixes: 48ba02b2e2b1 ("usb: gadget: add udc driver for max3420")
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
---
 drivers/usb/gadget/udc/max3420_udc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c
index ddf0ed3eb4f2..3666cc44f4e7 100644
--- a/drivers/usb/gadget/udc/max3420_udc.c
+++ b/drivers/usb/gadget/udc/max3420_udc.c
@@ -501,13 +501,16 @@ static irqreturn_t max3420_vbus_handler(int irq, void *dev_id)
 	unsigned long flags;
 
 	spin_lock_irqsave(&udc->lock, flags);
+
 	/* its a vbus change interrupt */
 	udc->vbus_active = !udc->vbus_active;
 	udc->todo |= UDC_START;
+
+	spin_unlock_irqrestore(&udc->lock, flags);
+
 	usb_udc_vbus_handler(&udc->gadget, udc->vbus_active);
 	usb_gadget_set_state(&udc->gadget, udc->vbus_active
 			     ? USB_STATE_POWERED : USB_STATE_NOTATTACHED);
-	spin_unlock_irqrestore(&udc->lock, flags);
 
 	if (udc->thread_task)
 		wake_up_process(udc->thread_task);
@@ -1298,15 +1301,14 @@ static int max3420_probe(struct spi_device *spi)
 static void max3420_remove(struct spi_device *spi)
 {
 	struct max3420_udc *udc = spi_get_drvdata(spi);
-	unsigned long flags;
 
 	usb_del_gadget_udc(&udc->gadget);
 
-	spin_lock_irqsave(&udc->lock, flags);
+	mutex_lock(&udc->spi_bus_mutex);
 
 	kthread_stop(udc->thread_task);
 
-	spin_unlock_irqrestore(&udc->lock, flags);
+	mutex_unlock(&udc->spi_bus_mutex);
 }
 
 static const struct of_device_id max3420_udc_of_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: udc: max3420_udc: fix serialized access
  2023-02-08 16:34 [PATCH] usb: gadget: udc: max3420_udc: fix serialized access jassisinghbrar
@ 2023-02-08 17:23 ` Greg KH
  2023-02-08 17:58   ` Jassi Brar
  2023-02-08 17:23 ` Greg KH
  1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2023-02-08 17:23 UTC (permalink / raw)
  To: jassisinghbrar; +Cc: linux-usb, linux-kernel, error27, stern, Jassi Brar

On Wed, Feb 08, 2023 at 10:34:18AM -0600, jassisinghbrar@gmail.com wrote:
> From: Jassi Brar <jaswinder.singh@linaro.org>
> 
>  The mutex 'spi_bus_mutex' should be used, instead of the spin-lock,
> while changing the state of the kernel-thread.

You forgot to say why this is the case.

> Also changing the
> usb-gadget state need not be protected by a spin-lock.

Why not?  Why isn't this a separate change?

>  This should fix the Smatch static checker warning
>     warn: sleeping in atomic context
> 
> Fixes: 48ba02b2e2b1 ("usb: gadget: add udc driver for max3420")
> Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
> ---
>  drivers/usb/gadget/udc/max3420_udc.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

You forgot a "Reported-by:" line, right?

And odd indentation in your changelog text.


thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: udc: max3420_udc: fix serialized access
  2023-02-08 16:34 [PATCH] usb: gadget: udc: max3420_udc: fix serialized access jassisinghbrar
  2023-02-08 17:23 ` Greg KH
@ 2023-02-08 17:23 ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2023-02-08 17:23 UTC (permalink / raw)
  To: jassisinghbrar; +Cc: linux-usb, linux-kernel, error27, stern, Jassi Brar

On Wed, Feb 08, 2023 at 10:34:18AM -0600, jassisinghbrar@gmail.com wrote:
> From: Jassi Brar <jaswinder.singh@linaro.org>

Also, housekeeping issue, I know Linaro has good email servers, please
use them and not gmail accounts to send patches so that we can validate
that you really are the correct author.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: udc: max3420_udc: fix serialized access
  2023-02-08 17:23 ` Greg KH
@ 2023-02-08 17:58   ` Jassi Brar
  0 siblings, 0 replies; 4+ messages in thread
From: Jassi Brar @ 2023-02-08 17:58 UTC (permalink / raw)
  To: Greg KH; +Cc: jassisinghbrar, linux-usb, linux-kernel, error27, stern

On Wed, 8 Feb 2023 at 11:23, Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Feb 08, 2023 at 10:34:18AM -0600, jassisinghbrar@gmail.com wrote:
> > From: Jassi Brar <jaswinder.singh@linaro.org>
> >
> >  The mutex 'spi_bus_mutex' should be used, instead of the spin-lock,
> > while changing the state of the kernel-thread.
>
> You forgot to say why this is the case.
>
It was 'inherited' (my fault) from  drivers/usb/host/max3421-hcd.c
which has the same issue.
OK, I will also add to the log why that is a bad idea.

> > Also changing the
> > usb-gadget state need not be protected by a spin-lock.
>
> Why not?  Why isn't this a separate change?
>
Because other low-level spi changes are protected by spin-lock and it
seems ok to not to have to worry about such a race.
I don't have the h/w anymore to actually test it, so it is just a
patch from looking.
I just got lazy to break it into two patches, will do that.

> >  This should fix the Smatch static checker warning
> >     warn: sleeping in atomic context
> >
> > Fixes: 48ba02b2e2b1 ("usb: gadget: add udc driver for max3420")
> > Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
> > ---
> >  drivers/usb/gadget/udc/max3420_udc.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
>
> You forgot a "Reported-by:" line, right?
>
Yes, I forgot.

thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-08 17:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-08 16:34 [PATCH] usb: gadget: udc: max3420_udc: fix serialized access jassisinghbrar
2023-02-08 17:23 ` Greg KH
2023-02-08 17:58   ` Jassi Brar
2023-02-08 17:23 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).