diff mbox series

[BlueZ,v2,2/3] hog-lib: Add force parameter to bt_hog_detach

Message ID 20240520181439.1407634-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit db383a5b4a8d5ce5ae26c33abeff0dfd56860d21
Headers show
Series [BlueZ,v2,1/3] device: Add btd_device_get_icon | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz May 20, 2024, 6:14 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds force parameter to bt_hog_detach which indicates if the
bt_uhid_destroy shall be called.
---
 android/hidhost.c        | 2 +-
 profiles/input/hog-lib.c | 9 ++++++---
 profiles/input/hog-lib.h | 2 +-
 profiles/input/hog.c     | 2 +-
 4 files changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/android/hidhost.c b/android/hidhost.c
index b4e5c527fafc..e0e3ecf92676 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -796,7 +796,7 @@  static void hog_conn_cb(const bdaddr_t *addr, int err, void *attrib)
 		if (dev->hog) {
 			bt_hid_notify_state(dev,
 						HAL_HIDHOST_STATE_DISCONNECTED);
-			bt_hog_detach(dev->hog);
+			bt_hog_detach(dev->hog, true);
 			return;
 		}
 		goto fail;
diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c
index 2d8d0f359e57..964acc716041 100644
--- a/profiles/input/hog-lib.c
+++ b/profiles/input/hog-lib.c
@@ -1232,7 +1232,7 @@  static void hog_free(void *data)
 {
 	struct bt_hog *hog = data;
 
-	bt_hog_detach(hog);
+	bt_hog_detach(hog, true);
 	uhid_destroy(hog);
 
 	queue_destroy(hog->bas, (void *) bt_bas_unref);
@@ -1747,7 +1747,7 @@  bool bt_hog_attach(struct bt_hog *hog, void *gatt)
 	return true;
 }
 
-void bt_hog_detach(struct bt_hog *hog)
+void bt_hog_detach(struct bt_hog *hog, bool force)
 {
 	GSList *l;
 
@@ -1759,7 +1759,7 @@  void bt_hog_detach(struct bt_hog *hog)
 	for (l = hog->instances; l; l = l->next) {
 		struct bt_hog *instance = l->data;
 
-		bt_hog_detach(instance);
+		bt_hog_detach(instance, force);
 	}
 
 	for (l = hog->reports; l; l = l->next) {
@@ -1780,6 +1780,9 @@  void bt_hog_detach(struct bt_hog *hog)
 	queue_remove_all(hog->gatt_op, cancel_gatt_req, hog, destroy_gatt_req);
 	g_attrib_unref(hog->attrib);
 	hog->attrib = NULL;
+
+	if (force)
+		uhid_destroy(hog);
 }
 
 int bt_hog_set_control_point(struct bt_hog *hog, bool suspend)
diff --git a/profiles/input/hog-lib.h b/profiles/input/hog-lib.h
index a79648976e79..abca829bee92 100644
--- a/profiles/input/hog-lib.h
+++ b/profiles/input/hog-lib.h
@@ -22,7 +22,7 @@  struct bt_hog *bt_hog_ref(struct bt_hog *hog);
 void bt_hog_unref(struct bt_hog *hog);
 
 bool bt_hog_attach(struct bt_hog *hog, void *gatt);
-void bt_hog_detach(struct bt_hog *hog);
+void bt_hog_detach(struct bt_hog *hog, bool force);
 
 int bt_hog_set_control_point(struct bt_hog *hog, bool suspend);
 int bt_hog_send_report(struct bt_hog *hog, void *data, size_t size, int type);
diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index d50b823213b5..2db52d1a2fcb 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -206,7 +206,7 @@  static int hog_disconnect(struct btd_service *service)
 {
 	struct hog_device *dev = btd_service_get_user_data(service);
 
-	bt_hog_detach(dev->hog);
+	bt_hog_detach(dev->hog, false);
 
 	btd_service_disconnecting_complete(service, 0);