From 7df322c6be655981812716b564874d98f0c9ec2e Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 18 Jan 2021 04:07:37 +0800 Subject: [PATCH] bluetooth: Move the lower half null check to common place Signed-off-by: Xiang Xiao --- .../stm32/stm32f4discovery/src/stm32_hciuart.c | 16 ++++------------ .../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 72892a622e..8a7f3e4355 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 74da902a59..b63d0d53e5 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 8c96894188..43e0f491f8 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 2388784299..fd49117c06 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 fcc7cfb7f8..3f86481e67 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 */