@@ -130,14 +130,14 @@ static int att_send(struct bt_conn *conn, struct net_buf *buf,
130
130
err = bt_smp_sign (conn , buf );
131
131
if (err ) {
132
132
BT_ERR ("Error signing data" );
133
+ net_buf_unref (buf );
133
134
return err ;
134
135
}
135
136
}
136
137
137
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , cb ? cb : att_cb (buf ),
138
- user_data );
139
-
140
- return 0 ;
138
+ return bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf ,
139
+ cb ? cb : att_cb (buf ),
140
+ user_data );
141
141
}
142
142
143
143
void att_pdu_sent (struct bt_conn * conn , void * user_data )
@@ -158,8 +158,6 @@ void att_pdu_sent(struct bt_conn *conn, void *user_data)
158
158
if (!att_send (conn , buf , NULL , NULL )) {
159
159
return ;
160
160
}
161
- /* If the buffer cannot be send unref it */
162
- net_buf_unref (buf );
163
161
}
164
162
165
163
k_sem_give (& att -> tx_sem );
@@ -241,7 +239,7 @@ static void send_err_rsp(struct bt_conn *conn, u8_t req, u16_t handle,
241
239
rsp -> handle = sys_cpu_to_le16 (handle );
242
240
rsp -> error = err ;
243
241
244
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , att_rsp_sent , NULL );
242
+ ( void ) bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , att_rsp_sent , NULL );
245
243
}
246
244
247
245
static u8_t att_mtu_req (struct bt_att * att , struct net_buf * buf )
@@ -275,7 +273,7 @@ static u8_t att_mtu_req(struct bt_att *att, struct net_buf *buf)
275
273
rsp = net_buf_add (pdu , sizeof (* rsp ));
276
274
rsp -> mtu = sys_cpu_to_le16 (mtu_server );
277
275
278
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , pdu , att_rsp_sent , NULL );
276
+ ( void ) bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , pdu , att_rsp_sent , NULL );
279
277
280
278
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484:
281
279
*
@@ -297,6 +295,8 @@ static inline bool att_is_connected(struct bt_att *att)
297
295
298
296
static int att_send_req (struct bt_att * att , struct bt_att_req * req )
299
297
{
298
+ int err ;
299
+
300
300
__ASSERT_NO_MSG (req );
301
301
__ASSERT_NO_MSG (req -> func );
302
302
__ASSERT_NO_MSG (!att -> req );
@@ -314,8 +314,13 @@ static int att_send_req(struct bt_att *att, struct bt_att_req *req)
314
314
net_buf_simple_save (& req -> buf -> b , & req -> state );
315
315
316
316
/* Keep a reference for resending in case of an error */
317
- bt_l2cap_send_cb (att -> chan .chan .conn , BT_L2CAP_CID_ATT ,
318
- net_buf_ref (req -> buf ), att_cb (req -> buf ), NULL );
317
+ err = bt_l2cap_send_cb (att -> chan .chan .conn , BT_L2CAP_CID_ATT ,
318
+ net_buf_ref (req -> buf ), att_cb (req -> buf ), NULL );
319
+ if (err ) {
320
+ net_buf_unref (req -> buf );
321
+ req -> buf = NULL ;
322
+ return err ;
323
+ }
319
324
320
325
return 0 ;
321
326
}
@@ -523,7 +528,8 @@ static u8_t att_find_info_rsp(struct bt_att *att, u16_t start_handle,
523
528
return 0 ;
524
529
}
525
530
526
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
531
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
532
+ NULL );
527
533
528
534
return 0 ;
529
535
}
@@ -669,7 +675,8 @@ static u8_t att_find_type_rsp(struct bt_att *att, u16_t start_handle,
669
675
return 0 ;
670
676
}
671
677
672
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
678
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
679
+ NULL );
673
680
674
681
return 0 ;
675
682
}
@@ -830,7 +837,8 @@ static u8_t att_read_type_rsp(struct bt_att *att, struct bt_uuid *uuid,
830
837
return 0 ;
831
838
}
832
839
833
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
840
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
841
+ NULL );
834
842
835
843
return 0 ;
836
844
}
@@ -953,7 +961,8 @@ static u8_t att_read_rsp(struct bt_att *att, u8_t op, u8_t rsp, u16_t handle,
953
961
return 0 ;
954
962
}
955
963
956
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
964
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
965
+ NULL );
957
966
958
967
return 0 ;
959
968
}
@@ -1031,7 +1040,8 @@ static u8_t att_read_mult_req(struct bt_att *att, struct net_buf *buf)
1031
1040
}
1032
1041
}
1033
1042
1034
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
1043
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
1044
+ NULL );
1035
1045
1036
1046
return 0 ;
1037
1047
}
@@ -1136,7 +1146,8 @@ static u8_t att_read_group_rsp(struct bt_att *att, struct bt_uuid *uuid,
1136
1146
return 0 ;
1137
1147
}
1138
1148
1139
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
1149
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
1150
+ NULL );
1140
1151
1141
1152
return 0 ;
1142
1153
}
@@ -1280,8 +1291,8 @@ static u8_t att_write_rsp(struct bt_conn *conn, u8_t req, u8_t rsp,
1280
1291
}
1281
1292
1282
1293
if (data .buf ) {
1283
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf ,
1284
- att_rsp_sent , NULL );
1294
+ ( void ) bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf ,
1295
+ att_rsp_sent , NULL );
1285
1296
}
1286
1297
1287
1298
return 0 ;
@@ -1406,7 +1417,8 @@ static u8_t att_prep_write_rsp(struct bt_att *att, u16_t handle, u16_t offset,
1406
1417
net_buf_add (data .buf , len );
1407
1418
memcpy (rsp -> value , value , len );
1408
1419
1409
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent , NULL );
1420
+ (void )bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , data .buf , att_rsp_sent ,
1421
+ NULL );
1410
1422
1411
1423
return 0 ;
1412
1424
}
@@ -1469,7 +1481,7 @@ static u8_t att_exec_write_rsp(struct bt_att *att, u8_t flags)
1469
1481
return BT_ATT_ERR_UNLIKELY ;
1470
1482
}
1471
1483
1472
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , att_rsp_sent , NULL );
1484
+ ( void ) bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , att_rsp_sent , NULL );
1473
1485
1474
1486
return 0 ;
1475
1487
}
@@ -1739,7 +1751,7 @@ static u8_t att_indicate(struct bt_att *att, struct net_buf *buf)
1739
1751
return 0 ;
1740
1752
}
1741
1753
1742
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , att_cfm_sent , NULL );
1754
+ ( void ) bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , buf , att_cfm_sent , NULL );
1743
1755
1744
1756
return 0 ;
1745
1757
}
@@ -2187,8 +2199,8 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan,
2187
2199
BT_DBG ("Retrying" );
2188
2200
2189
2201
/* Resend buffer */
2190
- bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , att -> req -> buf ,
2191
- att_cb (att -> req -> buf ), NULL );
2202
+ ( void ) bt_l2cap_send_cb (conn , BT_L2CAP_CID_ATT , att -> req -> buf ,
2203
+ att_cb (att -> req -> buf ), NULL );
2192
2204
att -> req -> buf = NULL ;
2193
2205
}
2194
2206
#endif /* CONFIG_BT_SMP */
@@ -2255,12 +2267,12 @@ int bt_att_send(struct bt_conn *conn, struct net_buf *buf, bt_conn_tx_cb_t cb,
2255
2267
struct bt_att * att ;
2256
2268
int err ;
2257
2269
2258
- if (!conn || !buf ) {
2259
- return - EINVAL ;
2260
- }
2270
+ __ASSERT_NO_MSG (conn );
2271
+ __ASSERT_NO_MSG (buf );
2261
2272
2262
2273
att = att_chan_get (conn );
2263
2274
if (!att ) {
2275
+ net_buf_unref (buf );
2264
2276
return - ENOTCONN ;
2265
2277
}
2266
2278
@@ -2290,12 +2302,13 @@ int bt_att_req_send(struct bt_conn *conn, struct bt_att_req *req)
2290
2302
2291
2303
BT_DBG ("conn %p req %p" , conn , req );
2292
2304
2293
- if (!conn || !req ) {
2294
- return - EINVAL ;
2295
- }
2305
+ __ASSERT_NO_MSG (conn );
2306
+ __ASSERT_NO_MSG (req );
2296
2307
2297
2308
att = att_chan_get (conn );
2298
2309
if (!att ) {
2310
+ net_buf_unref (req -> buf );
2311
+ req -> buf = NULL ;
2299
2312
return - ENOTCONN ;
2300
2313
}
2301
2314
0 commit comments