From: Dimitris <dimitris.on.linux@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Dimitris <dimitris.on.linux@gmail.com>
Subject: [PATCH BlueZ 1/1] Refactor btd_device_is_connected
Date: Wed, 3 Apr 2024 19:45:21 -0700 [thread overview]
Message-ID: <20240404024521.120349-2-dimitris.on.linux@gmail.com> (raw)
In-Reply-To: <20240404024521.120349-1-dimitris.on.linux@gmail.com>
Splitting the service state test out of btd_device_is_connected
and using the state-specific test from adapter_remove_connection.
This intends to fix a busy loop that happens when BT is disabled
from userspace with e.g. "rfkill block bluetooth".
---
src/adapter.c | 2 +-
src/device.c | 7 ++++++-
src/device.h | 1 +
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 4bcc464de..0b7aab4b5 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -7486,7 +7486,7 @@ static void adapter_remove_connection(struct btd_adapter *adapter,
device_cancel_authentication(device, TRUE);
/* If another bearer is still connected */
- if (btd_device_is_connected(device))
+ if (btd_device_state_is_connected(device))
return;
adapter->connections = g_slist_remove(adapter->connections, device);
diff --git a/src/device.c b/src/device.c
index 5e74633c6..123b1b796 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3273,13 +3273,18 @@ uint8_t btd_device_get_bdaddr_type(struct btd_device *dev)
bool btd_device_is_connected(struct btd_device *dev)
{
- if (dev->bredr_state.connected || dev->le_state.connected)
+ if (btd_device_state_is_connected(dev))
return true;
return find_service_with_state(dev->services,
BTD_SERVICE_STATE_CONNECTED);
}
+bool btd_device_state_is_connected(struct btd_device *dev)
+{
+ return dev->bredr_state.connected || dev->le_state.connected;
+}
+
static void clear_temporary_timer(struct btd_device *dev)
{
if (dev->temporary_timer) {
diff --git a/src/device.h b/src/device.h
index d4e70b7ef..e3191f2a4 100644
--- a/src/device.h
+++ b/src/device.h
@@ -104,6 +104,7 @@ void device_set_rssi(struct btd_device *device, int8_t rssi);
void device_set_tx_power(struct btd_device *device, int8_t tx_power);
void device_set_flags(struct btd_device *device, uint8_t flags);
bool btd_device_is_connected(struct btd_device *dev);
+bool btd_device_state_is_connected(struct btd_device *dev);
uint8_t btd_device_get_bdaddr_type(struct btd_device *dev);
bool device_is_retrying(struct btd_device *device);
void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type,
--
2.44.0
next prev parent reply other threads:[~2024-04-04 2:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 20:52 [PATCH BlueZ 0/1] Fixes busy loop when disabling Dimitris
2024-04-03 20:52 ` [PATCH BlueZ 1/1] Revert "device: Consider service state on device_is_connected" Dimitris
2024-04-03 22:39 ` Fixes busy loop when disabling bluez.test.bot
2024-04-04 6:24 ` [PATCH BlueZ 1/1] Revert "device: Consider service state on device_is_connected" Paul Menzel
2024-04-04 6:35 ` Dimitris
2024-04-04 2:45 ` [PATCH BlueZ 0/1] V2: Fix busy loop when disabling BT Dimitris
2024-04-04 2:45 ` Dimitris [this message]
2024-04-04 4:40 ` bluez.test.bot
2024-04-04 14:59 ` [PATCH BlueZ 1/1] Refactor btd_device_is_connected Luiz Augusto von Dentz
2024-04-04 15:52 ` Dimitris
2024-04-04 16:16 ` Luiz Augusto von Dentz
2024-04-04 18:25 ` Dimitris
2024-04-04 18:30 ` [PATCH BlueZ 0/1] V3: Fix busy loop when disabling BT Dimitris
2024-04-04 18:30 ` [PATCH BlueZ 1/1] refactor bearer connected test Dimitris
2024-04-04 20:07 ` V3: Fix busy loop when disabling BT bluez.test.bot
2024-04-04 18:50 ` [PATCH BlueZ 0/1] " patchwork-bot+bluetooth
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=20240404024521.120349-2-dimitris.on.linux@gmail.com \
--to=dimitris.on.linux@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).