From 2ddde5a701b51d830ff232d6c24195a67f88b9d0 Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Tue, 10 Jul 2012 16:17:05 -0300 Subject: [PATCH] hog: Fix destroying the uhid device when disconnecting The uhid device should have the lifetime of the hog_device structure. So, only destroy the uhid device when hog_device is destroyed. --- profiles/input/hog_device.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/profiles/input/hog_device.c b/profiles/input/hog_device.c index c7b5bcbfa..ffd71392a 100644 --- a/profiles/input/hog_device.c +++ b/profiles/input/hog_device.c @@ -551,12 +551,6 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data) static void attio_disconnected_cb(gpointer user_data) { struct hog_device *hogdev = user_data; - struct uhid_event ev; - - memset(&ev, 0, sizeof(ev)); - ev.type = UHID_DESTROY; - if (write(hogdev->uhid_fd, &ev, sizeof(ev)) < 0) - error("Failed to destroy uHID device: %s", strerror(errno)); g_attrib_unregister(hogdev->attrib, hogdev->report_cb_id); hogdev->report_cb_id = 0; @@ -677,6 +671,7 @@ int hog_device_register(struct btd_device *device, const char *path) int hog_device_unregister(const char *path) { struct hog_device *hogdev; + struct uhid_event ev; hogdev = find_device_by_path(devices, path); if (hogdev == NULL) @@ -689,6 +684,11 @@ int hog_device_unregister(const char *path) hogdev->uhid_watch_id = 0; } + memset(&ev, 0, sizeof(ev)); + ev.type = UHID_DESTROY; + if (write(hogdev->uhid_fd, &ev, sizeof(ev)) < 0) + error("Failed to destroy uHID device: %s", strerror(errno)); + close(hogdev->uhid_fd); hogdev->uhid_fd = -1; -- 2.47.3