Skip to contentSkip to conversation

shared/gatt-client: Fix not marking service as active

PATCH Superseded Luiz Augusto von Dentz 2 participants 2 messages Dec 16, 2022 Bluetooth drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/1 shared/gatt-client: Fix not marking service as active

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 marked as active as there will be no more attributes to be discovered.

---
 src/shared/gatt-client.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
src/shared/gatt-client.c +20 -1
index cf0d2e2b749d..83283110b636 100644
@@ -576,12 +576,28 @@ 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)
+			gatt_db_service_set_active(attr, true);
 	}
 
 next:
 	range = queue_pop_head(op->discov_ranges);
-	if (!range)
+	if (!range) {
+		/* If there are no range to discover mark current service as
+		 * active.
+		 */
+		gatt_db_service_set_active(op->cur_svc, true);
 		goto failed;
+	}
 
 	client->discovery_req = bt_gatt_discover_characteristics(client->att,
 							range->start,
@@ -725,6 +741,9 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
 		goto failed;
 	}
 
+	/* Done with the current service */
+	gatt_db_service_set_active(op->cur_svc, true);
+
 done:
 	free(chrc_data);
 	return true;
Signature · 1 line
2.37.3
#1 lore raw

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

---Test result---

Test Summary:

CheckPatch                    PASS      0.40 seconds
GitLint                       PASS      0.26 seconds
BuildEll                      PASS      26.35 seconds
BluezMake                     PASS      766.01 seconds
MakeCheck                     PASS      11.24 seconds
MakeDistcheck                 PASS      147.97 seconds
CheckValgrind                 PASS      239.23 seconds
bluezmakeextell               PASS      93.67 seconds
IncrementalBuild              PASS      615.21 seconds
ScanBuild                     WARNING   949.04 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:616:2: warning: Use of memory after it is freed
        discovery_op_complete(op, false, att_ecode);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:919:2: warning: Use of memory after it is freed
        discovery_op_complete(op, success, att_ecode);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1028:2: warning: Use of memory after it is freed
        discovery_op_complete(op, success, att_ecode);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1220:2: warning: Use of memory after it is freed
        discovery_op_complete(op, success, att_ecode);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1285:2: warning: Use of memory after it is freed
        discovery_op_complete(op, success, att_ecode);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1556:6: warning: Use of memory after it is freed
        if (read_db_hash(op)) {
            ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1561:2: warning: Use of memory after it is freed
        discover_all(op);
        ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2063:6: warning: Use of memory after it is freed
        if (read_db_hash(op)) {
            ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2071:8: warning: Use of memory after it is freed
                                                        discovery_op_ref(op),
                                                        ^~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3154:2: warning: Use of memory after it is freed
        complete_write_long_op(req, success, 0, false);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3176:2: warning: Use of memory after it is freed
        request_unref(req);
        ^~~~~~~~~~~~~~~~~~

12 warnings generated.

---
Regards,
Linux Bluetooth