Bluetooth: hci_core: Fix missing instances using HCI_MAX_AD_LENGTH
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 18 Aug 2023 21:19:27 +0000 (14:19 -0700)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 24 Aug 2023 19:22:05 +0000 (12:22 -0700)
There a few instances still using HCI_MAX_AD_LENGTH instead of using
max_adv_len which takes care of detecting what is the actual maximum
length depending on if the controller supports EA or not.

Fixes: 112b5090c219 ("Bluetooth: MGMT: Fix always using HCI_MAX_AD_LENGTH")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
include/net/bluetooth/hci_core.h
net/bluetooth/eir.c
net/bluetooth/mgmt.c

index 6fb055e..6e2988b 100644 (file)
@@ -83,7 +83,7 @@ struct discovery_state {
        u8                      last_adv_addr_type;
        s8                      last_adv_rssi;
        u32                     last_adv_flags;
-       u8                      last_adv_data[HCI_MAX_AD_LENGTH];
+       u8                      last_adv_data[HCI_MAX_EXT_AD_LENGTH];
        u8                      last_adv_data_len;
        bool                    report_invalid_rssi;
        bool                    result_filtering;
@@ -290,7 +290,7 @@ struct adv_pattern {
        __u8 ad_type;
        __u8 offset;
        __u8 length;
-       __u8 value[HCI_MAX_AD_LENGTH];
+       __u8 value[HCI_MAX_EXT_AD_LENGTH];
 };
 
 struct adv_rssi_thresholds {
@@ -726,7 +726,7 @@ struct hci_conn {
        __u16           le_conn_interval;
        __u16           le_conn_latency;
        __u16           le_supv_timeout;
-       __u8            le_adv_data[HCI_MAX_AD_LENGTH];
+       __u8            le_adv_data[HCI_MAX_EXT_AD_LENGTH];
        __u8            le_adv_data_len;
        __u8            le_per_adv_data[HCI_MAX_PER_AD_LENGTH];
        __u8            le_per_adv_data_len;
index 8a85f6c..9214189 100644 (file)
@@ -33,7 +33,7 @@ u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
        size_t complete_len;
 
        /* no space left for name (+ NULL + type + len) */
-       if ((HCI_MAX_AD_LENGTH - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
+       if ((max_adv_len(hdev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
                return ad_len;
 
        /* use complete name if present and fits */
index d6c9b7b..ba2e006 100644 (file)
@@ -5381,9 +5381,9 @@ static u8 parse_adv_monitor_pattern(struct adv_monitor *m, u8 pattern_count,
        for (i = 0; i < pattern_count; i++) {
                offset = patterns[i].offset;
                length = patterns[i].length;
-               if (offset >= HCI_MAX_AD_LENGTH ||
-                   length > HCI_MAX_AD_LENGTH ||
-                   (offset + length) > HCI_MAX_AD_LENGTH)
+               if (offset >= HCI_MAX_EXT_AD_LENGTH ||
+                   length > HCI_MAX_EXT_AD_LENGTH ||
+                   (offset + length) > HCI_MAX_EXT_AD_LENGTH)
                        return MGMT_STATUS_INVALID_PARAMS;
 
                p = kmalloc(sizeof(*p), GFP_KERNEL);