diff mbox series

[BlueZ,v1,2/2] hog-lib: Add logging when bt_uhid_new fails

Message ID 20240819205304.60594-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit d5c68dbed1eeffd62f55030bdc383c7a684daf69
Headers show
Series [BlueZ,v1,1/2] hog-lib: Fix calling bt_uhid_destroy with invalid instance | 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 Aug. 19, 2024, 8:53 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(-)
diff mbox series

Patch

diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c
index 729603702e5f..22599f71a394 100644
--- a/profiles/input/hog-lib.c
+++ b/profiles/input/hog-lib.c
@@ -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;
 	}