Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp485940imn; Wed, 27 Jul 2022 11:31:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1snYwBEqC1crJ3OpU1xoOz6yigF0DmI/sp23tqTCbqBTEaPnf3nATdLNLd8ZOCR/LXIAzpr X-Received: by 2002:a05:6a00:1412:b0:528:47a6:8569 with SMTP id l18-20020a056a00141200b0052847a68569mr23083895pfu.39.1658946718519; Wed, 27 Jul 2022 11:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946718; cv=none; d=google.com; s=arc-20160816; b=WsA2MjSOSuvJEgc7h/CiTWlypXZCJPV3UzllUPkplZeZ/CJUNBQwUwuY+DeNFXPzzk 4343UHNffncrG0wWXl5KsWVdLX3mm4luG3d6QnTiqnftkY1y+VyJf080lCUO7rp5MKrp EFLYaAz6u5fZaNPECFkKwUR5w4wMUExsv8vSQposf9KzcINwQE9eQUJxodHcIIBGg8zG CWOrrx2yQXm/crkbxEyL34MqRoQrIEfYqGLvDBc3R7mcyCPFbspZSgl6RF6JHztmKp3t KUibXDLROO3LyQE2hQeV9QTYShvHujbMohR+yzjVDsnVpQfEiRTFIt0Xp2n8SY9hCRA3 zMJQ== 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=49JnqhFjk/StQIaHthapc811E38Ezgig6OHXpbtjeHo=; b=p5nCuqQYWlW145GQXKllW5rvkjC2rs7ZkToM9KGpFcc2nvr9e1fgKf5nubbLkC26bs YeGBJpRl/0/A+zCfAH+3bIcU4tIqkFsljNC/NellIF0HutAck2jrGB54Et719D3IBRVZ RjfziUh5R2vElcRs4WzXzVra99TViN6mADS9GHbcWSXnRnIrL+sn9zrbt4cf8wx6eIAR 8fdW+DFGKEmtEbvMc8I6HvUrgFBhdTJZk36Q61dM/FCwhNFEjEcHXqiJ0mzARpO15JR0 qBmUdGSZ94qvkwQ6wxESSc59V3eoiTiIKRTlxkY1aZ2+MxR4l/BugWRFM7+jenZc1INS 9tIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OGFVrkB6; 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 u12-20020a170902a60c00b0016be35eabdfsi18780794plq.367.2022.07.27.11.31.42; Wed, 27 Jul 2022 11:31:58 -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=OGFVrkB6; 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 S242064AbiG0RZr (ORCPT + 99 others); Wed, 27 Jul 2022 13:25:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242243AbiG0RYp (ORCPT ); Wed, 27 Jul 2022 13:24:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86115F9A6; Wed, 27 Jul 2022 09:46:21 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C293C60DDB; Wed, 27 Jul 2022 16:46:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF6EEC433D6; Wed, 27 Jul 2022 16:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940372; bh=7cxcXXPeU7k5QbBJxp1iNTuJ664l3od0idVpycl5vRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OGFVrkB6f3JJo5Zp6bZVlArSwn85rMEegMFIKf/oZwZ7dTpfMTW1++T5ECb3m6j7I ywBhsEDGQbJe7r1JYwxyUqfuv9LFzirV62NMihCsD9Z7wDhDb7M/JvLM0uPTpbAJvj AHUV7ycPOAPxDa7kFCTyWurJcjg7aqw5/oKQ+cSg= 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 5.15 174/201] Bluetooth: Add bt_skb_sendmsg helper Date: Wed, 27 Jul 2022 18:11:18 +0200 Message-Id: <20220727161035.014956207@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@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 @@ -422,6 +422,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);