All of lore.kernel.org
 help / color / mirror / Atom feed
From: "João Paulo Rechi Vita" <jprvita@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
Subject: [PATCH BlueZ 13/13] hog: Fix destroying the uhid device when disconnecting
Date: Tue, 10 Jul 2012 16:17:05 -0300	[thread overview]
Message-ID: <1341947825-14789-14-git-send-email-jprvita@openbossa.org> (raw)
In-Reply-To: <1341947825-14789-1-git-send-email-jprvita@openbossa.org>

From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>

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


  parent reply	other threads:[~2012-07-10 19:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-10 19:16 [PATCH BlueZ 00/13] Rebased remaining HoG patches João Paulo Rechi Vita
2012-07-10 19:16 ` [PATCH BlueZ 01/13] hog: HID I/O driver João Paulo Rechi Vita
2012-07-10 21:24   ` [PATCH BlueZ] " João Paulo Rechi Vita
2012-07-10 21:26     ` Joao Paulo Rechi Vita
2012-07-10 21:50     ` Johan Hedberg
2012-07-10 19:16 ` [PATCH BlueZ 02/13] hog: Use real values for vendor and product IDs João Paulo Rechi Vita
2012-07-10 19:16 ` [PATCH BlueZ 03/13] hog: Add read Report Reference descriptor João Paulo Rechi Vita
2012-07-10 19:16 ` [PATCH BlueZ 04/13] hog: Prepend Report ID to the HID report João Paulo Rechi Vita
2012-07-10 19:16 ` [PATCH BlueZ 05/13] hog: Add support for uHID events João Paulo Rechi Vita
2012-07-10 19:16 ` [PATCH BlueZ 06/13] hog: Handle output reports João Paulo Rechi Vita
2012-07-10 19:16 ` [PATCH BlueZ 07/13] hog: Handle output events João Paulo Rechi Vita
2012-07-10 19:17 ` [PATCH BlueZ 08/13] hog: Handle feature reports João Paulo Rechi Vita
2012-07-10 19:17 ` [PATCH BlueZ 09/13] hog: Add HID Information Characteristic read João Paulo Rechi Vita
2012-07-10 19:17 ` [PATCH BlueZ 10/13] hog: Use hardware country code João Paulo Rechi Vita
2012-07-10 19:17 ` [PATCH BlueZ 11/13] hog: Handle HID devices operating in Boot Protocol Mode João Paulo Rechi Vita
2012-07-10 19:17 ` [PATCH BlueZ 12/13] hog: Fix re-discovering HoG characteristics when reconnecting João Paulo Rechi Vita
2012-07-10 19:17 ` João Paulo Rechi Vita [this message]
2012-07-13 14:02 ` [PATCH BlueZ 00/13] Rebased remaining HoG patches Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1341947825-14789-14-git-send-email-jprvita@openbossa.org \
    --to=jprvita@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=vinicius.gomes@openbossa.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.