Diff between 51cae76d75a03bf6a812328d5d760065661c07f0 and 8e73a002848a6a2abcbd436ea8aac089320c13f2

Changed Files

File Additions Deletions Status
profiles/input/hog.c +18 -12 modified

Full Patch

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index bd35830..e006add 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -844,6 +844,18 @@ static void char_discovered_cb(uint8_t status, GSList *chars, void *user_data)
 									hogdev);
 }
 
+static void report_free(void *data)
+{
+	struct report *report = data;
+	struct hog_device *hogdev = report->hogdev;
+
+	if (hogdev->attrib)
+		g_attrib_unregister(hogdev->attrib, report->notifyid);
+
+	g_free(report->decl);
+	g_free(report);
+}
+
 static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 {
 	struct hog_device *hogdev = user_data;
@@ -852,6 +864,12 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 
 	DBG("HoG connected");
 
+	if (!hogdev->uhid_created && hogdev->reports) {
+		DBG("HoG init failed previously, preparing for re-init");
+		g_slist_free_full(hogdev->reports, report_free);
+		hogdev->reports = NULL;
+	}
+
 	hogdev->attrib = g_attrib_ref(attrib);
 
 	if (hogdev->reports == NULL) {
@@ -901,18 +919,6 @@ static struct hog_device *hog_new_device(struct btd_device *device,
 	return hogdev;
 }
 
-static void report_free(void *data)
-{
-	struct report *report = data;
-	struct hog_device *hogdev = report->hogdev;
-
-	if (hogdev->attrib)
-		g_attrib_unregister(hogdev->attrib, report->notifyid);
-
-	g_free(report->decl);
-	g_free(report);
-}
-
 static void hog_free_device(struct hog_device *hogdev)
 {
 	btd_device_unref(hogdev->device);