[PATCH BlueZ 13/13] hog: Fix destroying the uhid device when disconnecting

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

 



From: Vinicius Costa Gomes <vinicius.gomes@xxxxxxxxxxxxx>

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 7f4cf2d..10bc622 100644
--- a/profiles/input/hog_device.c
+++ b/profiles/input/hog_device.c
@@ -550,12 +550,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;
@@ -675,6 +669,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)
@@ -687,6 +682,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;
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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