Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp271672pxb; Wed, 11 Nov 2020 03:21:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgu7zr8tGgw5hW8Wxamxnt++G/imGuHA3lMxq25oDx+qNU99xzxi9uJdieOxs3zrOxNKHp X-Received: by 2002:a17:906:a88:: with SMTP id y8mr24640469ejf.469.1605093692816; Wed, 11 Nov 2020 03:21:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605093692; cv=none; d=google.com; s=arc-20160816; b=vZAB6OlaA0Upn/NfmLKD1l+uVjZdFKSqCqiY82u3zHADq3icZsa15JQ0IHJ88eYlhZ bdXW47KrZsflzpMF2JiofIdvE9jlXLFOl6kaQKNtxBQsnjT0lRvTBDLFIUG/3MbXaRtL zsYb50wjU1FZj0uqAhPBIxcgVw5L3yAl7D8NewxtJNa4Ep4O41ju0/FhYZaVnvcapr6C OXkpAU0osyc+QAJuQEuajuc26RZhv6xTzz39S3W6frG1hqMCT6tH9LIf792a9F/e8iJM M93uB9tUa73Wl2xc0qXbnhaPG34zgp/zoKv1vKgEk/eDRCwciTWG6l5L/lmXVbve9W8L ZoOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=LJ0pw5z2T+zRaF3TrYPE4Lf1JHnl9gi16St98dkewAw=; b=n1nzeGuzbcc6zXcXCPKnM5c8ssI/VAQsMST+ETGgJIOuoH12Ndu7h3VGhL7IB+XPCa heNacEyZovK2ah8xXoPGUf5GOuZAQ+j10lQV5BmfHrU0gYLtTXp85OoUILGv7SE9c3pN uL1r6luDNdEDKVes/MrSMVbrz2f2rrMBT0Vy6wp5trjcm3L/o+mTuyssESQNgVzAa1UQ tSS9Z6OdMTNrTSlrohNmPXfi9NM4erPA3aCy0HTIpQa99xAxsFL4/aiVt5I6hmMVC7/V i0aRae1bjJQr/HSqolnd10pBxyEzcfkC7o4KhVOl9hDdv3d/EhpM3nI8tL5MkUxE01Jr b+zg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si1118685ejn.255.2020.11.11.03.21.07; Wed, 11 Nov 2020 03:21:32 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726207AbgKKLUa convert rfc822-to-8bit (ORCPT + 99 others); Wed, 11 Nov 2020 06:20:30 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:55225 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbgKKLU3 (ORCPT ); Wed, 11 Nov 2020 06:20:29 -0500 Received: from marcel-macbook.holtmann.net (unknown [37.83.201.106]) by mail.holtmann.org (Postfix) with ESMTPSA id 16C6FCECFE; Wed, 11 Nov 2020 12:27:35 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: [PATCH v9 5/6] Bluetooth: Refactor read default sys config for various types From: Marcel Holtmann In-Reply-To: <20201111150115.v9.5.I9231b35b0be815c32c3a3ec48dcd1d68fa65daf4@changeid> Date: Wed, 11 Nov 2020 12:20:25 +0100 Cc: linux-bluetooth , Luiz Augusto von Dentz , alainm@chromium.org, mmandlik@chromium.org, mcchou@chromium.org, "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: References: <20201111150115.v9.1.I55fa38874edc240d726c1de6e82b2ce57b64f5eb@changeid> <20201111150115.v9.5.I9231b35b0be815c32c3a3ec48dcd1d68fa65daf4@changeid> To: Howard Chung X-Mailer: Apple Mail (2.3608.120.23.2.4) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Howard, > Refactor read default system configuration function so that it's capable > of returning different types than u16 > > Signed-off-by: Howard Chung > --- > > (no changes since v8) > > Changes in v8: > - Update the commit title and message > > net/bluetooth/mgmt_config.c | 140 +++++++++++++++++++++--------------- > 1 file changed, 84 insertions(+), 56 deletions(-) > > diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c > index 2d3ad288c78ac..282fbf82f3192 100644 > --- a/net/bluetooth/mgmt_config.c > +++ b/net/bluetooth/mgmt_config.c > @@ -11,72 +11,100 @@ > #include "mgmt_util.h" > #include "mgmt_config.h" > > -#define HDEV_PARAM_U16(_param_code_, _param_name_) \ > -{ \ > - { cpu_to_le16(_param_code_), sizeof(__u16) }, \ > - { cpu_to_le16(hdev->_param_name_) } \ > -} > +#define HDEV_PARAM_U16(_param_name_) \ > + struct {\ > + struct mgmt_tlv entry; \ > + __le16 value; \ > + } __packed _param_name_ > > -#define HDEV_PARAM_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \ > -{ \ > - { cpu_to_le16(_param_code_), sizeof(__u16) }, \ > - { cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)) } \ > -} > +#define TLV_SET_U16(_param_code_, _param_name_) \ > + { \ > + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ > + cpu_to_le16(hdev->_param_name_) \ > + } > + > +#define TLV_SET_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \ > + { \ > + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ > + cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)) \ > + } > > int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, > u16 data_len) > { > - struct { > - struct mgmt_tlv entry; > - union { > - /* This is a simplification for now since all values > - * are 16 bits. In the future, this code may need > - * refactoring to account for variable length values > - * and properly calculate the required buffer size. > - */ > - __le16 value; > - }; > - } __packed params[] = { > + int ret; > + struct mgmt_rp_read_def_system_config { > /* Please see mgmt-api.txt for documentation of these values */ > - HDEV_PARAM_U16(0x0000, def_page_scan_type), > - HDEV_PARAM_U16(0x0001, def_page_scan_int), > - HDEV_PARAM_U16(0x0002, def_page_scan_window), > - HDEV_PARAM_U16(0x0003, def_inq_scan_type), > - HDEV_PARAM_U16(0x0004, def_inq_scan_int), > - HDEV_PARAM_U16(0x0005, def_inq_scan_window), > - HDEV_PARAM_U16(0x0006, def_br_lsto), > - HDEV_PARAM_U16(0x0007, def_page_timeout), > - HDEV_PARAM_U16(0x0008, sniff_min_interval), > - HDEV_PARAM_U16(0x0009, sniff_max_interval), > - HDEV_PARAM_U16(0x000a, le_adv_min_interval), > - HDEV_PARAM_U16(0x000b, le_adv_max_interval), > - HDEV_PARAM_U16(0x000c, def_multi_adv_rotation_duration), > - HDEV_PARAM_U16(0x000d, le_scan_interval), > - HDEV_PARAM_U16(0x000e, le_scan_window), > - HDEV_PARAM_U16(0x000f, le_scan_int_suspend), > - HDEV_PARAM_U16(0x0010, le_scan_window_suspend), > - HDEV_PARAM_U16(0x0011, le_scan_int_discovery), > - HDEV_PARAM_U16(0x0012, le_scan_window_discovery), > - HDEV_PARAM_U16(0x0013, le_scan_int_adv_monitor), > - HDEV_PARAM_U16(0x0014, le_scan_window_adv_monitor), > - HDEV_PARAM_U16(0x0015, le_scan_int_connect), > - HDEV_PARAM_U16(0x0016, le_scan_window_connect), > - HDEV_PARAM_U16(0x0017, le_conn_min_interval), > - HDEV_PARAM_U16(0x0018, le_conn_max_interval), > - HDEV_PARAM_U16(0x0019, le_conn_latency), > - HDEV_PARAM_U16(0x001a, le_supv_timeout), > - HDEV_PARAM_U16_JIFFIES_TO_MSECS(0x001b, > - def_le_autoconnect_timeout), > - HDEV_PARAM_U16(0x001d, advmon_allowlist_duration), > - HDEV_PARAM_U16(0x001e, advmon_no_filter_duration), > + HDEV_PARAM_U16(def_page_scan_type); > + HDEV_PARAM_U16(def_page_scan_int); > + HDEV_PARAM_U16(def_page_scan_window); > + HDEV_PARAM_U16(def_inq_scan_type); > + HDEV_PARAM_U16(def_inq_scan_int); > + HDEV_PARAM_U16(def_inq_scan_window); > + HDEV_PARAM_U16(def_br_lsto); > + HDEV_PARAM_U16(def_page_timeout); > + HDEV_PARAM_U16(sniff_min_interval); > + HDEV_PARAM_U16(sniff_max_interval); > + HDEV_PARAM_U16(le_adv_min_interval); > + HDEV_PARAM_U16(le_adv_max_interval); > + HDEV_PARAM_U16(def_multi_adv_rotation_duration); > + HDEV_PARAM_U16(le_scan_interval); > + HDEV_PARAM_U16(le_scan_window); > + HDEV_PARAM_U16(le_scan_int_suspend); > + HDEV_PARAM_U16(le_scan_window_suspend); > + HDEV_PARAM_U16(le_scan_int_discovery); > + HDEV_PARAM_U16(le_scan_window_discovery); > + HDEV_PARAM_U16(le_scan_int_adv_monitor); > + HDEV_PARAM_U16(le_scan_window_adv_monitor); > + HDEV_PARAM_U16(le_scan_int_connect); > + HDEV_PARAM_U16(le_scan_window_connect); > + HDEV_PARAM_U16(le_conn_min_interval); > + HDEV_PARAM_U16(le_conn_max_interval); > + HDEV_PARAM_U16(le_conn_latency); > + HDEV_PARAM_U16(le_supv_timeout); > + HDEV_PARAM_U16(def_le_autoconnect_timeout); > + HDEV_PARAM_U16(advmon_allowlist_duration); > + HDEV_PARAM_U16(advmon_no_filter_duration); > + } __packed rp = { > + TLV_SET_U16(0x0000, def_page_scan_type), > + TLV_SET_U16(0x0001, def_page_scan_int), > + TLV_SET_U16(0x0002, def_page_scan_window), > + TLV_SET_U16(0x0003, def_inq_scan_type), > + TLV_SET_U16(0x0004, def_inq_scan_int), > + TLV_SET_U16(0x0005, def_inq_scan_window), > + TLV_SET_U16(0x0006, def_br_lsto), > + TLV_SET_U16(0x0007, def_page_timeout), > + TLV_SET_U16(0x0008, sniff_min_interval), > + TLV_SET_U16(0x0009, sniff_max_interval), > + TLV_SET_U16(0x000a, le_adv_min_interval), > + TLV_SET_U16(0x000b, le_adv_max_interval), > + TLV_SET_U16(0x000c, def_multi_adv_rotation_duration), > + TLV_SET_U16(0x000d, le_scan_interval), > + TLV_SET_U16(0x000e, le_scan_window), > + TLV_SET_U16(0x000f, le_scan_int_suspend), > + TLV_SET_U16(0x0010, le_scan_window_suspend), > + TLV_SET_U16(0x0011, le_scan_int_discovery), > + TLV_SET_U16(0x0012, le_scan_window_discovery), > + TLV_SET_U16(0x0013, le_scan_int_adv_monitor), > + TLV_SET_U16(0x0014, le_scan_window_adv_monitor), > + TLV_SET_U16(0x0015, le_scan_int_connect), > + TLV_SET_U16(0x0016, le_scan_window_connect), > + TLV_SET_U16(0x0017, le_conn_min_interval), > + TLV_SET_U16(0x0018, le_conn_max_interval), > + TLV_SET_U16(0x0019, le_conn_latency), > + TLV_SET_U16(0x001a, le_supv_timeout), > + TLV_SET_U16_JIFFIES_TO_MSECS(0x001b, > + def_le_autoconnect_timeout), > + TLV_SET_U16(0x001d, advmon_allowlist_duration), > + TLV_SET_U16(0x001e, advmon_no_filter_duration), > }; > - struct mgmt_rp_read_def_system_config *rp = (void *)params; > > bt_dev_dbg(hdev, "sock %p", sk); > > - return mgmt_cmd_complete(sk, hdev->id, > - MGMT_OP_READ_DEF_SYSTEM_CONFIG, > - 0, rp, sizeof(params)); > + ret = mgmt_cmd_complete(sk, hdev->id, > + MGMT_OP_READ_DEF_SYSTEM_CONFIG, > + 0, &rp, sizeof(rp)); > + return ret; > } > frankly I would prefer if we do the re-factoring first and only then add new parameters. While I am looking at this, I am also really confused about this JIFFIES_TO_MSEC business. We should actually not store anything in jiffies or use it in an API. Is there a good reason to keep storing things in jiffies internally? Regards Marcel