2022-12-17 01:18:34

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ v4 1/2] shared/gatt-db: Add gatt_db_attribute_get_service

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

This adds gatt_db_attribute_get_service which can be used to get the
service which the given attribute belongs to.
---
src/shared/gatt-db.c | 9 +++++++++
src/shared/gatt-db.h | 3 +++
2 files changed, 12 insertions(+)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 9a92090ec493..b696fe33da93 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1712,6 +1712,15 @@ uint16_t gatt_db_attribute_get_handle(const struct gatt_db_attribute *attrib)
return attrib->handle;
}

+struct gatt_db_attribute *
+gatt_db_attribute_get_service(const struct gatt_db_attribute *attrib)
+{
+ if (!attrib)
+ return NULL;
+
+ return attrib->service->attributes[0];
+}
+
bool gatt_db_attribute_get_service_uuid(const struct gatt_db_attribute *attrib,
bt_uuid_t *uuid)
{
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 41464ad3e7e0..163a981df233 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -225,6 +225,9 @@ const bt_uuid_t *gatt_db_attribute_get_type(

uint16_t gatt_db_attribute_get_handle(const struct gatt_db_attribute *attrib);

+struct gatt_db_attribute *
+gatt_db_attribute_get_service(const struct gatt_db_attribute *attrib);
+
bool gatt_db_attribute_get_service_uuid(const struct gatt_db_attribute *attrib,
bt_uuid_t *uuid);

--
2.37.3


2022-12-17 01:19:41

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ v4 2/2] shared/gatt-client: Fix not removing pending services

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

If there are no characteristics to discover, or for some reason
bt_gatt_discover_descriptors is skiped, or the last attribute is
actually a included service the service should be removed from
pending list as there will be no more attributes to be discovered.

Fixes: https://github.com/bluez/bluez/issues/438
---
src/shared/gatt-client.c | 46 +++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index cf0d2e2b749d..cb2e64b6cc6b 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -500,6 +500,24 @@ static void discovery_req_clear(struct bt_gatt_client *client)
client->discovery_req = NULL;
}

+static void discover_remove_pending(struct discovery_op *op,
+ struct gatt_db_attribute *attr)
+{
+ struct gatt_db_attribute *svc;
+
+ svc = gatt_db_attribute_get_service(attr);
+ if (!svc)
+ return;
+
+ if (!queue_remove(op->pending_svcs, svc))
+ return;
+
+ gatt_db_service_set_active(svc, true);
+
+ if (op->cur_svc == svc)
+ op->cur_svc = NULL;
+}
+
static void discover_chrcs_cb(bool success, uint8_t att_ecode,
struct bt_gatt_result *result,
void *user_data);
@@ -576,12 +594,26 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
gatt_db_attribute_get_handle(attr), handle);
goto failed;
}
+
+ if (!gatt_db_attribute_get_service_data(attr, NULL, &end,
+ NULL, NULL)) {
+ DBG(client, "Unable to get service data at 0x%04x",
+ handle);
+ goto failed;
+ }
+
+ /* Skip if there are no attributes */
+ if (handle == end)
+ discover_remove_pending(op, attr);
}

next:
range = queue_pop_head(op->discov_ranges);
- if (!range)
+ if (!range) {
+ /* Skip if there are no attributes */
+ discover_remove_pending(op, op->cur_svc);
goto failed;
+ }

client->discovery_req = bt_gatt_discover_characteristics(client->att,
range->start,
@@ -725,6 +757,9 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
goto failed;
}

+ /* Done with the current service */
+ discover_remove_pending(op, op->cur_svc);
+
done:
free(chrc_data);
return true;
@@ -798,9 +833,6 @@ static void ext_prop_read_cb(bool success, uint8_t att_ecode,
if (discovering)
return;

- /* Done with the current service */
- gatt_db_service_set_active(op->cur_svc, true);
-
goto done;

failed:
@@ -888,9 +920,6 @@ next:
if (discovering)
return;

- /* Done with the current service */
- gatt_db_service_set_active(op->cur_svc, true);
-
goto done;

failed:
@@ -997,9 +1026,6 @@ next:
if (discovering)
return;

- /* Done with the current service */
- gatt_db_service_set_active(op->cur_svc, true);
-
goto done;

failed:
--
2.37.3

2022-12-17 03:22:07

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ,v4,1/2] shared/gatt-db: Add gatt_db_attribute_get_service

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=705299

---Test result---

Test Summary:
CheckPatch PASS 1.17 seconds
GitLint PASS 0.52 seconds
BuildEll PASS 26.63 seconds
BluezMake PASS 740.12 seconds
MakeCheck PASS 10.93 seconds
MakeDistcheck PASS 145.54 seconds
CheckValgrind PASS 237.68 seconds
bluezmakeextell PASS 93.02 seconds
IncrementalBuild PASS 1204.05 seconds
ScanBuild WARNING 930.96 seconds

Details
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
src/shared/gatt-client.c:387:21: warning: Use of memory after it is freed
gatt_db_unregister(op->client->db, op->db_id);
^~~~~~~~~~
src/shared/gatt-client.c:632:2: warning: Use of memory after it is freed
discovery_op_complete(op, false, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:929:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1035:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1227:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1292:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1563:6: warning: Use of memory after it is freed
if (read_db_hash(op)) {
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1568:2: warning: Use of memory after it is freed
discover_all(op);
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2070:6: warning: Use of memory after it is freed
if (read_db_hash(op)) {
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2078:8: warning: Use of memory after it is freed
discovery_op_ref(op),
^~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3161:2: warning: Use of memory after it is freed
complete_write_long_op(req, success, 0, false);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3183:2: warning: Use of memory after it is freed
request_unref(req);
^~~~~~~~~~~~~~~~~~
12 warnings generated.



---
Regards,
Linux Bluetooth

2022-12-19 20:56:36

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH BlueZ v4 1/2] shared/gatt-db: Add gatt_db_attribute_get_service

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Fri, 16 Dec 2022 17:10:58 -0800 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This adds gatt_db_attribute_get_service which can be used to get the
> service which the given attribute belongs to.
> ---
> src/shared/gatt-db.c | 9 +++++++++
> src/shared/gatt-db.h | 3 +++
> 2 files changed, 12 insertions(+)

Here is the summary with links:
- [BlueZ,v4,1/2] shared/gatt-db: Add gatt_db_attribute_get_service
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b91d9213d951
- [BlueZ,v4,2/2] shared/gatt-client: Fix not removing pending services
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=da203f5dbc7e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html