Bluetooth: ATT: Fix using k_fifo API with net_buf

net_buf shall not be used with k_fifo since net_buf_unref will assume
unused bytes in the beginning are actually fragments causing it to
unref them as well.

Jira: ZEP-1489

Change-Id: I5ce420de73b245dc20eb15ea4d8d0b6ba346e513
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2017-01-03 14:22:26 +02:00 committed by Johan Hedberg
commit ae6d92a4ef

View file

@ -1275,8 +1275,10 @@ static uint8_t att_prep_write_rsp(struct bt_att *att, uint16_t handle,
return 0;
}
BT_DBG("buf %p handle 0x%04x offset %u", data.buf, handle, offset);
/* Store buffer in the outstanding queue */
k_fifo_put(&att->prep_queue, data.buf);
net_buf_put(&att->prep_queue, data.buf);
/* Generate response */
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_PREPARE_WRITE_RSP, 0);
@ -1323,9 +1325,12 @@ static uint8_t att_exec_write_rsp(struct bt_att *att, uint8_t flags)
struct net_buf *buf;
uint8_t err = 0;
while ((buf = k_fifo_get(&att->prep_queue, K_NO_WAIT))) {
while ((buf = net_buf_get(&att->prep_queue, K_NO_WAIT))) {
struct bt_attr_data *data = net_buf_user_data(buf);
BT_DBG("buf %p handle 0x%04x offset %u", buf, data->handle,
data->offset);
/* Just discard the data if an error was set */
if (!err && flags == BT_ATT_FLAG_EXEC) {
err = att_write_rsp(conn, BT_ATT_OP_EXEC_WRITE_REQ, 0,