mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-05 05:18:00 +02:00
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>
This commit is contained in:
parent
5058ede399
commit
789dbb037c
1 changed files with 10 additions and 10 deletions
|
|
@ -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 */
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue