summaryrefslogtreecommitdiff
path: root/src/linux/hidpp-device.c
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-08-28 18:21:45 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-09-02 11:45:34 +0200
commit9bc63112c7c5caa9a86e4e5a09f56eff4286d8e3 (patch)
tree272c6cd6f4ea115ed3b69773185ccba05aa4d4a3 /src/linux/hidpp-device.c
parentc511b7356460bf8818e0dcd85ed15cc7f765b701 (diff)
downloadupower-9bc63112c7c5caa9a86e4e5a09f56eff4286d8e3.tar.gz
hidpp: move timeout checking before reading
When no report matches the report type or device, the previous code did not terminate the loop early enough because the check was missed. Now the timeout is always checked before attempting to poll. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
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 */
}