@@ -475,20 +475,22 @@ static struct net_buf *l2cap_create_le_sig_pdu(uint8_t code, uint8_t ident,
475
475
* Any other cleanup in failure to send should be handled by the disconnected
476
476
* handler.
477
477
*/
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 )
480
479
{
481
- if (bt_l2cap_send (conn , cid , buf )) {
480
+ int err = bt_l2cap_send (conn , cid , buf );
481
+
482
+ if (err ) {
482
483
net_buf_unref (buf );
483
484
}
485
+
486
+ return err ;
484
487
}
485
488
486
489
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL )
487
490
static void l2cap_chan_send_req (struct bt_l2cap_chan * chan ,
488
491
struct net_buf * buf , k_timeout_t timeout )
489
492
{
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 )) {
492
494
return ;
493
495
}
494
496
@@ -1204,8 +1206,7 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
1204
1206
rsp :
1205
1207
rsp -> result = sys_cpu_to_le16 (result );
1206
1208
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 )) {
1209
1210
return ;
1210
1211
}
1211
1212
@@ -1324,8 +1325,7 @@ static void le_ecred_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
1324
1325
1325
1326
net_buf_add_mem (buf , dcid , sizeof (scid ) * req_cid_count );
1326
1327
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 )) {
1329
1329
goto callback ;
1330
1330
}
1331
1331
@@ -2344,7 +2344,6 @@ static void l2cap_chan_send_credits(struct bt_l2cap_le_chan *chan,
2344
2344
#if defined(CONFIG_BT_L2CAP_SEG_RECV )
2345
2345
static int l2cap_chan_send_credits_pdu (struct bt_conn * conn , uint16_t cid , uint16_t credits )
2346
2346
{
2347
- int err ;
2348
2347
struct net_buf * buf ;
2349
2348
struct bt_l2cap_le_credits * ev ;
2350
2349
@@ -2359,13 +2358,7 @@ static int l2cap_chan_send_credits_pdu(struct bt_conn *conn, uint16_t cid, uint1
2359
2358
.credits = sys_cpu_to_le16 (credits ),
2360
2359
};
2361
2360
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 );
2369
2362
}
2370
2363
2371
2364
/**
@@ -2782,7 +2775,6 @@ int bt_l2cap_update_conn_param(struct bt_conn *conn,
2782
2775
{
2783
2776
struct bt_l2cap_conn_param_req * req ;
2784
2777
struct net_buf * buf ;
2785
- int err ;
2786
2778
2787
2779
buf = l2cap_create_le_sig_pdu (BT_L2CAP_CONN_PARAM_REQ ,
2788
2780
get_ident (), sizeof (* req ));
@@ -2796,13 +2788,7 @@ int bt_l2cap_update_conn_param(struct bt_conn *conn,
2796
2788
req -> latency = sys_cpu_to_le16 (param -> latency );
2797
2789
req -> timeout = sys_cpu_to_le16 (param -> timeout );
2798
2790
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 );
2806
2792
}
2807
2793
2808
2794
static void l2cap_connected (struct bt_l2cap_chan * chan )
0 commit comments