2022-09-17 00:05:54

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ] shared/gatt-client: Make use of gatt_db_attribute_get_ccc

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

This makes use of gatt_db_attribute_get_ccc to locate a CCC of a given
attribute.
---
src/shared/gatt-client.c | 41 ++++++++++------------------------------
1 file changed, 10 insertions(+), 31 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index ba9228ddf3f4..45b6ed92fde1 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -211,22 +211,6 @@ static void notify_data_unref(void *data)
free(notify_data);
}

-static void find_ccc(struct gatt_db_attribute *attr, void *user_data)
-{
- struct gatt_db_attribute **ccc_ptr = user_data;
- bt_uuid_t uuid;
-
- if (*ccc_ptr)
- return;
-
- bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
-
- if (bt_uuid_cmp(&uuid, gatt_db_attribute_get_type(attr)))
- return;
-
- *ccc_ptr = attr;
-}
-
static bool match_notify_chrc(const void *data, const void *user_data)
{
const struct notify_data *notify_data = data;
@@ -273,24 +257,25 @@ static void chrc_removed(struct gatt_db_attribute *attr, void *user_data)
}

static struct notify_chrc *notify_chrc_create(struct bt_gatt_client *client,
- uint16_t value_handle)
+ uint16_t handle)
{
struct gatt_db_attribute *attr, *ccc;
struct notify_chrc *chrc;
- bt_uuid_t uuid;
+ uint16_t value_handle;
uint8_t properties;

- /* Check that chrc_value_handle belongs to a known characteristic */
- attr = gatt_db_get_attribute(client->db, value_handle - 1);
+ /* Check that there is an attribute with handle */
+ attr = gatt_db_get_attribute(client->db, handle);
if (!attr)
return NULL;

- bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
- if (bt_uuid_cmp(&uuid, gatt_db_attribute_get_type(attr)))
+ if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle,
+ &properties, NULL, NULL))
return NULL;

- if (!gatt_db_attribute_get_char_data(attr, NULL, NULL, &properties,
- NULL, NULL))
+ /* Check that there is an attribute with value_handle */
+ attr = gatt_db_get_attribute(client->db, value_handle);
+ if (!attr)
return NULL;

chrc = new0(struct notify_chrc, 1);
@@ -301,13 +286,7 @@ static struct notify_chrc *notify_chrc_create(struct bt_gatt_client *client,
return NULL;
}

- /*
- * Find the CCC characteristic. Some characteristics that allow
- * notifications may not have a CCC descriptor. We treat these as
- * automatically successful.
- */
- ccc = NULL;
- gatt_db_service_foreach_desc(attr, find_ccc, &ccc);
+ ccc = gatt_db_attribute_get_ccc(attr);
if (ccc)
chrc->ccc_handle = gatt_db_attribute_get_handle(ccc);

--
2.37.3


2022-09-17 01:07:57

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ] shared/gatt-client: Make use of gatt_db_attribute_get_ccc

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

---Test result---

Test Summary:
CheckPatch PASS 1.43 seconds
GitLint PASS 1.02 seconds
Prep - Setup ELL PASS 27.08 seconds
Build - Prep PASS 0.94 seconds
Build - Configure PASS 8.81 seconds
Build - Make PASS 984.61 seconds
Make Check PASS 11.55 seconds
Make Check w/Valgrind PASS 292.56 seconds
Make Distcheck PASS 242.54 seconds
Build w/ext ELL - Configure PASS 8.75 seconds
Build w/ext ELL - Make PASS 85.00 seconds
Incremental Build w/ patches PASS 0.00 seconds
Scan Build WARNING 553.94 seconds

Details
##############################
Test: Scan Build - WARNING
Desc: Run Scan Build with patches
Output:
*****************************************************************************
The bugs reported by the scan-build may or may not be caused by your patches.
Please check the list and fix the bugs if they are caused by your patch.
*****************************************************************************
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:600:2: warning: Use of memory after it is freed
discovery_op_complete(op, false, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:900:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1009:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1185:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1250:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1521:6: warning: Use of memory after it is freed
if (read_db_hash(op)) {
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1526:2: warning: Use of memory after it is freed
discover_all(op);
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2028:6: warning: Use of memory after it is freed
if (read_db_hash(op)) {
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2036:8: warning: Use of memory after it is freed
discovery_op_ref(op),
^~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3119:2: warning: Use of memory after it is freed
complete_write_long_op(req, success, 0, false);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3141:2: warning: Use of memory after it is freed
request_unref(req);
^~~~~~~~~~~~~~~~~~
12 warnings generated.




---
Regards,
Linux Bluetooth

2022-09-19 21:41:34

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH BlueZ] shared/gatt-client: Make use of gatt_db_attribute_get_ccc

Hello:

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

On Fri, 16 Sep 2022 16:46:04 -0700 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This makes use of gatt_db_attribute_get_ccc to locate a CCC of a given
> attribute.
> ---
> src/shared/gatt-client.c | 41 ++++++++++------------------------------
> 1 file changed, 10 insertions(+), 31 deletions(-)

Here is the summary with links:
- [BlueZ] shared/gatt-client: Make use of gatt_db_attribute_get_ccc
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f6ac0886f08e

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