Skip to content

Commit

Permalink
Bluetooth: Add bt_skb_sendmsg helper
Browse files Browse the repository at this point in the history
bt_skb_sendmsg helps takes care of allocation the skb and copying the
the contents of msg over to the skb while checking for possible errors
so it should be safe to call it without holding lock_sock.

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
Signed-off-by: Marcel Holtmann <[email protected]>
  • Loading branch information
Vudentz authored and holtmann committed Sep 13, 2021
1 parent 2fc7acb commit 38f64f6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/net/bluetooth/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,34 @@ static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
return NULL;
}

/* Shall not be called with lock_sock held */
static inline struct sk_buff *bt_skb_sendmsg(struct sock *sk,
struct msghdr *msg,
size_t len, size_t mtu,
size_t headroom, size_t tailroom)
{
struct sk_buff *skb;
size_t size = min_t(size_t, len, mtu);
int err;

skb = bt_skb_send_alloc(sk, size + headroom + tailroom,
msg->msg_flags & MSG_DONTWAIT, &err);
if (!skb)
return ERR_PTR(err);

skb_reserve(skb, headroom);
skb_tailroom_reserve(skb, mtu, tailroom);

if (!copy_from_iter_full(skb_put(skb, size), size, &msg->msg_iter)) {
kfree_skb(skb);
return ERR_PTR(-EFAULT);
}

skb->priority = sk->sk_priority;

return skb;
}

int bt_to_errno(u16 code);

void hci_sock_set_flag(struct sock *sk, int nr);
Expand Down

0 comments on commit 38f64f6

Please sign in to comment.