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 <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
if (!idev->uhid_created)
return 0;
+ bt_uhid_unregister_all(idev->uhid);
+
memset(&ev, 0, sizeof(ev));
ev.type = UHID_DESTROY;
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;
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);