summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2016-10-17 16:08:47 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2016-10-21 07:47:31 +0300
commitb87d49e99a8e89b1a1225e24e93aeab64065566b (patch)
tree4f85ac0a84b0fafd163d66a16f5c3f7f63dce4de /net
parentde58e096dd0f13e1f6068b5495e431f3f12cc291 (diff)
Bluetooth: L2CAP: Simplify allocation of buffer fragments
Instead of requesting the full length just request one buffer at time. Change-Id: I8f97ecf0a959316e1fadfdedf9e500e61ed26c27 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/l2cap.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index d3c349c75..6cf5ed510 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -986,27 +986,19 @@ done:
BT_DBG("chan %p credits %u", chan, chan->rx.credits.nsig);
}
-static struct net_buf *l2cap_alloc_frag(struct bt_l2cap_le_chan *chan,
- uint16_t len)
+static struct net_buf *l2cap_alloc_frag(struct bt_l2cap_le_chan *chan)
{
struct net_buf *frag = NULL;
- while (len) {
- frag = chan->chan.ops->alloc_buf(&chan->chan);
- if (!frag) {
- return NULL;
- }
-
- BT_DBG("frag %p tailroom %u", frag, net_buf_tailroom(frag));
- net_buf_frag_add(chan->_sdu, frag);
+ frag = chan->chan.ops->alloc_buf(&chan->chan);
+ if (!frag) {
+ return NULL;
+ }
- if (net_buf_tailroom(frag) > len) {
- return frag;
- }
+ BT_DBG("frag %p tailroom %u", frag, net_buf_tailroom(frag));
- len -= net_buf_tailroom(frag);
- }
+ net_buf_frag_add(chan->_sdu, frag);
return frag;
}
@@ -1017,7 +1009,8 @@ static void l2cap_chan_le_recv_sdu(struct bt_l2cap_le_chan *chan,
struct net_buf *frag;
uint16_t len;
- BT_DBG("chan %p len %u sdu len %u", chan, buf->len, chan->_sdu->len);
+ BT_DBG("chan %p len %u sdu %u", chan, buf->len,
+ net_buf_frags_len(chan->_sdu));
if (net_buf_frags_len(chan->_sdu) + buf->len > chan->_sdu_len) {
BT_ERR("SDU length mismatch");
@@ -1031,7 +1024,7 @@ static void l2cap_chan_le_recv_sdu(struct bt_l2cap_le_chan *chan,
while (buf->len) {
/* Check if there is any space left in the current fragment */
if (!net_buf_tailroom(frag)) {
- frag = l2cap_alloc_frag(chan, buf->len);
+ frag = l2cap_alloc_frag(chan);
if (!frag) {
BT_ERR("Unable to store SDU");
bt_l2cap_chan_disconnect(&chan->chan);
@@ -1039,12 +1032,11 @@ static void l2cap_chan_le_recv_sdu(struct bt_l2cap_le_chan *chan,
}
}
- BT_DBG("frag %p tailroom %u len %u", frag,
- net_buf_tailroom(frag), buf->len);
-
len = min(net_buf_tailroom(frag), buf->len);
memcpy(net_buf_add(frag, len), buf->data, len);
net_buf_pull(buf, len);
+
+ BT_DBG("frag %p len %u", frag, frag->len);
}
if (net_buf_frags_len(chan->_sdu) == chan->_sdu_len) {