Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp479165imn; Wed, 27 Jul 2022 11:20:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tzgxo7PSkEjz9KVO2xSWm7HTQDGPfLLpH1vKLdMQix3lCwWcClbjl3eT33RyyWMLDM+2Nf X-Received: by 2002:a17:907:75e3:b0:72b:198a:b598 with SMTP id jz3-20020a17090775e300b0072b198ab598mr18561912ejc.401.1658946038438; Wed, 27 Jul 2022 11:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946038; cv=none; d=google.com; s=arc-20160816; b=hbdQzHn+cjqlQXwFuwc8WHqJ9sAL3RTq2wP3ebd3yxQe72bF9YR/9pQsZe3UT2358z SlC1wxhjbfvy+yJfVDC9StK5I1M2qIeP8rmSBPn0oAtP9GgPqm/DSMFhAhcH/wTmhFCO XnvHJN3H1ywYKTpg8R7DigaQY9Iqc3gaDTL7MXF2JKX4JtBOzuJI8G9DFbreaee0rjsH 9is2Gd3vSeevWyv8xinmRZRk+yK+UaEZ/gv0V9uZi6xwN277e563KwNpk1gFVD2zDvJP sjtHXLLpspy8lWCYTG5sn07H9yYmF8wyxmrXFQqLa7qVm5biOcTJQ178Fcw2ru00XAkG NGlA== 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=NiyrGAk467uAgrEf57kpl7ZUsNxotVVgCbF0S+gKWdM=; b=RKV51ic6SzLpD+HsexPQT/i/9RBDypV31Sj4xGUi1j27BiTcJAfT23Mx8EnyJ/bOTP MQHFNsGTLZVYAb+7CYhiWbgX0PqELAFx5S4wLssbcVACBCclDAIcApi9xKf08CxnhoUF eykEyya26S1zekhot5fSsYbiN0gqD7eaiN65VPDNiBkqt3oBVKsWNxupMmhsD/p8K/Zt Lx4bA4k/13DoB+y+oEdyPWscGMkBwVUcjjyJw7ATQ7/LKl24WaWh1+HPnB9fAKp4DS3E fQ+sCrteAuJ67+DIReCA4wfJAAV8UWbvN2hDJtvBB5XFbgkWig1t69Rx6b+VydwSi7xh 3/rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vb5R2psm; 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 ej27-20020a056402369b00b0043bcafe41c9si17114716edb.2.2022.07.27.11.20.13; Wed, 27 Jul 2022 11:20:38 -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=vb5R2psm; 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 S237191AbiG0QeH (ORCPT + 99 others); Wed, 27 Jul 2022 12:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236541AbiG0Qda (ORCPT ); Wed, 27 Jul 2022 12:33:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 592DF54C8A; Wed, 27 Jul 2022 09:26:42 -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 E93CDB821B6; Wed, 27 Jul 2022 16:26:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FC1EC433D6; Wed, 27 Jul 2022 16:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939195; bh=MOCVpztG29Nt42exOx0JADtWROu433VsUJTiTZsPNxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vb5R2psmwryUXw5cP1vl6c547/psvO84IXh+lo/g5WWB92Fp908Y2C/i1E3GnmobK jRkyz9uBHQNTZokoOa0cHtLupuAJxtysyJvEgqjlw2JZ2t5eH337IijVs6S9vOrByY mxO88aGvM2EjtPG2YapM0Ha0wE1LMiYoba+M3++E= 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.19 45/62] Bluetooth: Add bt_skb_sendmsg helper Date: Wed, 27 Jul 2022 18:10:54 +0200 Message-Id: <20220727161005.918771230@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161004.175638564@linuxfoundation.org> References: <20220727161004.175638564@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 @@ -370,6 +370,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);