input/device: Notify failure if ctrl disconnect when waiting intr
authorArchie Pusaka <apusaka@chromium.org>
Wed, 18 May 2022 04:33:07 +0000 (12:33 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
On some rare occasions, the peer HID device might disconnect the ctrl
channel when we are trying to connect the intr channel. If this
happens, interrupt_connect_cb() will not be called by btio, and we
will be stuck in "connecting" state. Any future connection attempt to
the peer device will fail because of "busy".

This patch prevents that by checking if we need to report connection
failure when the ctrl channel is disconnected.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/input/device.c

index 979a560..8dc01a4 100644 (file)
@@ -588,6 +588,13 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
        if (idev->intr_io && !(cond & G_IO_NVAL))
                g_io_channel_shutdown(idev->intr_io, TRUE, NULL);
 
+       /* It's possible this is triggered while the intr channel is not even
+        * connected yet, therefore we are still in the connecting state.
+        */
+       if (btd_service_get_state(idev->service) ==
+                                               BTD_SERVICE_STATE_CONNECTING)
+               btd_service_connecting_complete(idev->service, -EIO);
+
        if (!idev->intr_io && idev->virtual_cable_unplug)
                virtual_cable_unplug(idev);