Skip to content

Commit b5a46db

Browse files
Vudentznashif
authored andcommitted
Bluetooth: ISO: Use CHECKIF instead of __ASSERT_NO_MSG
CHECKIF is preferred as it handles full runtime error handling in addition to just asserts. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent af0fc96 commit b5a46db

File tree

1 file changed

+50
-15
lines changed
  • subsys/bluetooth/host

1 file changed

+50
-15
lines changed

subsys/bluetooth/host/iso.c

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ void hci_le_cis_estabilished(struct net_buf *buf)
118118
return;
119119
}
120120

121-
__ASSERT(conn->type == BT_CONN_TYPE_ISO, "Invalid connection type");
121+
CHECKIF(conn->type != BT_CONN_TYPE_ISO) {
122+
BT_DBG("Invalid connection type %u", conn->type);
123+
return;
124+
}
122125

123126
if (!evt->status) {
124127
/* TODO: Add CIG sync delay */
@@ -257,7 +260,11 @@ void bt_iso_cleanup(struct bt_conn *conn)
257260
{
258261
int i;
259262

260-
__ASSERT_NO_MSG(conn->type == BT_CONN_TYPE_ISO);
263+
CHECKIF(!conn || conn->type != BT_CONN_TYPE_ISO) {
264+
BT_DBG("Invalid parameters: conn %p conn->type %u", conn,
265+
conn ? conn->type : 0);
266+
return;
267+
}
261268

262269
BT_DBG("%p", conn);
263270

@@ -656,7 +663,11 @@ int bt_iso_accept(struct bt_conn *conn)
656663
struct bt_iso_chan *chan;
657664
int err;
658665

659-
__ASSERT_NO_MSG(conn->type == BT_CONN_TYPE_ISO);
666+
CHECKIF(!conn || conn->type != BT_CONN_TYPE_ISO) {
667+
BT_DBG("Invalid parameters: conn %p conn->type %u", conn,
668+
conn ? conn->type : 0);
669+
return -EINVAL;
670+
}
660671

661672
BT_DBG("%p", conn);
662673

@@ -723,7 +734,11 @@ void bt_iso_connected(struct bt_conn *conn)
723734
{
724735
struct bt_iso_chan *chan;
725736

726-
__ASSERT_NO_MSG(conn->type == BT_CONN_TYPE_ISO);
737+
CHECKIF(!conn || conn->type != BT_CONN_TYPE_ISO) {
738+
BT_DBG("Invalid parameters: conn %p conn->type %u", conn,
739+
conn ? conn->type : 0);
740+
return;
741+
}
727742

728743
BT_DBG("%p", conn);
729744

@@ -776,7 +791,11 @@ void bt_iso_disconnected(struct bt_conn *conn)
776791
{
777792
struct bt_iso_chan *chan, *next;
778793

779-
__ASSERT_NO_MSG(conn->type == BT_CONN_TYPE_ISO);
794+
CHECKIF(!conn || conn->type != BT_CONN_TYPE_ISO) {
795+
BT_DBG("Invalid parameters: conn %p conn->type %u", conn,
796+
conn ? conn->type : 0);
797+
return;
798+
}
780799

781800
BT_DBG("%p", conn);
782801

@@ -793,7 +812,10 @@ void bt_iso_disconnected(struct bt_conn *conn)
793812

794813
int bt_iso_server_register(struct bt_iso_server *server)
795814
{
796-
__ASSERT_NO_MSG(server);
815+
CHECKIF(!server) {
816+
BT_DBG("Invalid parameter: server %p", server);
817+
return -EINVAL;
818+
}
797819

798820
/* Check if controller is ISO capable */
799821
if (!BT_FEAT_LE_CIS_SLAVE(bt_dev.le.features)) {
@@ -906,9 +928,11 @@ int bt_iso_chan_bind(struct bt_conn **conns, uint8_t num_conns,
906928
int i, err;
907929
static uint8_t id;
908930

909-
__ASSERT_NO_MSG(conns);
910-
__ASSERT_NO_MSG(num_conns);
911-
__ASSERT_NO_MSG(chans);
931+
CHECKIF(!conns || !num_conns || !chans) {
932+
BT_DBG("Invalid parameters: conns %p num_conns %u chans %p",
933+
conns, num_conns, chans);
934+
return -EINVAL;
935+
}
912936

913937
memset(&param, 0, sizeof(param));
914938

@@ -933,7 +957,10 @@ int bt_iso_chan_bind(struct bt_conn **conns, uint8_t num_conns,
933957

934958
int bt_iso_chan_unbind(struct bt_iso_chan *chan)
935959
{
936-
__ASSERT_NO_MSG(chan);
960+
CHECKIF(!chan) {
961+
BT_DBG("Invalid parameter: chan %p", chan);
962+
return -EINVAL;
963+
}
937964

938965
if (!chan->conn || chan->state != BT_ISO_BOUND) {
939966
return -EINVAL;
@@ -954,8 +981,11 @@ int bt_iso_chan_connect(struct bt_iso_chan **chans, uint8_t num_chans)
954981
struct bt_conn *conns[CONFIG_BT_ISO_MAX_CHAN];
955982
int i, err;
956983

957-
__ASSERT_NO_MSG(chans);
958-
__ASSERT_NO_MSG(num_chans);
984+
CHECKIF(!chans || !num_chans) {
985+
BT_DBG("Invalid parameters: chans %p num_chans %u", chans,
986+
num_chans);
987+
return -EINVAL;
988+
}
959989

960990
for (i = 0; i < num_chans; i++) {
961991
if (!chans[i]->conn) {
@@ -979,7 +1009,10 @@ int bt_iso_chan_connect(struct bt_iso_chan **chans, uint8_t num_chans)
9791009

9801010
int bt_iso_chan_disconnect(struct bt_iso_chan *chan)
9811011
{
982-
__ASSERT_NO_MSG(chan);
1012+
CHECKIF(!chan) {
1013+
BT_DBG("Invalid parameter: chan %p", chan);
1014+
return -EINVAL;
1015+
}
9831016

9841017
if (!chan->conn) {
9851018
return -ENOTCONN;
@@ -1129,8 +1162,10 @@ int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf)
11291162
struct bt_hci_iso_data_hdr *hdr;
11301163
static uint16_t sn;
11311164

1132-
__ASSERT_NO_MSG(chan);
1133-
__ASSERT_NO_MSG(buf);
1165+
CHECKIF(!chan || !buf) {
1166+
BT_DBG("Invalid parameters: chan %p buf %p", chan, buf);
1167+
return -EINVAL;
1168+
}
11341169

11351170
BT_DBG("chan %p len %zu", chan, net_buf_frags_len(buf));
11361171

0 commit comments

Comments
 (0)