Skip to contentSkip to conversation

hog-lib: Don't destroy UHID device on detach

PATCH Applied Luiz Augusto von Dentz 3 participants 5 messages Feb 14, 2024 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v5 1/3 hog-lib: Don't destroy UHID device on detach

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

This makes bt_hog_detach not to destroy UHID device which means the device node don't need to be recreated in case of reconnections which speeds up the process.

---
 profiles/input/hog-lib.c | 48 ++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
profiles/input/hog-lib.c +24 -24
index 7ff1ede3db35..67492a63eca3 100644
@@ -1309,11 +1309,35 @@ static bool cancel_gatt_req(const void *data, const void *user_data)
 	return g_attrib_cancel(hog->attrib, req->id);
 }
 
+static void uhid_destroy(struct bt_hog *hog)
+{
+	int err;
+	struct uhid_event ev;
+
+	if (!hog->uhid_created)
+		return;
+
+	bt_uhid_unregister_all(hog->uhid);
+
+	memset(&ev, 0, sizeof(ev));
+	ev.type = UHID_DESTROY;
+
+	err = bt_uhid_send(hog->uhid, &ev);
+
+	if (err < 0) {
+		error("bt_uhid_send: %s", strerror(-err));
+		return;
+	}
+
+	hog->uhid_created = false;
+}
+
 static void hog_free(void *data)
 {
 	struct bt_hog *hog = data;
 
 	bt_hog_detach(hog);
+	uhid_destroy(hog);
 
 	queue_destroy(hog->input, free);
 	queue_destroy(hog->bas, (void *) bt_bas_unref);
@@ -1823,29 +1847,6 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)
 	return true;
 }
 
-static void uhid_destroy(struct bt_hog *hog)
-{
-	int err;
-	struct uhid_event ev;
-
-	if (!hog->uhid_created)
-		return;
-
-	bt_uhid_unregister_all(hog->uhid);
-
-	memset(&ev, 0, sizeof(ev));
-	ev.type = UHID_DESTROY;
-
-	err = bt_uhid_send(hog->uhid, &ev);
-
-	if (err < 0) {
-		error("bt_uhid_send: %s", strerror(-err));
-		return;
-	}
-
-	hog->uhid_created = false;
-}
-
 void bt_hog_detach(struct bt_hog *hog)
 {
 	GSList *l;
@@ -1879,7 +1880,6 @@ 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;
-	uhid_destroy(hog);
 }
 
 int bt_hog_set_control_point(struct bt_hog *hog, bool suspend)
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v5 2/3 input.conf: Make UserspaceHID defaults to true

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

This makes UserspaceHID defaults to true so the plugin has more control over the input device lifetime.

---
 profiles/input/device.c   | 2 +-
 profiles/input/input.conf | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
profiles/input/device.c +1 -1
index 6c64ff1c1c52..ff7e3482d0eb 100644
@@ -81,7 +81,7 @@ struct input_device {
 };
 
 static int idle_timeout = 0;
-static bool uhid_enabled = false;
+static bool uhid_enabled = true;
 static bool classic_bonded_only = true;
 
 void input_set_idle_timeout(int timeout)
profiles/input/input.conf +1 -1
index d8645f3dd664..00a34eb63de1 100644
@@ -9,7 +9,7 @@
 #IdleTimeout=30
 
 # Enable HID protocol handling in userspace input profile
-# Defaults to false (HIDP handled in HIDP kernel module)
+# Defaults to true (Use UHID instead of kernel HIDP)
 #UserspaceHID=true
 
 # Limit HID connections to bonded devices
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v5 3/3 input/device: Don't destroy UHID device on disconnect

In reply to Luiz Augusto von Dentz

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

This makes classic HID behave like HoG which keeps the UHID device around while disconnected so it doesn't have to be recreated on every reconnection.

---
 profiles/input/device.c | 4 ++++
 1 file changed, 4 insertions(+)
profiles/input/device.c +4 -0
index ff7e3482d0eb..0d32b705bd00 100644
@@ -985,6 +985,10 @@ static int uhid_disconnect(struct input_device *idev)
 	if (!idev->uhid_created)
 		return 0;
 
+	/* Only destroy the node if virtual cable unplug flag has been set */
+	if (!idev->virtual_cable_unplug)
+		return 0;
+
 	bt_uhid_unregister_all(idev->uhid);
 
 	memset(&ev, 0, sizeof(ev));
Signature · 1 line
2.43.0
#3 lore raw
In reply to Luiz Augusto von Dentz

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

---Test result---

Test Summary:

CheckPatch                    PASS      1.29 seconds
GitLint                       PASS      0.90 seconds
BuildEll                      PASS      24.20 seconds
BluezMake                     PASS      716.57 seconds
MakeCheck                     PASS      11.67 seconds
MakeDistcheck                 PASS      164.95 seconds
CheckValgrind                 PASS      228.39 seconds
CheckSmatch                   PASS      331.35 seconds
bluezmakeextell               PASS      108.34 seconds
IncrementalBuild              PASS      2053.08 seconds
ScanBuild                     PASS      960.58 seconds

---
Regards,
Linux Bluetooth

#4 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

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

Quoted 9 lines · On Wed, 14 Feb 2024 13:57:16 -0500 you wrote:

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

This makes bt_hog_detach not to destroy UHID device which means the device node don't need to be recreated in case of reconnections which speeds up the process.

[...]

Here is the summary with links:
- [BlueZ,v5,1/3] hog-lib: Don't destroy UHID device on detach

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=247ae8524888
  - [BlueZ,v5,2/3] input.conf: Make UserspaceHID defaults to true
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9698870015b0
  - [BlueZ,v5,3/3] input/device: Don't destroy UHID device on disconnect
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ee880bee8586

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html