From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2] gatt: Fix not cleaning up device state properly
Date: Mon, 1 Oct 2018 14:53:25 +0300 [thread overview]
Message-ID: <20181001115325.17082-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If the device is removed locally device_free would end up calling
bt_att_unref which won't trigger any disconnect callback necessary
to remove device states.
---
v2: Fix glib warning if att is already disconnected.
src/device.c | 3 +++
src/gatt-database.c | 29 +++++++++++++++++++++++++++++
src/gatt-database.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/src/device.c b/src/device.c
index ef5b8f86a..5ddfb9266 100644
--- a/src/device.c
+++ b/src/device.c
@@ -580,6 +580,9 @@ static void gatt_server_cleanup(struct btd_device *device)
bt_gatt_server_unref(device->server);
device->server = NULL;
+
+ btd_gatt_database_att_disconnected(
+ btd_adapter_get_database(device->adapter), device->att);
}
static void attio_cleanup(struct btd_device *device)
diff --git a/src/gatt-database.c b/src/gatt-database.c
index abcf7b759..911c674d3 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -357,6 +357,11 @@ static bool get_dst_info(struct bt_att *att, bdaddr_t *dst, uint8_t *dst_type)
{
GIOChannel *io = NULL;
GError *gerr = NULL;
+ int fd;
+
+ fd = bt_att_get_fd(att);
+ if (fd < 0)
+ return false;
io = g_io_channel_unix_new(bt_att_get_fd(att));
if (!io)
@@ -3349,6 +3354,30 @@ void btd_gatt_database_att_connected(struct btd_gatt_database *database,
state->pending = NULL;
}
+void btd_gatt_database_att_disconnected(struct btd_gatt_database *database,
+ struct bt_att *att)
+{
+ struct device_state *state;
+ bdaddr_t bdaddr;
+ uint8_t bdaddr_type;
+
+ DBG("");
+
+ if (!get_dst_info(att, &bdaddr, &bdaddr_type))
+ return;
+
+ state = find_device_state(database, &bdaddr, bdaddr_type);
+ if (!state)
+ return;
+
+ if (state->disc_id) {
+ bt_att_unregister_disconnect(att, state->disc_id);
+ state->disc_id = 0;
+ }
+
+ att_disconnected(0, state);
+}
+
static void restore_ccc(struct btd_gatt_database *database,
const bdaddr_t *addr, uint8_t addr_type, uint16_t value)
{
diff --git a/src/gatt-database.h b/src/gatt-database.h
index a6c3139c4..9e7cda8c2 100644
--- a/src/gatt-database.h
+++ b/src/gatt-database.h
@@ -25,5 +25,7 @@ void btd_gatt_database_destroy(struct btd_gatt_database *database);
struct gatt_db *btd_gatt_database_get_db(struct btd_gatt_database *database);
void btd_gatt_database_att_connected(struct btd_gatt_database *database,
struct bt_att *att);
+void btd_gatt_database_att_disconnected(struct btd_gatt_database *database,
+ struct bt_att *att);
void btd_gatt_database_restore_svc_chng_ccc(struct btd_gatt_database *database);
--
2.17.1
reply other threads:[~2018-10-01 11:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181001115325.17082-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).