All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times
@ 2024-08-13 14:29 Luiz Augusto von Dentz
  2024-08-13 14:29 ` [PATCH BlueZ v3 2/2] shared/uhid: Fix not cleanup input queue on destroy Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2024-08-13 14:29 UTC (permalink / raw)
  To: linux-bluetooth

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

UHID_START callback shall only be registered once otherwise there is a
risk of processing input queue multiple times.
---
 src/shared/uhid.c | 13 ++++++++++---
 unit/test-uhid.c  |  4 +++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/shared/uhid.c b/src/shared/uhid.c
index 1eddc6122990..4f149fdb8c4d 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;
 };
@@ -246,7 +247,7 @@ unsigned int bt_uhid_register(struct bt_uhid *uhid, uint32_t event,
 		return 0;
 
 	notify = new0(struct uhid_notify, 1);
-	notify->id = uhid->notify_id++;
+	notify->id = ++uhid->notify_id ? uhid->notify_id : ++uhid->notify_id;
 	notify->event = event;
 	notify->func = func;
 	notify->user_data = user_data;
@@ -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;
diff --git a/unit/test-uhid.c b/unit/test-uhid.c
index b0592d3657a8..573da318d480 100644
--- a/unit/test-uhid.c
+++ b/unit/test-uhid.c
@@ -233,8 +233,10 @@ static void test_client(gconstpointer data)
 
 	err = bt_uhid_create(context->uhid, "", NULL, NULL, 0, 0, 0, 0,
 				BT_UHID_NONE, NULL, 0);
-	if (err < 0)
+	if (err < 0) {
+		tester_debug("create failed: %s\n", strerror(-err));
 		tester_test_failed();
+	}
 
 	if (g_str_equal(context->data->test_name, "/uhid/command/destroy")) {
 		err = bt_uhid_destroy(context->uhid, true);
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ v3 2/2] shared/uhid: Fix not cleanup input queue on destroy
  2024-08-13 14:29 [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times Luiz Augusto von Dentz
@ 2024-08-13 14:29 ` Luiz Augusto von Dentz
  2024-08-13 15:50 ` [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times patchwork-bot+bluetooth
  2024-08-13 16:31 ` [BlueZ,v3,1/2] " bluez.test.bot
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2024-08-13 14:29 UTC (permalink / raw)
  To: linux-bluetooth

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

The input queue shall be cleanup on bt_uhid_destroy since that shall not
be carried to the next session even if the input node is not destroyed.
---
 src/shared/uhid.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/shared/uhid.c b/src/shared/uhid.c
index 4f149fdb8c4d..98d6198c7d0a 100644
--- a/src/shared/uhid.c
+++ b/src/shared/uhid.c
@@ -504,6 +504,10 @@ int bt_uhid_destroy(struct bt_uhid *uhid, bool force)
 	if (!uhid)
 		return -EINVAL;
 
+	/* Cleanup input queue */
+	queue_destroy(uhid->input, free);
+	uhid->input = NULL;
+
 	/* Force destroy for non-keyboard devices - keyboards are not destroyed
 	 * on disconnect since they can glitch on reconnection losing
 	 * keypresses.
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times
  2024-08-13 14:29 [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times Luiz Augusto von Dentz
  2024-08-13 14:29 ` [PATCH BlueZ v3 2/2] shared/uhid: Fix not cleanup input queue on destroy Luiz Augusto von Dentz
@ 2024-08-13 15:50 ` patchwork-bot+bluetooth
  2024-08-13 16:31 ` [BlueZ,v3,1/2] " bluez.test.bot
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2024-08-13 15:50 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue, 13 Aug 2024 10:29:34 -0400 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> UHID_START callback shall only be registered once otherwise there is a
> risk of processing input queue multiple times.
> ---
>  src/shared/uhid.c | 13 ++++++++++---
>  unit/test-uhid.c  |  4 +++-
>  2 files changed, 13 insertions(+), 4 deletions(-)

Here is the summary with links:
  - [BlueZ,v3,1/2] shared/uhid: Fix registering UHID_START multiple times
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ee39d01fb9ee
  - [BlueZ,v3,2/2] shared/uhid: Fix not cleanup input queue on destroy
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a13638e6ae38

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [BlueZ,v3,1/2] shared/uhid: Fix registering UHID_START multiple times
  2024-08-13 14:29 [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times Luiz Augusto von Dentz
  2024-08-13 14:29 ` [PATCH BlueZ v3 2/2] shared/uhid: Fix not cleanup input queue on destroy Luiz Augusto von Dentz
  2024-08-13 15:50 ` [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times patchwork-bot+bluetooth
@ 2024-08-13 16:31 ` bluez.test.bot
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2024-08-13 16:31 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 949 bytes --]

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

---Test result---

Test Summary:
CheckPatch                    PASS      0.76 seconds
GitLint                       PASS      0.53 seconds
BuildEll                      PASS      25.31 seconds
BluezMake                     PASS      1715.75 seconds
MakeCheck                     PASS      13.54 seconds
MakeDistcheck                 PASS      183.50 seconds
CheckValgrind                 PASS      258.93 seconds
CheckSmatch                   PASS      361.11 seconds
bluezmakeextell               PASS      122.10 seconds
IncrementalBuild              PASS      3027.76 seconds
ScanBuild                     PASS      1047.24 seconds



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-13 16:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 14:29 [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times Luiz Augusto von Dentz
2024-08-13 14:29 ` [PATCH BlueZ v3 2/2] shared/uhid: Fix not cleanup input queue on destroy Luiz Augusto von Dentz
2024-08-13 15:50 ` [PATCH BlueZ v3 1/2] shared/uhid: Fix registering UHID_START multiple times patchwork-bot+bluetooth
2024-08-13 16:31 ` [BlueZ,v3,1/2] " bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.