Skip to contentSkip to conversation

hog-lib: Fix calling bt_uhid_destroy with invalid instance

PATCH Applied Luiz Augusto von Dentz 3 participants 4 messages Aug 19, 2024 – Aug 20, 2024 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 hog-lib: Fix calling bt_uhid_destroy with invalid instance

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

If the hog->uhid cannot be created then it is pointless to call bt_uhid_destroy as it will likely just produce bogus output as in:

https://github.com/bluez/bluez/issues/529#issuecomment-2297350805

---
 profiles/input/hog-lib.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
profiles/input/hog-lib.c +5 -3
index 1b4aca07486b..729603702e5f 100644
@@ -830,14 +830,16 @@ static void uhid_destroy(struct bt_hog *hog, bool force)
 {
 	int err;
 
+	if (!hog->uhid)
+		return;
+
+	bt_uhid_unregister_all(hog->uhid);
+
 	err = bt_uhid_destroy(hog->uhid, force);
 	if (err < 0) {
 		error("bt_uhid_destroy: %s", strerror(-err));
 		return;
 	}
-
-	if (bt_uhid_created(hog->uhid))
-		bt_uhid_unregister_all(hog->uhid);
 }
 
 static void set_report(struct uhid_event *ev, void *user_data)
Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH 2/2 hog-lib: Add logging when bt_uhid_new fails

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

If bt_uhid_new fails there is likely a problem with uHID module or bluetoothd don't have previleges to access /dev/uhid.

---
 profiles/input/hog-lib.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
profiles/input/hog-lib.c +13 -7
index 729603702e5f..22599f71a394 100644
@@ -1421,23 +1421,29 @@ static struct bt_hog *hog_new(int fd, const char *name, uint16_t vendor,
 					uint8_t type,
 					struct gatt_db_attribute *attr)
 {
+	struct bt_uhid *uhid;
 	struct bt_hog *hog;
 
+	if (fd < 0)
+		uhid = bt_uhid_new_default();
+	else
+		uhid = bt_uhid_new(fd);
+
+	if (!uhid) {
+		DBG("Unable to create UHID");
+		return NULL;
+	}
+
 	hog = g_try_new0(struct bt_hog, 1);
 	if (!hog)
 		return NULL;
 
 	hog->gatt_op = queue_new();
 	hog->bas = queue_new();
-
-	if (fd < 0)
-		hog->uhid = bt_uhid_new_default();
-	else
-		hog->uhid = bt_uhid_new(fd);
-
 	hog->uhid_fd = fd;
+	hog->uhid = uhid;
 
-	if (!hog->gatt_op || !hog->bas || !hog->uhid) {
+	if (!hog->gatt_op || !hog->bas) {
 		hog_free(hog);
 		return NULL;
 	}
Signature · 1 line
2.46.0
#2 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=881045

---Test result---

Test Summary:

CheckPatch                    PASS      0.92 seconds
GitLint                       PASS      0.66 seconds
BuildEll                      PASS      25.28 seconds
BluezMake                     PASS      1828.05 seconds
MakeCheck                     FAIL      14.00 seconds
MakeDistcheck                 FAIL      168.85 seconds
CheckValgrind                 FAIL      265.27 seconds
CheckSmatch                   PASS      375.40 seconds
bluezmakeextell               PASS      127.67 seconds
IncrementalBuild              PASS      3199.30 seconds
ScanBuild                     PENDING   1127.18 seconds

Details
##############################
Test: MakeCheck - FAIL
Desc: Run Bluez Make Check
Output:

make[3]: *** [Makefile:11764: test-suite.log] Error 1 make[2]: *** [Makefile:11872: check-TESTS] Error 2 make[1]: *** [Makefile:12301: check-am] Error 2
make: *** [Makefile:12303: check] Error 2
##############################
Test: MakeDistcheck - FAIL
Desc: Run Bluez Make Distcheck
Output:

Package cups was not found in the pkg-config search path. Perhaps you should add the directory containing `cups.pc' to the PKG_CONFIG_PATH environment variable
No package 'cups' found
make[4]: *** [Makefile:11764: test-suite.log] Error 1 make[3]: *** [Makefile:11872: check-TESTS] Error 2 make[2]: *** [Makefile:12301: check-am] Error 2 make[1]: *** [Makefile:12303: check] Error 2
make: *** [Makefile:12224: distcheck] Error 1
##############################
Test: CheckValgrind - FAIL
Desc: Run Bluez Make Check with Valgrind
Output:

tools/mgmt-tester.c: In function ‘main’:
tools/mgmt-tester.c:12725:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without 12725 | int main(int argc, char *argv[])

      |     ^~~~

make[3]: *** [Makefile:11764: test-suite.log] Error 1 make[2]: *** [Makefile:11872: check-TESTS] Error 2 make[1]: *** [Makefile:12301: check-am] Error 2
make: *** [Makefile:12303: check] Error 2
##############################
Test: ScanBuild - PENDING
Desc: Run Scan Build
Output:

---
Regards,
Linux Bluetooth

#3 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 8 lines · On Mon, 19 Aug 2024 16:53:03 -0400 you wrote:

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

If the hog->uhid cannot be created then it is pointless to call bt_uhid_destroy as it will likely just produce bogus output as in:

https://github.com/bluez/bluez/issues/529#issuecomment-2297350805

[...]

Here is the summary with links:
- [BlueZ,v1,1/2] hog-lib: Fix calling bt_uhid_destroy with invalid instance

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=1cc3cf08c493
  - [BlueZ,v1,2/2] hog-lib: Add logging when bt_uhid_new fails
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d5c68dbed1ee

You are awesome, thank you!

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