This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 62f7a8fa22f200903677dfe670f08bd2e211029c Author: yangsong8 <[email protected]> AuthorDate: Fri Jun 20 22:05:23 2025 +0800 drivers/usbhost: use small lock to protect usbhost bthci replace critical_section with spinlock Signed-off-by: yangsong8 <[email protected]> --- drivers/usbhost/usbhost_bthci.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/usbhost/usbhost_bthci.c b/drivers/usbhost/usbhost_bthci.c index 66fe2922441..49916a7cd02 100644 --- a/drivers/usbhost/usbhost_bthci.c +++ b/drivers/usbhost/usbhost_bthci.c @@ -25,6 +25,7 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <nuttx/spinlock.h> #include <stdio.h> #include <stdlib.h> @@ -219,6 +220,8 @@ static struct usbhost_registry_s g_bthci = static uint32_t g_devinuse; +static spinlock_t g_lock = SP_UNLOCKED; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -294,7 +297,7 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) irqstate_t flags; int devno; - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_lock); for (devno = 0; devno < 26; devno++) { uint32_t bitno = 1 << devno; @@ -302,12 +305,12 @@ static int usbhost_allocdevno(FAR struct usbhost_state_s *priv) { g_devinuse |= bitno; priv->devchar = 'a' + devno; - leave_critical_section(flags); + spin_unlock_irqrestore(&g_lock, flags); return OK; } } - leave_critical_section(flags); + spin_unlock_irqrestore(&g_lock, flags); return -EMFILE; } @@ -319,9 +322,9 @@ static void usbhost_freedevno(FAR struct usbhost_state_s *priv) if (devno >= 0 && devno < 26) { - irqstate_t flags = enter_critical_section(); + irqstate_t flags = spin_lock_irqsave(&g_lock); g_devinuse &= ~(1 << devno); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_lock, flags); } } } @@ -1440,7 +1443,6 @@ static int usbhci_connect(FAR struct usbhost_class_s *usbclass, static int usbhost_disconnected(FAR struct usbhost_class_s *usbclass) { FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)usbclass; - irqstate_t flags; DEBUGASSERT(priv != NULL); @@ -1448,8 +1450,6 @@ static int usbhost_disconnected(FAR struct usbhost_class_s *usbclass) * longer available. */ - flags = enter_critical_section(); - priv->disconnected = true; if (priv->devchar == 'a') @@ -1481,7 +1481,6 @@ static int usbhost_disconnected(FAR struct usbhost_class_s *usbclass) usbhost_destroy(priv); } - leave_critical_section(flags); return OK; }
