|
|
19062e |
From ea793cb9f744cd2942b66385118161b880de958a Mon Sep 17 00:00:00 2001
|
|
|
19062e |
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
|
|
|
19062e |
Date: Tue, 19 Jun 2012 12:44:43 +0300
|
|
|
19062e |
Subject: [PATCH] input: Fix not adding watches when io channel is connected
|
|
|
19062e |
|
|
|
19062e |
This can leave dangling pointers in case one of the channel is never
|
|
|
19062e |
connected which cause -EALREADY to be returned by
|
|
|
19062e |
input_device_set_channel next time the device attempts to connect.
|
|
|
19062e |
|
|
|
19062e |
For the same reason the code path when acting as client now add the
|
|
|
19062e |
watch as soon as the connection completes instead when both channels
|
|
|
19062e |
are connected.
|
|
|
19062e |
---
|
|
|
19062e |
input/device.c | 31 ++++++++++++++++++++++++-------
|
|
|
19062e |
1 file changed, 24 insertions(+), 7 deletions(-)
|
|
|
19062e |
|
|
|
19062e |
diff --git a/input/device.c b/input/device.c
|
|
|
19062e |
index 0e3f4a9..09a9a39 100644
|
|
|
19062e |
--- a/input/device.c
|
|
|
19062e |
+++ b/input/device.c
|
|
|
19062e |
@@ -387,6 +387,11 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
|
|
|
19062e |
struct input_conn *iconn = data;
|
|
|
19062e |
struct input_device *idev = iconn->idev;
|
|
|
19062e |
gboolean connected = FALSE;
|
|
|
19062e |
+ char address[18];
|
|
|
19062e |
+
|
|
|
19062e |
+ ba2str(&iconn->idev->dst, address);
|
|
|
19062e |
+
|
|
|
19062e |
+ DBG("Device %s disconnected", address);
|
|
|
19062e |
|
|
|
19062e |
/* Checking for ctrl_watch avoids a double g_io_channel_shutdown since
|
|
|
19062e |
* it's likely that ctrl_watch_cb has been queued for dispatching in
|
|
|
19062e |
@@ -415,6 +420,11 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
|
|
|
19062e |
static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
|
|
|
19062e |
{
|
|
|
19062e |
struct input_conn *iconn = data;
|
|
|
19062e |
+ char address[18];
|
|
|
19062e |
+
|
|
|
19062e |
+ ba2str(&iconn->idev->dst, address);
|
|
|
19062e |
+
|
|
|
19062e |
+ DBG("Device %s disconnected", address);
|
|
|
19062e |
|
|
|
19062e |
/* Checking for intr_watch avoids a double g_io_channel_shutdown since
|
|
|
19062e |
* it's likely that intr_watch_cb has been queued for dispatching in
|
|
|
19062e |
@@ -811,13 +821,6 @@ static int input_device_connected(struct input_device *idev,
|
|
|
19062e |
if (err < 0)
|
|
|
19062e |
return err;
|
|
|
19062e |
|
|
|
19062e |
- iconn->intr_watch = g_io_add_watch(iconn->intr_io,
|
|
|
19062e |
- G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
|
|
19062e |
- intr_watch_cb, iconn);
|
|
|
19062e |
- iconn->ctrl_watch = g_io_add_watch(iconn->ctrl_io,
|
|
|
19062e |
- G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
|
|
19062e |
- ctrl_watch_cb, iconn);
|
|
|
19062e |
-
|
|
|
19062e |
connected = TRUE;
|
|
|
19062e |
emit_property_changed(idev->conn, idev->path, INPUT_DEVICE_INTERFACE,
|
|
|
19062e |
"Connected", DBUS_TYPE_BOOLEAN, &connected);
|
|
|
19062e |
@@ -854,6 +857,10 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
|
|
|
19062e |
dbus_message_unref(iconn->pending_connect);
|
|
|
19062e |
iconn->pending_connect = NULL;
|
|
|
19062e |
|
|
|
19062e |
+ iconn->intr_watch = g_io_add_watch(iconn->intr_io,
|
|
|
19062e |
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
|
|
19062e |
+ intr_watch_cb, iconn);
|
|
|
19062e |
+
|
|
|
19062e |
return;
|
|
|
19062e |
|
|
|
19062e |
failed:
|
|
|
19062e |
@@ -913,6 +920,10 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
|
|
|
19062e |
|
|
|
19062e |
iconn->intr_io = io;
|
|
|
19062e |
|
|
|
19062e |
+ iconn->ctrl_watch = g_io_add_watch(iconn->ctrl_io,
|
|
|
19062e |
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
|
|
19062e |
+ ctrl_watch_cb, iconn);
|
|
|
19062e |
+
|
|
|
19062e |
return;
|
|
|
19062e |
|
|
|
19062e |
failed:
|
|
|
19062e |
@@ -1272,11 +1283,17 @@ int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm,
|
|
|
19062e |
if (iconn->ctrl_io)
|
|
|
19062e |
return -EALREADY;
|
|
|
19062e |
iconn->ctrl_io = g_io_channel_ref(io);
|
|
|
19062e |
+ iconn->ctrl_watch = g_io_add_watch(iconn->ctrl_io,
|
|
|
19062e |
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
|
|
19062e |
+ ctrl_watch_cb, iconn);
|
|
|
19062e |
break;
|
|
|
19062e |
case L2CAP_PSM_HIDP_INTR:
|
|
|
19062e |
if (iconn->intr_io)
|
|
|
19062e |
return -EALREADY;
|
|
|
19062e |
iconn->intr_io = g_io_channel_ref(io);
|
|
|
19062e |
+ iconn->intr_watch = g_io_add_watch(iconn->intr_io,
|
|
|
19062e |
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
|
|
19062e |
+ intr_watch_cb, iconn);
|
|
|
19062e |
break;
|
|
|
19062e |
}
|
|
|
19062e |
|
|
|
19062e |
--
|
|
|
19062e |
1.8.0.1
|
|
|
19062e |
|