Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp198445pxb; Tue, 31 Aug 2021 19:02:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQTNKkowsv9Qzptmd3zgP9420MSj9Lo/VWc0R/aok0sp+x7KnBTVLrX4j0p2vY+ITGmpJR X-Received: by 2002:aa7:c4c3:: with SMTP id p3mr32560578edr.122.1630461733584; 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=cCDCQKYFaOvzRqtul7zlpF79kWDgUdNlG+TcA5a8cczjyaZiW3VT3AN0PgIlDXAqYG YOvFSZKsLCmUY5D70SKMJY9fM54PA/wiFk38mVGB5Und5gLORDVNdTW71DndUujgcNrE FywrskHECdYUhg0yjwSBC/XNQAa8bfVDevJqu4XfdDlJx15Mffop8ubHC7rOmhZMqrm0 pa5MmopMMAzkSWbQIPWiPbhLtLdgKtJrDE0EN39af8JdQfe+1JbFpY4IKe56eD9weHaU 2n2AdvZHcXgmcVRK1hGdMAohEaNxcRa6CKyD3WTObrr1w5tsM4/DNOq5zFAOO0TwWklX nwrg== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=oyY+Qj1v1ce0ewZFAidlMwWq7Ceg2ohLUWvByrJdMb8=; b=H+4m+84+OBhWcrrisR/zhBGT4udJSFVxuBonUXaLoHPpblYuRaAAmSlBmdt0JozNN/ ni7e9Zp0GXDvaRxDHN3xJH+RSLUINMGznmRT1O3ZQciUcA/6LRCgSWlwWz9nCC2zX3NY sQ0zY6xMJZER0XnMqIEuBSuNGoOvAkRZ2a22Oi8XaKwQEhhjsQyxubvH6CbntGHPfd/Y vUfzSzAnoqy5g7mhu4edzlDm2mgUp3pl2mzBQa/KAuOB8gGWt+3FRcrclEr/F0SMNoU4 phYvLOTamZO/YUrh9un9v000McYqzEsYMGqeEfZ0BisJgsK9fd/1/jVXYqzENdMJ/9yB Nh5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VxniagMm; 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 z26si870664ejc.486.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=VxniagMm; 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 S241443AbhIAA1V (ORCPT + 99 others); Tue, 31 Aug 2021 20:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241398AbhIAA1U (ORCPT ); Tue, 31 Aug 2021 20:27:20 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47CC5C061575 for ; Tue, 31 Aug 2021 17:26:24 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id g184so975468pgc.6 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:in-reply-to:references:mime-version :content-transfer-encoding; bh=oyY+Qj1v1ce0ewZFAidlMwWq7Ceg2ohLUWvByrJdMb8=; b=VxniagMmuRoe0vPC7fMMyZrC7D8p0oR66J9dHFuS5Gddk0/CTSjKxdClDpcDVcd/pf 2/rzUJGy0v/D4OEFKY6SqDGTcvk5OF9HPLVrN2JBisAWvvZJLdjeYZUpb+dTbeZpo0X0 7/kClKWcK6jttbU6O/jXTPhjx1j5toe8IHcFcrYJXTjtPzqydgRkHi8I3UGyMfc8y8a7 Ik3CcP8pyJupBTy7k0leemoSj95y1TuUTzhZPLtKwlzwA6UgnNPGWVOtjhajjI9jRtz1 dljauwkVNtn55SfZnXpg2EdHm4mUWvpFevHyi2zskJ0AfM5Y0FX+083ckLBk+YBkCTa8 rXfA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=oyY+Qj1v1ce0ewZFAidlMwWq7Ceg2ohLUWvByrJdMb8=; b=T/d3CQQb3HtreTy8yh1dR+SjltxdbXst/BUd9aICVGH8v+bl0XmP8BmM0pMP7dvkiR SUfEdsRRR/Kj2kT3IqHCfjeetYz/ZoXw221u8aW0c137eQUE7clYtnVGX2BK1oiJ9ofZ Z30YykAFuTwV61jhNs1uJlytTEbXZCdY7E2sDrP4pJ70/50oLviFAeVMYFGYr+x5XSlv VAJk0akEt+fMCUWN/YKeSjvYJq+Vue61kaHsmBSX7qBxm8Q+vppwOK06zRCSt+W7Q9Xs ic2i0twDObHjnVtIPTXdaEk9LMGKO8BVfoMeWkRk4qg2FxDmg7PPr7+ePO1FKnxYb1pA S4dg== X-Gm-Message-State: AOAM532u7iWWgYAuaQxCmmaBOMv2SrinKsDaIf7gGG52py9weQnoaQrU vMYaoWc3B8oJHs+Mztkl29c9wSbJh7o= X-Received: by 2002:a62:1ec7:0:b0:3eb:2693:90e2 with SMTP id e190-20020a621ec7000000b003eb269390e2mr31234147pfe.52.1630455983512; Tue, 31 Aug 2021 17:26:23 -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.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 17:26:23 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 3/4] Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg Date: Tue, 31 Aug 2021 17:26:20 -0700 Message-Id: <20210901002621.414016-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901002621.414016-1-luiz.dentz@gmail.com> References: <20210901002621.414016-1-luiz.dentz@gmail.com> 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 This makes use of bt_skb_sendmsg instead of allocating a different buffer to be used with memcpy_from_msg which cause one extra copy. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/sco.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index b62c91c627e2..60fb4dc73bc2 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -280,27 +280,19 @@ static int sco_connect(struct hci_dev *hdev, struct sock *sk) return err; } -static int sco_send_frame(struct sock *sk, void *buf, int len, - unsigned int msg_flags) +static int sco_send_frame(struct sock *sk, struct sk_buff *skb) { struct sco_conn *conn = sco_pi(sk)->conn; - struct sk_buff *skb; - int err; /* Check outgoing MTU */ - if (len > conn->mtu) + if (skb->len > conn->mtu) return -EINVAL; - BT_DBG("sk %p len %d", sk, len); + BT_DBG("sk %p len %d", sk, skb->len); - skb = bt_skb_send_alloc(sk, len, msg_flags & MSG_DONTWAIT, &err); - if (!skb) - return err; - - memcpy(skb_put(skb, len), buf, len); hci_send_sco(conn->hcon, skb); - return len; + return skb->len; } static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) @@ -722,7 +714,7 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { struct sock *sk = sock->sk; - void *buf; + struct sk_buff *skb; int err; BT_DBG("sock %p, sk %p", sock, sk); @@ -734,24 +726,20 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg, if (msg->msg_flags & MSG_OOB) return -EOPNOTSUPP; - buf = kmalloc(len, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - if (memcpy_from_msg(buf, msg, len)) { - kfree(buf); - return -EFAULT; - } + skb = bt_skb_sendmsg(sk, msg, len, 0, 0); + if (IS_ERR_OR_NULL(skb)) + return PTR_ERR(skb); lock_sock(sk); if (sk->sk_state == BT_CONNECTED) - err = sco_send_frame(sk, buf, len, msg->msg_flags); + err = sco_send_frame(sk, skb); else err = -ENOTCONN; release_sock(sk); - kfree(buf); + if (err) + kfree_skb(skb); return err; } -- 2.31.1