Skip to content

Commit 61f834e

Browse files
jori-nordicaescolar
authored andcommitted
Bluetooth: L2CAP: don't use bt_l2cap_send internally
Prevents confusion, as the similarly-named `l2cap_send()` also unrefs the buffer if it fails to send. Signed-off-by: Jonathan Rico <[email protected]>
1 parent 7127c2a commit 61f834e

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

subsys/bluetooth/host/l2cap.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,22 @@ static struct net_buf *l2cap_create_le_sig_pdu(uint8_t code, uint8_t ident,
475475
* Any other cleanup in failure to send should be handled by the disconnected
476476
* handler.
477477
*/
478-
static inline void l2cap_send(struct bt_conn *conn, uint16_t cid,
479-
struct net_buf *buf)
478+
static inline int l2cap_send(struct bt_conn *conn, uint16_t cid, struct net_buf *buf)
480479
{
481-
if (bt_l2cap_send(conn, cid, buf)) {
480+
int err = bt_l2cap_send(conn, cid, buf);
481+
482+
if (err) {
482483
net_buf_unref(buf);
483484
}
485+
486+
return err;
484487
}
485488

486489
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
487490
static void l2cap_chan_send_req(struct bt_l2cap_chan *chan,
488491
struct net_buf *buf, k_timeout_t timeout)
489492
{
490-
if (bt_l2cap_send(chan->conn, BT_L2CAP_CID_LE_SIG, buf)) {
491-
net_buf_unref(buf);
493+
if (l2cap_send(chan->conn, BT_L2CAP_CID_LE_SIG, buf)) {
492494
return;
493495
}
494496

@@ -1204,8 +1206,7 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
12041206
rsp:
12051207
rsp->result = sys_cpu_to_le16(result);
12061208

1207-
if (bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf)) {
1208-
net_buf_unref(buf);
1209+
if (l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf)) {
12091210
return;
12101211
}
12111212

@@ -1324,8 +1325,7 @@ static void le_ecred_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
13241325

13251326
net_buf_add_mem(buf, dcid, sizeof(scid) * req_cid_count);
13261327

1327-
if (bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf)) {
1328-
net_buf_unref(buf);
1328+
if (l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf)) {
13291329
goto callback;
13301330
}
13311331

@@ -2344,7 +2344,6 @@ static void l2cap_chan_send_credits(struct bt_l2cap_le_chan *chan,
23442344
#if defined(CONFIG_BT_L2CAP_SEG_RECV)
23452345
static int l2cap_chan_send_credits_pdu(struct bt_conn *conn, uint16_t cid, uint16_t credits)
23462346
{
2347-
int err;
23482347
struct net_buf *buf;
23492348
struct bt_l2cap_le_credits *ev;
23502349

@@ -2359,13 +2358,7 @@ static int l2cap_chan_send_credits_pdu(struct bt_conn *conn, uint16_t cid, uint1
23592358
.credits = sys_cpu_to_le16(credits),
23602359
};
23612360

2362-
err = bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf);
2363-
if (err) {
2364-
net_buf_unref(buf);
2365-
return err;
2366-
}
2367-
2368-
return 0;
2361+
return l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf);
23692362
}
23702363

23712364
/**
@@ -2782,7 +2775,6 @@ int bt_l2cap_update_conn_param(struct bt_conn *conn,
27822775
{
27832776
struct bt_l2cap_conn_param_req *req;
27842777
struct net_buf *buf;
2785-
int err;
27862778

27872779
buf = l2cap_create_le_sig_pdu(BT_L2CAP_CONN_PARAM_REQ,
27882780
get_ident(), sizeof(*req));
@@ -2796,13 +2788,7 @@ int bt_l2cap_update_conn_param(struct bt_conn *conn,
27962788
req->latency = sys_cpu_to_le16(param->latency);
27972789
req->timeout = sys_cpu_to_le16(param->timeout);
27982790

2799-
err = bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf);
2800-
if (err) {
2801-
net_buf_unref(buf);
2802-
return err;
2803-
}
2804-
2805-
return 0;
2791+
return l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf);
28062792
}
28072793

28082794
static void l2cap_connected(struct bt_l2cap_chan *chan)

0 commit comments

Comments
 (0)