From: Sonny Sasaka Date: Fri, 21 Aug 2020 04:35:36 +0000 (-0700) Subject: input/device: Unregister all UHID event listeners at UHID_DESTROY X-Git-Tag: submit/tizen/20210606.232858~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8bfb40020c3cd6b3e2110e4839b753d79e9441e;p=platform%2Fupstream%2Fbluez.git input/device: Unregister all UHID event listeners at UHID_DESTROY When destroying UHID, we should also unregister all event listeners so that they don't get double registered at reconnection. It fixes a bug where battery report is not available to kernel after reconnection and also prevents memory leak. Tested with Logitech M535 mouse: * Connect mouse to the device running BlueZ * cat /sys/class/power_supply/hid-{addr}-battery/capacity # works * Disconnect mouse * Reconnect mouse * cat /sys/class/power_supply/hid-{addr}-battery/capacity # still works Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- diff --git a/profiles/input/device.c b/profiles/input/device.c index 4740fd93..14f092fc 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -989,6 +989,8 @@ static int uhid_disconnect(struct input_device *idev) if (!idev->uhid_created) return 0; + bt_uhid_unregister_all(idev->uhid); + memset(&ev, 0, sizeof(ev)); ev.type = UHID_DESTROY; diff --git a/src/shared/uhid.c b/src/shared/uhid.c index 1c684cd9..576432ce 100755 --- a/src/shared/uhid.c +++ b/src/shared/uhid.c @@ -218,6 +218,15 @@ bool bt_uhid_unregister(struct bt_uhid *uhid, unsigned int id) return true; } +bool bt_uhid_unregister_all(struct bt_uhid *uhid) +{ + if (!uhid) + return false; + + queue_remove_all(uhid->notify_list, NULL, NULL, free); + return true; +} + int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev) { ssize_t len; diff --git a/src/shared/uhid.h b/src/shared/uhid.h index 459a2490..dbdca852 100755 --- a/src/shared/uhid.h +++ b/src/shared/uhid.h @@ -40,5 +40,6 @@ typedef void (*bt_uhid_callback_t)(struct uhid_event *ev, void *user_data); unsigned int bt_uhid_register(struct bt_uhid *uhid, uint32_t event, bt_uhid_callback_t func, void *user_data); bool bt_uhid_unregister(struct bt_uhid *uhid, unsigned int id); +bool bt_uhid_unregister_all(struct bt_uhid *uhid); int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev);