diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index 4c955503ebd..7d95420d0e8 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -537,7 +537,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver, /* Unbind the constituent class drivers */ - flags = enter_critical_section(); + flags = spin_lock_irqsave_nopreempt(&priv->lock); for (i = 0; i < priv->ndevices; i++) { CLASS_UNBIND(priv->device[i].dev, dev); @@ -552,7 +552,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver, priv->ctrlreq = NULL; } - leave_critical_section(flags); + spin_unlock_irqrestore_nopreempt(&priv->lock, flags); } } @@ -864,7 +864,7 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver, * the disconnection. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave_nopreempt(&priv->lock); for (i = 0; i < priv->ndevices; i++) { @@ -872,7 +872,7 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver, } priv->config = COMPOSITE_CONFIGIDNONE; - leave_critical_section(flags); + spin_unlock_irqrestore_nopreempt(&priv->lock, flags); /* Perform the soft connect function so that we will we can be * re-enumerated. @@ -920,14 +920,14 @@ static void composite_suspend(FAR struct usbdevclass_driver_s *driver, /* Forward the suspend event to the constituent devices */ - flags = enter_critical_section(); + flags = spin_lock_irqsave_nopreempt(&priv->lock); for (i = 0; i < priv->ndevices; i++) { CLASS_SUSPEND(priv->device[i].dev, priv->usbdev); } - leave_critical_section(flags); + spin_unlock_irqrestore_nopreempt(&priv->lock, flags); } /**************************************************************************** @@ -967,14 +967,14 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver, /* Forward the resume event to the constituent devices */ - flags = enter_critical_section(); + flags = spin_lock_irqsave_nopreempt(&priv->lock); for (i = 0; i < priv->ndevices; i++) { CLASS_RESUME(priv->device[i].dev, priv->usbdev); } - leave_critical_section(flags); + spin_unlock_irqrestore_nopreempt(&priv->lock, flags); } /**************************************************************************** @@ -1040,6 +1040,7 @@ FAR void *composite_initialize(FAR const struct usbdev_devdescs_s *devdescs, priv->descs = devdescs; priv->cfgdescsize = USB_SIZEOF_CFGDESC; priv->ninterfaces = 0; + spin_lock_init(&priv->lock); /* Get the constituent class driver objects */ diff --git a/drivers/usbdev/composite.h b/drivers/usbdev/composite.h index aa69f3ba117..dc26f10ac41 100644 --- a/drivers/usbdev/composite.h +++ b/drivers/usbdev/composite.h @@ -36,6 +36,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -88,6 +89,7 @@ struct composite_dev_s uint8_t ndevices; /* Num devices in this composite device */ struct composite_devobj_s device[NUM_DEVICES_TO_HANDLE]; /* Device class object */ FAR const struct usbdev_devdescs_s *descs; /* Device descriptors */ + spinlock_t lock; }; #endif /* __DRIVERS_USBDEV_COMPOSITE_H */