Skip to contentSkip to conversation

Bluetooth: HCI: Fix definition of hci_rp_read_stored_link_key

PATCH In review Luiz Augusto von Dentz 3 participants 5 messages Nov 25, 2021 – Nov 27, 2021

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/2 Bluetooth: HCI: Fix definition of hci_rp_read_stored_link_key

From: Luiz Augusto von Dentz <[email protected]>

Both max_num_keys and num_key are 2 octects:

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1985:

Max_Num_Keys:
Size: 2 octets
Range: 0x0000 to 0xFFFF

Num_Keys_Read:
Size: 2 octets
Range: 0x0000 to 0xFFFF

---
v2: Use __le16 instead of __u16 in hci_rp_read_stored_link_key and update fields in hci_dev to properly store 2 octects. Also add a patch for hci_rp_delete_stored_link_key since num_keys is also 2 octecs like hci_rp_read_stored_link_key.

 include/net/bluetooth/hci.h      | 4 ++--
 include/net/bluetooth/hci_core.h | 4 ++--
 net/bluetooth/hci_event.c        | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +2 -2
index 84db6b275231..3c5211c3a790 100644
@@ -1047,8 +1047,8 @@ struct hci_cp_read_stored_link_key {
 } __packed;
 struct hci_rp_read_stored_link_key {
 	__u8     status;
-	__u8     max_keys;
-	__u8     num_keys;
+	__le16    max_keys;
+	__le16    num_keys;
 } __packed;
 
 #define HCI_OP_DELETE_STORED_LINK_KEY	0x0c12
include/net/bluetooth/hci_core.h +2 -2
index 2560cfe80db8..bb07a6d0d597 100644
@@ -352,8 +352,8 @@ struct hci_dev {
 	__u16		lmp_subver;
 	__u16		voice_setting;
 	__u8		num_iac;
-	__u8		stored_max_keys;
-	__u8		stored_num_keys;
+	__u16		stored_max_keys;
+	__u16		stored_num_keys;
 	__u8		io_capability;
 	__s8		inq_tx_power;
 	__u8		err_data_reporting;
net/bluetooth/hci_event.c +2 -2
index efc5458b1345..7452de6895fc 100644
@@ -256,8 +256,8 @@ static void hci_cc_read_stored_link_key(struct hci_dev *hdev,
 		return;
 
 	if (!rp->status && sent->read_all == 0x01) {
-		hdev->stored_max_keys = rp->max_keys;
-		hdev->stored_num_keys = rp->num_keys;
+		hdev->stored_max_keys = le16_to_cpu(rp->max_keys);
+		hdev->stored_num_keys = le16_to_cpu(rp->num_keys);
 	}
 }
 
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH v2 2/2 Bluetooth: HCI: Fix definition of hci_rp_delete_stored_link_key

From: Luiz Augusto von Dentz <[email protected]>

num_keys is actually 2 octects not 1:

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1989:

Num_Keys_Deleted:
Size: 2 octets
0xXXXX Number of Link Keys Deleted

---
 include/net/bluetooth/hci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/bluetooth/hci.h +1 -1
index 3c5211c3a790..b557d86396d5 100644
@@ -1058,7 +1058,7 @@ struct hci_cp_delete_stored_link_key {
 } __packed;
 struct hci_rp_delete_stored_link_key {
 	__u8     status;
-	__u8     num_keys;
+	__le16   num_keys;
 } __packed;
 
 #define HCI_MAX_NAME_LENGTH		248
Signature · 1 line
2.33.1
maintainer
#2 lore raw

Re: [PATCH v2 2/2] Bluetooth: HCI: Fix definition of hci_rp_delete_stored_link_key

Hi Luiz,

Quoted 5 lines

num_keys is actually 2 octects not 1:

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1989:

Quoted 8 lines

Num_Keys_Deleted:
Size: 2 octets
0xXXXX Number of Link Keys Deleted

---
include/net/bluetooth/hci.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree. However I also had to fix the user of this struct.

Regards

Marcel

#3 lore raw

Re: [PATCH v2 2/2] Bluetooth: HCI: Fix definition of hci_rp_delete_stored_link_key

In reply to Luiz Augusto von Dentz
I love your patch! Perhaps something to improve:

Hi Luiz,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on v5.16-rc2]
[cannot apply to next-20211126]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-HCI-Fix-definition-of-hci_rp_read_stored_link_key/20211125-081632
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: i386-randconfig-s001-20211126 (https://download.01.org/0day-ci/archive/20211127/202111271449.QQM12YkZ-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/0day-ci/linux/commit/eed7490f0a05bc41f1f2e58b20663dc0870a38ba
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Luiz-Augusto-von-Dentz/Bluetooth-HCI-Fix-definition-of-hci_rp_read_stored_link_key/20211125-081632
        git checkout eed7490f0a05bc41f1f2e58b20663dc0870a38ba
        # save the config file to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash net/bluetooth/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> net/bluetooth/hci_event.c:274:15: sparse: sparse: restricted __le16 degrades to integer
>> net/bluetooth/hci_event.c:275:39: sparse: sparse: invalid assignment: -=
>> net/bluetooth/hci_event.c:275:39: sparse:    left side has type unsigned short
>> net/bluetooth/hci_event.c:275:39: sparse:    right side has type restricted __le16

vim +274 net/bluetooth/hci_event.c

c2f0f979276fc49 Marcel Holtmann 2015-01-12  263  
a93661203641eb5 Marcel Holtmann 2015-01-12  264  static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
a93661203641eb5 Marcel Holtmann 2015-01-12  265  					  struct sk_buff *skb)
a93661203641eb5 Marcel Holtmann 2015-01-12  266  {
a93661203641eb5 Marcel Holtmann 2015-01-12  267  	struct hci_rp_delete_stored_link_key *rp = (void *)skb->data;
a93661203641eb5 Marcel Holtmann 2015-01-12  268  
a93661203641eb5 Marcel Holtmann 2015-01-12  269  	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
a93661203641eb5 Marcel Holtmann 2015-01-12  270  
a93661203641eb5 Marcel Holtmann 2015-01-12  271  	if (rp->status)
a93661203641eb5 Marcel Holtmann 2015-01-12  272  		return;
a93661203641eb5 Marcel Holtmann 2015-01-12  273  
a93661203641eb5 Marcel Holtmann 2015-01-12 @274  	if (rp->num_keys <= hdev->stored_num_keys)
a93661203641eb5 Marcel Holtmann 2015-01-12 @275  		hdev->stored_num_keys -= rp->num_keys;
a93661203641eb5 Marcel Holtmann 2015-01-12  276  	else
a93661203641eb5 Marcel Holtmann 2015-01-12  277  		hdev->stored_num_keys = 0;
a93661203641eb5 Marcel Holtmann 2015-01-12  278  }

a93661203641eb5 Marcel Holtmann 2015-01-12 279

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#4 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 20 lines

Both max_num_keys and num_key are 2 octects:

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1985:

Max_Num_Keys:
Size: 2 octets
Range: 0x0000 to 0xFFFF

Num_Keys_Read:
Size: 2 octets
Range: 0x0000 to 0xFFFF

---
v2: Use __le16 instead of __u16 in hci_rp_read_stored_link_key and update fields in hci_dev to properly store 2 octects. Also add a patch for hci_rp_delete_stored_link_key since num_keys is also 2 octecs like hci_rp_read_stored_link_key.

Quoted 4 lines
include/net/bluetooth/hci.h      | 4 ++--
include/net/bluetooth/hci_core.h | 4 ++--
net/bluetooth/hci_event.c        | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)

patch has been applied to bluetooth-next tree. However I had to fix some alignment issue.

Regards

Marcel