All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Bluetooth: Add bt_skb_sendmsg helper
@ 2021-09-01  0:26 Luiz Augusto von Dentz
  2021-09-01  0:26 ` [PATCH 2/4] Bluetooth: Add bt_skb_sendmmsg helper Luiz Augusto von Dentz
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-09-01  0:26 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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 <luiz.von.dentz@intel.com>
---
 include/net/bluetooth/bluetooth.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 9125effbf448..f858efcf9f40 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -420,6 +420,32 @@ 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 header,
+					     size_t footer)
+{
+	struct sk_buff *skb;
+	int err;
+
+	skb = bt_skb_send_alloc(sk, len + header + footer,
+				msg->msg_flags & MSG_DONTWAIT, &err);
+	if (!skb)
+		return ERR_PTR(err);
+
+	skb_reserve(skb, header);
+
+	if (memcpy_from_msg(skb_put(skb, len), msg, len)) {
+		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);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-09-03  9:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  0:26 [PATCH 1/4] Bluetooth: Add bt_skb_sendmsg helper Luiz Augusto von Dentz
2021-09-01  0:26 ` [PATCH 2/4] Bluetooth: Add bt_skb_sendmmsg helper Luiz Augusto von Dentz
2021-09-01  0:26 ` [PATCH 3/4] Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg Luiz Augusto von Dentz
2021-09-01  0:26 ` [PATCH 4/4] Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg Luiz Augusto von Dentz
2021-09-03  9:02   ` [Bluetooth] e1ce6a3427: BUG:unable_to_handle_page_fault_for_address kernel test robot
2021-09-03  9:02     ` kernel test robot
2021-09-01  2:02 ` [1/4] Bluetooth: Add bt_skb_sendmsg helper bluez.test.bot
2021-09-01  5:44 ` [PATCH 1/4] " Marcel Holtmann
2021-09-01 19:16   ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.