All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez PATCH v2 1/2] plugins/admin: add adapter_remove handler
@ 2021-09-06  6:03 Howard Chung
  2021-09-06  6:03 ` [Bluez PATCH v2 2/2] plugins/admin: create admin_policy_settings if not exists Howard Chung
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Howard Chung @ 2021-09-06  6:03 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz; +Cc: Yun-Hao Chung, Shyh-In Hwang, Miao-chen Chou

From: Yun-Hao Chung <howardchung@chromium.org>

Currently admin doesn't handle adapter removed callbacks, which causes
interfaces AdminPolicySet1 and AdminPolicyStatus1 not being
unregistered, which in turns causes these interfaces can not be
re-registered once adapter is back.

This adds handler for adapter_remove.

Reviewed-by: Shyh-In Hwang <josephsih@chromium.org>
Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
---
tested with following steps
1. rmmod btusb
2. modprobe btusb
3. read allowlist via bluetoothctl

Changes in v2:
1. Fix make errors

 plugins/admin.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/plugins/admin.c b/plugins/admin.c
index 02fec04568ba..82c00cabdb6b 100644
--- a/plugins/admin.c
+++ b/plugins/admin.c
@@ -85,6 +85,17 @@ static void admin_policy_free(void *data)
 	g_free(admin_policy);
 }
 
+static void admin_policy_destroy(struct btd_admin_policy *admin_policy)
+{
+	const char *path = adapter_get_path(admin_policy->adapter);
+
+	g_dbus_unregister_interface(dbus_conn, path,
+						ADMIN_POLICY_SET_INTERFACE);
+	g_dbus_unregister_interface(dbus_conn, path,
+						ADMIN_POLICY_STATUS_INTERFACE);
+	admin_policy_free(admin_policy);
+}
+
 static bool uuid_match(const void *data, const void *match_data)
 {
 	const bt_uuid_t *uuid = data;
@@ -492,7 +503,7 @@ static int admin_policy_adapter_probe(struct btd_adapter *adapter)
 	if (!g_dbus_register_interface(dbus_conn, adapter_path,
 					ADMIN_POLICY_SET_INTERFACE,
 					admin_policy_adapter_methods, NULL,
-					NULL, policy_data, admin_policy_free)) {
+					NULL, policy_data, NULL)) {
 		btd_error(policy_data->adapter_id,
 			"Admin Policy Set interface init failed on path %s",
 								adapter_path);
@@ -506,7 +517,7 @@ static int admin_policy_adapter_probe(struct btd_adapter *adapter)
 					ADMIN_POLICY_STATUS_INTERFACE,
 					NULL, NULL,
 					admin_policy_adapter_properties,
-					policy_data, admin_policy_free)) {
+					policy_data, NULL)) {
 		btd_error(policy_data->adapter_id,
 			"Admin Policy Status interface init failed on path %s",
 								adapter_path);
@@ -574,10 +585,24 @@ static void admin_policy_device_removed(struct btd_adapter *adapter,
 		unregister_device_data(data, NULL);
 }
 
+static void admin_policy_remove(struct btd_adapter *adapter)
+{
+	DBG("");
+
+	queue_foreach(devices, unregister_device_data, NULL);
+	queue_destroy(devices, g_free);
+
+	if (policy_data) {
+		admin_policy_destroy(policy_data);
+		policy_data = NULL;
+	}
+}
+
 static struct btd_adapter_driver admin_policy_driver = {
 	.name	= "admin_policy",
 	.probe	= admin_policy_adapter_probe,
 	.resume = NULL,
+	.remove = admin_policy_remove,
 	.device_resolved = admin_policy_device_added,
 	.device_removed = admin_policy_device_removed
 };
@@ -597,11 +622,7 @@ static void admin_exit(void)
 	DBG("");
 
 	btd_unregister_adapter_driver(&admin_policy_driver);
-	queue_foreach(devices, unregister_device_data, NULL);
-	queue_destroy(devices, g_free);
-
-	if (policy_data)
-		admin_policy_free(policy_data);
+	admin_policy_remove(NULL);
 }
 
 BLUETOOTH_PLUGIN_DEFINE(admin, VERSION,
-- 
2.33.0.153.gba50c8fa24-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-17  3:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  6:03 [Bluez PATCH v2 1/2] plugins/admin: add adapter_remove handler Howard Chung
2021-09-06  6:03 ` [Bluez PATCH v2 2/2] plugins/admin: create admin_policy_settings if not exists Howard Chung
2021-09-06  6:40 ` [Bluez,v2,1/2] plugins/admin: add adapter_remove handler bluez.test.bot
2021-09-15 12:32 ` [Bluez PATCH v2 1/2] " Yun-hao Chung
2021-09-15 23:40   ` Luiz Augusto von Dentz
2021-09-16 23:50     ` Luiz Augusto von Dentz
2021-09-17  3:43       ` Yun-hao Chung

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.