diff mbox series

Bluetooth: hci_core: Fix missing instances using HCI_MAX_AD_LENGTH

Message ID 20230818212211.3207580-1-luiz.dentz@gmail.com
State Superseded
Headers show
Series Bluetooth: hci_core: Fix missing instances using HCI_MAX_AD_LENGTH | expand

Commit Message

Luiz Augusto von Dentz Aug. 18, 2023, 9:22 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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 | 6 +++---
 net/bluetooth/eir.c              | 2 +-
 net/bluetooth/mgmt.c             | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

Comments

kernel test robot Aug. 21, 2023, 1:03 p.m. UTC | #1
Hi Luiz,

kernel test robot noticed the following build errors:

[auto build test ERROR on linux-next/master]
[also build test ERROR on linus/master v6.5-rc7]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-hci_core-Fix-missing-instances-using-HCI_MAX_AD_LENGTH/20230821-102220
base:   linux-next/master
patch link:    https://lore.kernel.org/r/20230818212211.3207580-1-luiz.dentz%40gmail.com
patch subject: [PATCH] Bluetooth: hci_core: Fix missing instances using HCI_MAX_AD_LENGTH
config: i386-buildonly-randconfig-002-20230821 (https://download.01.org/0day-ci/archive/20230821/202308212004.EXsdDWkd-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce: (https://download.01.org/0day-ci/archive/20230821/202308212004.EXsdDWkd-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308212004.EXsdDWkd-lkp@intel.com/

All errors (new ones prefixed by >>):

>> net/bluetooth/eir.c:36:19: error: use of undeclared identifier 'dev'; did you mean 'hdev'?
           if ((max_adv_len(dev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
                            ^~~
                            hdev
   include/net/bluetooth/hci_core.h:1854:19: note: expanded from macro 'max_adv_len'
           (ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
                            ^
   include/net/bluetooth/hci_core.h:1850:33: note: expanded from macro 'ext_adv_capable'
   #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
                                   ^
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^
   include/linux/compiler.h:57:52: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                      ^
   net/bluetooth/eir.c:30:42: note: 'hdev' declared here
   u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
                                            ^
>> net/bluetooth/eir.c:36:19: error: use of undeclared identifier 'dev'; did you mean 'hdev'?
           if ((max_adv_len(dev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
                            ^~~
                            hdev
   include/net/bluetooth/hci_core.h:1854:19: note: expanded from macro 'max_adv_len'
           (ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
                            ^
   include/net/bluetooth/hci_core.h:1850:33: note: expanded from macro 'ext_adv_capable'
   #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
                                   ^
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^
   include/linux/compiler.h:57:61: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                               ^
   net/bluetooth/eir.c:30:42: note: 'hdev' declared here
   u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
                                            ^
>> net/bluetooth/eir.c:36:19: error: use of undeclared identifier 'dev'; did you mean 'hdev'?
           if ((max_adv_len(dev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
                            ^~~
                            hdev
   include/net/bluetooth/hci_core.h:1854:19: note: expanded from macro 'max_adv_len'
           (ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
                            ^
   include/net/bluetooth/hci_core.h:1850:33: note: expanded from macro 'ext_adv_capable'
   #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
                                   ^
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^
   include/linux/compiler.h:57:86: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                                        ^
   include/linux/compiler.h:68:3: note: expanded from macro '__trace_if_value'
           (cond) ?                                        \
            ^
   net/bluetooth/eir.c:30:42: note: 'hdev' declared here
   u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
                                            ^
   3 errors generated.


vim +36 net/bluetooth/eir.c

    29	
    30	u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
    31	{
    32		size_t short_len;
    33		size_t complete_len;
    34	
    35		/* no space left for name (+ NULL + type + len) */
  > 36		if ((max_adv_len(dev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
    37			return ad_len;
    38	
    39		/* use complete name if present and fits */
    40		complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
    41		if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH)
    42			return eir_append_name(ptr, ad_len, EIR_NAME_COMPLETE,
    43					       hdev->dev_name, complete_len + 1);
    44	
    45		/* use short name if present */
    46		short_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
    47		if (short_len)
    48			return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
    49					       hdev->short_name,
    50					       short_len == HCI_MAX_SHORT_NAME_LENGTH ?
    51					       short_len : short_len + 1);
    52	
    53		/* use shortened full name if present, we already know that name
    54		 * is longer then HCI_MAX_SHORT_NAME_LENGTH
    55		 */
    56		if (complete_len)
    57			return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
    58					       hdev->dev_name,
    59					       HCI_MAX_SHORT_NAME_LENGTH);
    60	
    61		return ad_len;
    62	}
    63
diff mbox series

Patch

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 6fb055e3c595..6e2988b11f99 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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;
diff --git a/net/bluetooth/eir.c b/net/bluetooth/eir.c
index 8a85f6cdfbc1..0f66097b0693 100644
--- a/net/bluetooth/eir.c
+++ b/net/bluetooth/eir.c
@@ -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(dev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
 		return ad_len;
 
 	/* use complete name if present and fits */
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d6c9b7bc8592..ba2e00646e8e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -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);