Commit f11d676d authored by Gustavo F. Padovan's avatar Gustavo F. Padovan Committed by Marcel Holtmann

Bluetooth: Refactor l2cap_retransmit_frame()

Make the code flow cleaner and changes the function to void.
It also fixes a potential NULL dereference with skb.
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
Reviewed-by: default avatarJoão Paulo Rechi Vita <jprvita@profusion.mobi>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 9a9c6a34
...@@ -1331,43 +1331,44 @@ static int l2cap_streaming_send(struct sock *sk) ...@@ -1331,43 +1331,44 @@ static int l2cap_streaming_send(struct sock *sk)
return 0; return 0;
} }
static int l2cap_retransmit_frame(struct sock *sk, u8 tx_seq) static void l2cap_retransmit_frame(struct sock *sk, u8 tx_seq)
{ {
struct l2cap_pinfo *pi = l2cap_pi(sk); struct l2cap_pinfo *pi = l2cap_pi(sk);
struct sk_buff *skb, *tx_skb; struct sk_buff *skb, *tx_skb;
u16 control, fcs; u16 control, fcs;
skb = skb_peek(TX_QUEUE(sk)); skb = skb_peek(TX_QUEUE(sk));
do { if (!skb)
if (bt_cb(skb)->tx_seq != tx_seq) { return;
if (skb_queue_is_last(TX_QUEUE(sk), skb))
break;
skb = skb_queue_next(TX_QUEUE(sk), skb);
continue;
}
if (pi->remote_max_tx && do {
bt_cb(skb)->retries == pi->remote_max_tx) { if (bt_cb(skb)->tx_seq == tx_seq)
l2cap_send_disconn_req(pi->conn, sk);
break; break;
}
tx_skb = skb_clone(skb, GFP_ATOMIC); if (skb_queue_is_last(TX_QUEUE(sk), skb))
bt_cb(skb)->retries++; return;
control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
| (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
if (pi->fcs == L2CAP_FCS_CRC16) { } while ((skb = skb_queue_next(TX_QUEUE(sk), skb)));
fcs = crc16(0, (u8 *)tx_skb->data, tx_skb->len - 2);
put_unaligned_le16(fcs, tx_skb->data + tx_skb->len - 2);
}
l2cap_do_send(sk, tx_skb); if (pi->remote_max_tx &&
break; bt_cb(skb)->retries == pi->remote_max_tx) {
} while(1); l2cap_send_disconn_req(pi->conn, sk);
return 0; return;
}
tx_skb = skb_clone(skb, GFP_ATOMIC);
bt_cb(skb)->retries++;
control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
| (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
if (pi->fcs == L2CAP_FCS_CRC16) {
fcs = crc16(0, (u8 *)tx_skb->data, tx_skb->len - 2);
put_unaligned_le16(fcs, tx_skb->data + tx_skb->len - 2);
}
l2cap_do_send(sk, tx_skb);
} }
static int l2cap_ertm_send(struct sock *sk) static int l2cap_ertm_send(struct sock *sk)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment