Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp503345imn; Wed, 27 Jul 2022 12:02:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vVctiTodiq6A1q9gUU7jJTaxQ08JffhBg/bikApI2tjSwGJxrKhcD8SjtnbWBe77oOZSeX X-Received: by 2002:a17:906:4fc5:b0:72b:9943:6f10 with SMTP id i5-20020a1709064fc500b0072b99436f10mr18888964ejw.722.1658948557559; Wed, 27 Jul 2022 12:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658948557; cv=none; d=google.com; s=arc-20160816; b=0cPtAA4wHWOOd+i4vd+YhG/3o6OlblOuv13ivauBWADS95s56J7kOrNqHjAn9mv1bK uhDoVoYs+eVvP3Fep/5Y3fjDWTgU5y7FLfpyA0UN9x+fK9yb+k7vP2Ogye9w7EYaLbXD 1sZPiqvuyllLxKJ31w6W0MHTctmdooLSOn8ms/U0C2d7Cl9mWWzGaN6QZwptm9b7luYF m0h6bczRfE6ECSDoYcj0Ytv0lIzegTzTqCWojBNat2g6chrXn3DkmIQ5OnN2Cx3oFMBK xomH+/AOoEwCxQwJUsGF9i/yZaESq8wbCiwVADk+0CP92sb9L8Oh7zyIQHp2rDf2ZfCe XELA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HTrUvDEtvdy8qtnCGuzF7b1CJAoP6iNS+riZoq2UZrA=; b=GsBU5IvyFZ5VblPA5oxk3tHr+8eh4B+ZkDiTJEUVdFTMJrIVxF2wD1+oyNc8j/ECTv f7FW/a2CPrI2pEEif9bFo0cB4UPiXbZBzJ4eoZkEdbKcBexK61w3XJnP0+LkNKPG5OMR uOj6v/IVYzi8SdmxV2mdRI/jYBGIPCfZMWJux9OowJDFJRaVDoz1tVjfWlAOobhRZdr2 f4G1peyeRLKRfi6nVqHD741dc1I//KOHeNKRscAjXA+kkCLpbQsenA7xOXzwLLTtWsVL uUYZuxS7l9egM3zMk8mbgLzGTnu7Y3sZC5N/1z1r39SsH+6feRQA6VdUSyCGpAzo6u67 R6Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kuqGzMaE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw15-20020a170906478f00b0072f36fddba7si22774595ejc.812.2022.07.27.12.02.11; Wed, 27 Jul 2022 12:02:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kuqGzMaE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236883AbiG0Q0v (ORCPT + 99 others); Wed, 27 Jul 2022 12:26:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236428AbiG0QZu (ORCPT ); Wed, 27 Jul 2022 12:25:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E80C44F185; Wed, 27 Jul 2022 09:23:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 870AAB821BC; Wed, 27 Jul 2022 16:23:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD6FFC433D7; Wed, 27 Jul 2022 16:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939015; bh=u4byFlQJsz3ZevS0sUJUuzhJBaAdVaUfUAUmILwEF9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kuqGzMaElK2yAcmgP1qp/B7nlmv0VAwemKlvKWIUuxAAadqjlgjkdCZ2kNOGnXg0U ShKiTFQCuzBPLkWV94I4n+YRmPcHTGEw39TbNMnlPblfE/K8gPetb5nW+ExcjPNKki JpUfElLzYuZgJhQmXfdduJ5uF5DJYImOLPTr886g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 4.14 21/37] Bluetooth: Add bt_skb_sendmsg helper Date: Wed, 27 Jul 2022 18:10:47 +0200 Message-Id: <20220727161001.682182744@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161000.822869853@linuxfoundation.org> References: <20220727161000.822869853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luiz Augusto von Dentz commit 38f64f650dc0e44c146ff88d15a7339efa325918 upstream. 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 Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman --- include/net/bluetooth/bluetooth.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -367,6 +367,34 @@ out: 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);