diff mbox series

[BlueZ] shared/gatt-db: Fix gatt_db_attribute_get_index

Message ID 20220401213857.36738-1-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ] shared/gatt-db: Fix gatt_db_attribute_get_index | expand

Commit Message

Luiz Augusto von Dentz April 1, 2022, 9:38 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

gatt_db_attribute_get_index was calculating the index based on
attrib->handle - service->attributes[0]->handle which doesn't work when
there are gaps in between handles.

Fixes: https://github.com/bluez/bluez/issues/326
---
 src/shared/gatt-db.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

bluez.test.bot@gmail.com April 1, 2022, 11:43 p.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=628334

---Test result---

Test Summary:
CheckPatch                    PASS      0.67 seconds
GitLint                       PASS      0.46 seconds
Prep - Setup ELL              PASS      51.25 seconds
Build - Prep                  PASS      0.66 seconds
Build - Configure             PASS      10.18 seconds
Build - Make                  PASS      1848.64 seconds
Make Check                    PASS      13.13 seconds
Make Check w/Valgrind         PASS      543.05 seconds
Make Distcheck                PASS      295.71 seconds
Build w/ext ELL - Configure   PASS      10.95 seconds
Build w/ext ELL - Make        PASS      1838.54 seconds
Incremental Build with patchesPASS      0.00 seconds



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index be07cdbe4..4f5d10b57 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1537,12 +1537,12 @@  static int gatt_db_attribute_get_index(struct gatt_db_attribute *attrib)
 		return -1;
 
 	service = attrib->service;
-	index = attrib->handle - service->attributes[0]->handle;
-
-	if (index > (service->num_handles - 1))
-		return -1;
+	for (index = 0; index < service->num_handles; index++) {
+		if (service->attributes[index] == attrib)
+			return index;
+	}
 
-	return index;
+	return -1;
 }
 
 static struct gatt_db_attribute *