You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by bt...@apache.org on 2021/01/18 04:49:35 UTC

[incubator-nuttx] 03/03: bluetooth: Move the lower half null check to common place

This is an automated email from the ASF dual-hosted git repository.

btashton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 7df322c6be655981812716b564874d98f0c9ec2e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Jan 18 04:07:37 2021 +0800

    bluetooth: Move the lower half null check to common place
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 boards/arm/stm32/stm32f4discovery/src/stm32_hciuart.c | 16 ++++------------
 boards/arm/tiva/tm4c1294-launchpad/src/tm4c_hciuart.c | 16 ++++------------
 drivers/wireless/bluetooth/bt_uart_bcm4343x.c         |  6 +++++-
 drivers/wireless/bluetooth/bt_uart_cc2564.c           |  6 +++++-
 drivers/wireless/bluetooth/bt_uart_generic.c          |  6 +++++-
 5 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_hciuart.c b/boards/arm/stm32/stm32f4discovery/src/stm32_hciuart.c
index 72892a6..8a7f3e4 100644
--- a/boards/arm/stm32/stm32f4discovery/src/stm32_hciuart.c
+++ b/boards/arm/stm32/stm32f4discovery/src/stm32_hciuart.c
@@ -75,25 +75,17 @@
 
 int hciuart_dev_initialize(void)
 {
-  const struct btuart_lowerhalf_s *lower;
   int ret;
 
   /* Perform one-time initialization */
 
   hciuart_initialize();
 
-  /* Instantiate the HCI UART lower half interface */
+  /* Instantiate the HCI UART lower half interface
+   * Then initialize the HCI UART upper half driver with the bluetooth stack
+   */
 
-  lower = hciuart_instantiate(HCIUART_SERDEV);
-  if (lower == NULL)
-    {
-      wlerr("ERROR: Failed to instantiate HCIUART%d\n", HCIUART_SERDEV + 1);
-      return -ENODEV;
-    }
-
-  /* Then initialize the HCI UART upper half driver with the bluetooth stack */
-
-  ret = btuart_register(lower);
+  ret = btuart_register(hciuart_instantiate(HCIUART_SERDEV));
   if (ret < 0)
     {
       wlerr("ERROR: btuart_register() failed: %d\n", ret);
diff --git a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_hciuart.c b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_hciuart.c
index 74da902..b63d0d5 100644
--- a/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_hciuart.c
+++ b/boards/arm/tiva/tm4c1294-launchpad/src/tm4c_hciuart.c
@@ -75,25 +75,17 @@
 
 int hciuart_dev_initialize(void)
 {
-  const struct btuart_lowerhalf_s *lower;
   int ret;
 
   /* Perform one-time initialization */
 
   hciuart_initialize();
 
-  /* Instantiate the HCI UART lower half interface */
+  /* Instantiate the HCI UART lower half interface
+   * Then initialize the HCI UART upper half driver with the bluetooth stack
+   */
 
-  lower = hciuart_instantiate(HCIUART_SERDEV);
-  if (lower == NULL)
-    {
-      wlerr("ERROR: Failed to instantiate HCIUART%d\n", HCIUART_SERDEV + 1);
-      return -ENODEV;
-    }
-
-  /* Then initialize the HCI UART upper half driver with the bluetooth stack */
-
-  ret = btuart_register(lower);
+  ret = btuart_register(hciuart_instantiate(HCIUART_SERDEV));
   if (ret < 0)
     {
       wlerr("ERROR: btuart_register() failed: %d\n", ret);
diff --git a/drivers/wireless/bluetooth/bt_uart_bcm4343x.c b/drivers/wireless/bluetooth/bt_uart_bcm4343x.c
index 8c96894..43e0f49 100644
--- a/drivers/wireless/bluetooth/bt_uart_bcm4343x.c
+++ b/drivers/wireless/bluetooth/bt_uart_bcm4343x.c
@@ -416,7 +416,11 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
 
   wlinfo("lower %p\n", lower);
 
-  DEBUGASSERT(lower != NULL);
+  if (lower == NULL)
+    {
+      wlerr("ERROR: btuart lower half is NULL\n");
+      return -ENODEV;
+    }
 
   /* Allocate a new instance of the upper half driver state structure */
 
diff --git a/drivers/wireless/bluetooth/bt_uart_cc2564.c b/drivers/wireless/bluetooth/bt_uart_cc2564.c
index 2388784..fd49117 100644
--- a/drivers/wireless/bluetooth/bt_uart_cc2564.c
+++ b/drivers/wireless/bluetooth/bt_uart_cc2564.c
@@ -181,7 +181,11 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
 
   wlinfo("lower %p\n", lower);
 
-  DEBUGASSERT(lower != NULL);
+  if (lower == NULL)
+    {
+      wlerr("ERROR: btuart lower half is NULL\n");
+      return -ENODEV;
+    }
 
   /* Allocate a new instance of the upper half driver state structure */
 
diff --git a/drivers/wireless/bluetooth/bt_uart_generic.c b/drivers/wireless/bluetooth/bt_uart_generic.c
index fcc7cfb..3f86481 100644
--- a/drivers/wireless/bluetooth/bt_uart_generic.c
+++ b/drivers/wireless/bluetooth/bt_uart_generic.c
@@ -75,7 +75,11 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
 
   wlinfo("lower %p\n", lower);
 
-  DEBUGASSERT(lower != NULL);
+  if (lower == NULL)
+    {
+      wlerr("ERROR: btuart lower half is NULL\n");
+      return -ENODEV;
+    }
 
   /* Allocate a new instance of the upper half driver state structure */