Skip to content

Commit 8de6705

Browse files
PavelVPVkartben
authored andcommitted
drivers: bluetooth: Align bt_hci_send behavior on error
This change alignes HCI drivers behavior with Host expectation. That is: if an HCI driver managed to send a packet to Controller, the HCI driver also unreferences it. If the HCI driver didn't manage to send the packet to Controller and returns an error code, it does not unreferences buffer. This change aligns the behavior of HCI drivers with the Host's expectations. Specifically: - If an HCI driver successfully sends a packet to the Controller, the HCI driver also unreferences it. - If the HCI driver fails to send the packet to the Controller and returns an error code, it does not unreference the buffer. Fixes #94445 Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 3ab84aa commit 8de6705

File tree

11 files changed

+44
-17
lines changed

11 files changed

+44
-17
lines changed

drivers/bluetooth/hci/hci_ambiq.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,13 @@ static int bt_apollo_send(const struct device *dev, struct net_buf *buf)
353353

354354
/* Send the SPI packet */
355355
ret = spi_send_packet(buf->data, buf->len);
356+
if (ret != 0) {
357+
return ret;
358+
}
356359

357360
net_buf_unref(buf);
358361

359-
return ret;
362+
return 0;
360363
}
361364

362365
static int bt_apollo_open(const struct device *dev, bt_hci_recv_t recv)

drivers/bluetooth/hci/hci_esp32.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ static int bt_esp32_send(const struct device *dev, struct net_buf *buf)
253253
err = -ETIMEDOUT;
254254
}
255255

256-
net_buf_unref(buf);
256+
if (!err) {
257+
net_buf_unref(buf);
258+
}
259+
257260
k_sem_give(&hci_send_sem);
258261

259262
return err;

drivers/bluetooth/hci/hci_ifx_cyw208xx.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int cyw208xx_send(const struct device *dev, struct net_buf *buf)
286286

287287
ARG_UNUSED(dev);
288288

289-
int ret = 0;
289+
int ret;
290290

291291
k_sem_take(&hci_sem, K_FOREVER);
292292

@@ -324,8 +324,14 @@ static int cyw208xx_send(const struct device *dev, struct net_buf *buf)
324324

325325
done:
326326
k_sem_give(&hci_sem);
327+
328+
if (ret != 0) {
329+
return -EIO;
330+
}
331+
327332
net_buf_unref(buf);
328-
return ret ? -EIO : 0;
333+
334+
return 0;
329335
}
330336

331337
static DEVICE_API(bt_hci, drv) = {

drivers/bluetooth/hci/hci_ifx_psoc6_bless.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ static int psoc6_bless_send(const struct device *dev, struct net_buf *buf)
172172

173173
if (k_sem_take(&psoc6_bless_operation_sem, K_MSEC(BLE_LOCK_TMOUT_MS)) != 0) {
174174
LOG_ERR("Failed to acquire BLE DRV Semaphore");
175-
net_buf_unref(buf);
176175
return -EIO;
177176
}
178177

drivers/bluetooth/hci/hci_silabs_efr32.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,12 @@ static int slz_bt_send(const struct device *dev, struct net_buf *buf)
214214

215215
rv = hci_common_transport_receive(buf->data, buf->len, true);
216216

217+
if (rv != 0) {
218+
return rv;
219+
}
220+
217221
net_buf_unref(buf);
218-
return rv;
222+
return 0;
219223
}
220224

221225
/**

drivers/bluetooth/hci/hci_silabs_siwx91x.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ static int siwx91x_bt_send(const struct device *dev, struct net_buf *buf)
4848
sc = -EIO;
4949
}
5050
}
51+
52+
if (sc != 0) {
53+
return sc;
54+
}
55+
5156
net_buf_unref(buf);
52-
return sc;
57+
return 0;
5358
}
5459

5560
static void siwx91x_bt_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf)

drivers/bluetooth/hci/hci_spi_st.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,14 @@ static int bt_spi_send(const struct device *dev, struct net_buf *buf)
619619
}
620620
}
621621
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_hci_spi_v1) */
622+
623+
if (ret != 0) {
624+
return ret;
625+
}
626+
622627
net_buf_unref(buf);
623628

624-
return ret;
629+
return 0;
625630
}
626631

627632
static int bt_spi_open(const struct device *dev, bt_hci_recv_t recv)

drivers/bluetooth/hci/hci_stm32wb0.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ static struct net_buf *get_rx(uint8_t *msg)
394394

395395
static int bt_hci_stm32wb0_send(const struct device *dev, struct net_buf *buf)
396396
{
397-
int ret = 0;
398397
uint8_t type = net_buf_pull_u8(buf);
399398
uint8_t *hci_buffer = buf->data;
400399

@@ -444,7 +443,7 @@ static int bt_hci_stm32wb0_send(const struct device *dev, struct net_buf *buf)
444443
}
445444
net_buf_unref(buf);
446445

447-
return ret;
446+
return 0;
448447
}
449448

450449
static int bt_hci_stm32wb0_open(const struct device *dev, bt_hci_recv_t recv)

drivers/bluetooth/hci/ipc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ static int bt_ipc_send(const struct device *dev, struct net_buf *buf)
282282

283283
if (err < 0) {
284284
LOG_ERR("Failed to send (err %d)", err);
285-
} else {
286-
err = 0;
285+
return err;
287286
}
288287

289288
net_buf_unref(buf);
290-
return err;
289+
290+
return 0;
291291
}
292292

293293
static void hci_ept_bound(void *priv)

drivers/bluetooth/hci/spi.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,16 @@ static int bt_spi_send(const struct device *dev, struct net_buf *buf)
347347

348348
k_sem_give(&sem_busy);
349349

350-
if (ret) {
350+
if (ret != 0) {
351351
LOG_ERR("Error %d", ret);
352-
goto out;
352+
return ret;
353353
}
354354

355355
LOG_HEXDUMP_DBG(buf->data, buf->len, "SPI TX");
356356

357-
out:
358357
net_buf_unref(buf);
359358

360-
return ret;
359+
return 0;
361360
}
362361

363362
static int bt_spi_open(const struct device *dev, bt_hci_recv_t recv)

0 commit comments

Comments
 (0)