summaryrefslogtreecommitdiff
path: root/src/linux/hidpp-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/linux/hidpp-device.c')
-rw-r--r--src/linux/hidpp-device.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c
index 03c7112..d714b46 100644
--- a/src/linux/hidpp-device.c
+++ b/src/linux/hidpp-device.c
@@ -394,6 +394,16 @@ hidpp_device_read_resp (HidppDevice *device,
/* read from the device */
begin_time = g_get_monotonic_time () / 1000;
for (;;) {
+ /* avoid infinite loop when there is no response */
+ remaining_time = HIDPP_DEVICE_READ_RESPONSE_TIMEOUT -
+ (g_get_monotonic_time () / 1000 - begin_time);
+ if (remaining_time <= 0) {
+ g_set_error (error, 1, 0,
+ "timeout while reading response");
+ ret = FALSE;
+ goto out;
+ }
+
r = g_poll (poll, G_N_ELEMENTS(poll), remaining_time);
if (r < 0) {
if (errno == EINTR)
@@ -453,16 +463,6 @@ hidpp_device_read_resp (HidppDevice *device,
goto out;
}
- /* avoid infinite loop when there is no response */
- remaining_time = HIDPP_DEVICE_READ_RESPONSE_TIMEOUT -
- (g_get_monotonic_time () / 1000 - begin_time);
- if (remaining_time <= 0) {
- g_set_error (error, 1, 0,
- "timeout while reading response");
- ret = FALSE;
- goto out;
- }
-
/* not our message, ignore it and try again */
}