From 281f27ec38aa2ab663cdacc76827cd55de430bab Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Thu, 30 Nov 2023 15:26:44 +0000 Subject: [PATCH] drivers: bluetooth: fix and clean up BlueNRG HCI setup() function If no public address was set, it should just do nothing instead of erroring. The function should also be static and there's no need to copy the address struct. Signed-off-by: Armin Brauns --- drivers/bluetooth/hci/spi.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 8b5bbc4bd46..a2cabc46215 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -243,22 +243,20 @@ static int bt_spi_send_aci_config(uint8_t offset, const uint8_t *value, size_t v return bt_hci_cmd_send(BLUENRG_ACI_WRITE_CONFIG_DATA, buf); } -int bt_spi_bluenrg_setup(const struct bt_hci_setup_params *params) +static int bt_spi_bluenrg_setup(const struct bt_hci_setup_params *params) { int ret; - const bt_addr_t addr = params->public_addr; + const bt_addr_t *addr = ¶ms->public_addr; - if (bt_addr_eq(&addr, BT_ADDR_NONE) || bt_addr_eq(&addr, BT_ADDR_ANY)) { - return -EINVAL; - } + if (!bt_addr_eq(addr, BT_ADDR_NONE) && !bt_addr_eq(addr, BT_ADDR_ANY)) { + ret = bt_spi_send_aci_config( + BLUENRG_CONFIG_PUBADDR_OFFSET, + addr->val, sizeof(addr->val)); - ret = bt_spi_send_aci_config( - BLUENRG_CONFIG_PUBADDR_OFFSET, - addr.val, sizeof(addr.val)); - - if (ret != 0) { - LOG_ERR("Failed to set BlueNRG public address (%d)", ret); - return ret; + if (ret != 0) { + LOG_ERR("Failed to set BlueNRG public address (%d)", ret); + return ret; + } } return 0;