All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/4] USB: UDC: Implement udc_async_callbacks in dummy-hcd
@ 2021-05-20 20:21 Alan Stern
  2021-06-04  5:21 ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2021-05-20 20:21 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: USB mailing list

This patch adds a udc_async_callbacks handler to the dummy-hcd UDC
driver, which will prevent a theoretical race during gadget unbinding.

The implementation is simple, since dummy-hcd already has a flag to
keep track of whether emulated IRQs are enabled.  All the handler has
to do is store the enable value in the flag, and avoid setting the
flag prematurely.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---


[as1957]


 drivers/usb/gadget/udc/dummy_hcd.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Index: usb-devel/drivers/usb/gadget/udc/dummy_hcd.c
===================================================================
--- usb-devel.orig/drivers/usb/gadget/udc/dummy_hcd.c
+++ usb-devel/drivers/usb/gadget/udc/dummy_hcd.c
@@ -919,6 +919,15 @@ static void dummy_udc_set_speed(struct u
 	dummy_udc_update_ep0(dum);
 }
 
+static void dummy_udc_async_callbacks(struct usb_gadget *_gadget, bool enable)
+{
+	struct dummy	*dum = gadget_dev_to_dummy(&_gadget->dev);
+
+	spin_lock_irq(&dum->lock);
+	dum->ints_enabled = enable;
+	spin_unlock_irq(&dum->lock);
+}
+
 static int dummy_udc_start(struct usb_gadget *g,
 		struct usb_gadget_driver *driver);
 static int dummy_udc_stop(struct usb_gadget *g);
@@ -931,6 +940,7 @@ static const struct usb_gadget_ops dummy
 	.udc_start	= dummy_udc_start,
 	.udc_stop	= dummy_udc_stop,
 	.udc_set_speed	= dummy_udc_set_speed,
+	.udc_async_callbacks = dummy_udc_async_callbacks,
 };
 
 /*-------------------------------------------------------------------------*/
@@ -990,7 +1000,6 @@ static int dummy_udc_start(struct usb_ga
 	spin_lock_irq(&dum->lock);
 	dum->devstatus = 0;
 	dum->driver = driver;
-	dum->ints_enabled = 1;
 	spin_unlock_irq(&dum->lock);
 
 	return 0;

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

end of thread, other threads:[~2021-06-04 14:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 20:21 [PATCH 2/4] USB: UDC: Implement udc_async_callbacks in dummy-hcd Alan Stern
2021-06-04  5:21 ` Felipe Balbi
2021-06-04 14:15   ` Alan Stern
2021-06-04 14:20     ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.