Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp198444pxb; Tue, 31 Aug 2021 19:02:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweFHoai/9G3L3g5yQ1CW12LormOyaVKeTKroEpQhXOeSJT5v1pN4nvdl6xKYhJtA4T3V45 X-Received: by 2002:a17:906:4452:: with SMTP id i18mr34820482ejp.374.1630461733588; Tue, 31 Aug 2021 19:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630461733; cv=none; d=google.com; s=arc-20160816; b=lh9RRQJcDXlrkBHc6VIZsnwOEKmoKVAhpeZxekp5T9z6P1ovFKbeW0lnugZRfOFCHR OW7qHMhgzIWp/WHnpIOen6n7barJTuEV0vz2qGp7OG++SlJdDoMDhuz+9ZCzeA8Sn28L 1W+oNZHLTI7fDrcB8w0aSb6nChIEumMAKO0djjjOcCu5zCNAnSe/+/RuPw9r/ddF4x3A hBLVBMFEuFqHZgeDeN0gE7X4/vmjV/XM5DPLBhqNGkk8DIymv3TF/QLNm2UH7wYv3AaI P9FRjnvrQ5sl41UoerPj2eu3Am3JXpcmleHLtFnnROdg9dFQd4vebnKvQpik4oQJJLdA GHoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=oV91TlQ/uyvI2F8HVAFusfi8G+Q5pnpGFBPBrBkciLA=; b=qyll41O9wMuwYf5XaKVLFRVmdKG6S2cIa8E8jKDubAI+gxXEBfc1SZfFyhKPNTJfoe eY565ag5ffKC9qLZI1u8LmWUzVMw3JJhday8+Dbumn/G+5zbUwN96yU0k0+Z10MjJfS9 ZZk4sUQVS2vNJaFn7NdpQj+tFhTc3rferZbFbTNaYnFnZHZ/ZsqpLOeG647gfk19QOWn JtCO4EJo8i8j+NdDSs0MVbYMBWWWP/Kn0UkTLeodICLipX8u5qP/ebBQBw3CSr5PLYd4 I+B98FNOGtE5w3g+MTU9aei3LOZaHbbxXzUzy1jHZZvKapO3LxhJa92Uy6hlJOq3lG/K ODgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="mZJY/oca"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y28si98266ejk.264.2021.08.31.19.01.07; Tue, 31 Aug 2021 19:02:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="mZJY/oca"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbhIAA1U (ORCPT + 99 others); Tue, 31 Aug 2021 20:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbhIAA1T (ORCPT ); Tue, 31 Aug 2021 20:27:19 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B6DC061760 for ; Tue, 31 Aug 2021 17:26:24 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id x16so700892pfh.2 for ; Tue, 31 Aug 2021 17:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=oV91TlQ/uyvI2F8HVAFusfi8G+Q5pnpGFBPBrBkciLA=; b=mZJY/ocaN6AjdA65d6pe50IWkT7WSpv6+//ptgBwH1ImMCTUwQI7rkrsNs/qcPHN03 /1GjAUv5HR3+QHWJgycHtW7Fu8AFYfs040FpFE/9U5ieoEySafctP2e4c8YSQP6cajZz z0cd6+40fmIhJrC/RCLTWxsISRx509G/JZQDGbywMFUP9aDM0hisrBQva0xzU3RXAXOi RWdr2a2KkpZOJicFdVK5BupulPkvADDmrmfUSMjAwM3BBwMc7GLAy4L+9hXnka7vLREg 0bxYGQdWdbGR30xM2oAJWZELy7R7r1d67CDNRHLQR1piYqfSaPbTlRbGf7q4kPXo7ycl SaqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=oV91TlQ/uyvI2F8HVAFusfi8G+Q5pnpGFBPBrBkciLA=; b=mxMNQQs+FgklpXi+l6ZzTmENpxgty3dFy9ZkZOhD/W/+GRdoZkKhvanjPYVPWnNKQI Sm6GvpSuDHniQVJigjKta3FvRoQinnASkh9TrcKV4Ex58ctg86nGz3hvNoGtrxb//YqH +lkgkNbnbFNb590AOslfzNxdhbWP02U0nwwNLvAjw51kA+BeeLkZNdzY213ZItF3s6Dp 11OYANPKWmJbCQDPwyXETjBaSPGqxAjzI5i+AuxpuCURWUeiqszHO4o+TUancebM0w+a 0ObjXHmekXPomp+zlQvF4J86vIj1HZFLi5Cgn1+x0MWflriFxgWHOI5MjqNh8XlcUmLT 5bmQ== X-Gm-Message-State: AOAM531Fziu39YcLXiZD+udd7BEL7aDy0pP4ggAnuKkCgXLzp8VPsY9O 2NLY3p43qiPUvGtb/+kooOamyhaZYeQ= X-Received: by 2002:a62:cf86:0:b029:3e0:7cef:9e03 with SMTP id b128-20020a62cf860000b02903e07cef9e03mr31566411pfg.0.1630455982143; Tue, 31 Aug 2021 17:26:22 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id gm5sm4054655pjb.32.2021.08.31.17.26.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 17:26:21 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 1/4] Bluetooth: Add bt_skb_sendmsg helper Date: Tue, 31 Aug 2021 17:26:18 -0700 Message-Id: <20210901002621.414016-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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 --- 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