Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1399011pxb; Wed, 2 Feb 2022 04:12:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGwdAEcI7rzcSljWHhp45/BaGWkFcPj4e4aIod2r3yw5BnlfV/zePxeWT6jUZNXOHF0aVu X-Received: by 2002:a63:6947:: with SMTP id e68mr11686236pgc.94.1643803973175; Wed, 02 Feb 2022 04:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643803973; cv=none; d=google.com; s=arc-20160816; b=IQ63AbL7T9HU3BAxEjZY/4Kv3cBiHmKH4iJBMI92c0jM6YdiCeODQ2egnqm82p7hlI 6bBLP92rNYBh24AvPIX7QNog9kKfsFU8dBbqJoM4V8EQ/S1wbQ9yo7Z5mDo3N1QdM2v1 Zz9reXDNcrO40+nZidX4C+gA24GaTjWETf7kAfcN0+Ar7v4bveoFRi2Jd2wEm/eVBG9T 3hbbuvz1ErMglVc0egt3JFRU5zO3yJnMVCX5loIcRubnGUhymYBloO1Y/SiJKmOVLmdu j3ei1DDHwwq3dpYVE5b8miDS/0cv8WOZKe/eTJvhZvnwklwX7XQpKallUckZbpUYSzgO nPkw== 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:cc:to:from :dkim-signature; bh=/QTYMxwWed/jQIivtJaGb3o5ZDyC8gqB+NImkJjoA+M=; b=NYdt/939hjj8/kghZPaRvfVhBjopORaa2tlU7BNMDA8RYLsdYWQuPBuuuzaYBrjVLQ VkyAtUf2HLvzABkX4PtsRJTP6MSkhzRNKanMCfek7TQns2pDGb/D4dwTQ6DqJdLJnBZh xS2ntmonCR/VRzaxMJrlroVyg064Kl0CLfPX5/YNRMRhpQdjsLew6+ug6Yv6c0NVEZje aLgdjKwo3qzLRW7dc2QMYAZHBuQGI8Hc4+76h60ngey01yVflIG4PltDY5Po3Plggnxw zYYNCa+syp9HPG4lgrcSCYkcNElGjtl0Bvo5jEo1k1B2DBuxAF0Dorx/ZJ14rF/N3u7b O6hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20210112.gappssmtp.com header.s=20210112 header.b="R2s/WYxq"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 82si18835060pgd.518.2022.02.02.04.12.40; Wed, 02 Feb 2022 04:12:53 -0800 (PST) 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=@semihalf-com.20210112.gappssmtp.com header.s=20210112 header.b="R2s/WYxq"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236390AbiBAUEF (ORCPT + 99 others); Tue, 1 Feb 2022 15:04:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235924AbiBAUEA (ORCPT ); Tue, 1 Feb 2022 15:04:00 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7E48C061714 for ; Tue, 1 Feb 2022 12:03:59 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id e8so34229519wrc.0 for ; Tue, 01 Feb 2022 12:03:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/QTYMxwWed/jQIivtJaGb3o5ZDyC8gqB+NImkJjoA+M=; b=R2s/WYxqrkrLqzzep4rDEqMSd1N/6u42Y0fF6kR/9+RQCyhZVXbJaJN/ugywk8HMnn NcoM405UM/+ErO67Cclrqd2Lx1QAebg5/WSP+C1S2RslP3RTYbCghiAXZECfuOMxriu6 JwaIOtSQSL+JtYd/FG4MRGbDtX+f0lU7jtRjk679xtxiWKG3zrFAdXLyKjIvvJxnlG/s RxKL6S1HJwJrhIXCghSnn8DciIt22mQXtBX1X8YEztUhR6v93wntQ/2RYqo9xBDqWVqR U3WV+cb/YXe8g0kF2u1s9e2T++GBKgpdo05cVeDztvC1YmEnsYEGUVFztViQ143Nj+mk dUnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/QTYMxwWed/jQIivtJaGb3o5ZDyC8gqB+NImkJjoA+M=; b=cJuIlMvBstN5G71gCo0Aryt5cqIJW/jrd+K0apIeQIbma45jdabCCeTqp+P10fs8Ax GZewR6wJ+Qoo5YqiS1KhMHkybfuMxdZRpV7cnktx/i8QnwWqc4AUjwvJmdX5WriOXhXB bhCQ1C6K+e3X7z+gwK6ffFx/Dlobbnrs1HCXl8v0rC8Kx6iquIq3X7kOaZPiPI3QXwT2 lhWrGKOZPDeV6WHv6JNR/S6uE3vAYXW03fP61im6m3A1+nz8np+n0M8OkweIuDpyBoZ4 L/21ouujiQfSFBwdyYloksF/CAtpxM4Cq1j9fLC3oQhtfbE+vE4OVBZ9LZuyf1pdjARo 1h4g== X-Gm-Message-State: AOAM532GCpVYxuUlYZY/s0FvgucISm8a602j+2aUriNgTqij5BAqaWHY nrWgZ7feSdVYybMYAqwgP/0pDw== X-Received: by 2002:a5d:500c:: with SMTP id e12mr23426786wrt.187.1643745838279; Tue, 01 Feb 2022 12:03:58 -0800 (PST) Received: from biernacki.c.googlers.com.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id m6sm3367280wmq.6.2022.02.01.12.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 12:03:57 -0800 (PST) From: Radoslaw Biernacki X-Google-Original-From: Radoslaw Biernacki To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Miao-chen Chou , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, upstream@semihalf.com, Radoslaw Biernacki , Angela Czubak , Marek Maslanka , Radoslaw Biernacki Subject: [PATCH v2 2/2] Bluetooth: Improve skb handling in mgmt_device_connected() Date: Tue, 1 Feb 2022 20:03:53 +0000 Message-Id: <20220201200353.1331443-3-rad@semihalf.ocm> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220201200353.1331443-1-rad@semihalf.ocm> References: <20220201200353.1331443-1-rad@semihalf.ocm> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduce eir_skb_put_data() that can be used to simplify operations on eir in goal of eliminating the necessity of intermediary buffers. eir_skb_put_data() is in pair to what eir_append_data() does with help of eir_len, but without awkwardness when passing return value to skb_put() (as it returns updated offset not size). Signed-off-by: Radoslaw Biernacki --- net/bluetooth/eir.h | 15 +++++++++++++++ net/bluetooth/mgmt.c | 25 ++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/net/bluetooth/eir.h b/net/bluetooth/eir.h index e5876751f07e..43f1945bffc5 100644 --- a/net/bluetooth/eir.h +++ b/net/bluetooth/eir.h @@ -41,6 +41,21 @@ static inline u16 eir_append_le16(u8 *eir, u16 eir_len, u8 type, u16 data) return eir_len; } +static inline u16 eir_skb_put_data(struct sk_buff *skb, u8 type, u8 *data, u8 data_len) +{ + u8 *eir; + u16 eir_len; + + eir_len = eir_precalc_len(data_len); + eir = skb_put(skb, eir_len); + WARN_ON(sizeof(type) + data_len > U8_MAX); + eir[0] = sizeof(type) + data_len; + eir[1] = type; + memcpy(&eir[2], data, data_len); + + return eir_len; +} + static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type, size_t *data_len) { diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 43ca228104ce..4a24159f7dd6 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -9087,18 +9087,12 @@ void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, skb_put_data(skb, conn->le_adv_data, conn->le_adv_data_len); eir_len = conn->le_adv_data_len; } else { - if (name_len > 0) { - eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, - name, name_len); - skb_put(skb, eir_len); - } + if (name) + eir_len += eir_skb_put_data(skb, EIR_NAME_COMPLETE, name, name_len); - if (memcmp(conn->dev_class, "\0\0\0", 3) != 0) { - eir_len = eir_append_data(ev->eir, eir_len, - EIR_CLASS_OF_DEV, - conn->dev_class, 3); - skb_put(skb, 5); - } + if (memcmp(conn->dev_class, "\0\0\0", sizeof(conn->dev_class))) + eir_len += eir_skb_put_data(skb, EIR_CLASS_OF_DEV, + conn->dev_class, sizeof(conn->dev_class)); } ev->eir_len = cpu_to_le16(eir_len); @@ -9798,13 +9792,10 @@ void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, ev->addr.type = link_to_bdaddr(link_type, addr_type); ev->rssi = rssi; - if (name) { - eir_len = eir_append_data(ev->eir, 0, EIR_NAME_COMPLETE, name, - name_len); - skb_put(skb, eir_len); - } else { + if (name) + eir_len += eir_skb_put_data(skb, EIR_NAME_COMPLETE, name, name_len); + else flags = MGMT_DEV_FOUND_NAME_REQUEST_FAILED; - } ev->eir_len = cpu_to_le16(eir_len); ev->flags = cpu_to_le32(flags); -- 2.35.0.rc2.247.g8bbb082509-goog