[PATCH BlueZ v1 1/2] shared/uhid: Fix registering UHID_START multiple times

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

UHID_START callback shall only be registered once otherwise there is a
risk of processing input queue multiple times.
---
 src/shared/uhid.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/shared/uhid.c b/src/shared/uhid.c
index 1eddc6122990..b0a436d7862b 100644
--- a/src/shared/uhid.c
+++ b/src/shared/uhid.c
@@ -46,6 +46,7 @@ struct bt_uhid {
 	struct queue *input;
 	uint8_t type;
 	bool created;
+	unsigned int start_id;
 	bool started;
 	struct uhid_replay *replay;
 };
@@ -351,6 +352,14 @@ int bt_uhid_create(struct bt_uhid *uhid, const char *name, bdaddr_t *src,
 	if (uhid->created)
 		return 0;
 
+	/* Register callback for UHID_START if not registered yet */
+	if (!uhid->start_id) {
+		uhid->start_id = bt_uhid_register(uhid, UHID_START, uhid_start,
+									uhid);
+		if (!uhid->start_id)
+			return -ENOMEM;
+	}
+
 	memset(&ev, 0, sizeof(ev));
 	ev.type = UHID_CREATE2;
 	strncpy((char *) ev.u.create2.name, name,
@@ -378,8 +387,6 @@ int bt_uhid_create(struct bt_uhid *uhid, const char *name, bdaddr_t *src,
 	if (err)
 		return err;
 
-	bt_uhid_register(uhid, UHID_START, uhid_start, uhid);
-
 	uhid->created = true;
 	uhid->started = false;
 	uhid->type = type;
-- 
2.46.0





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux