Skip to content

Commit 7c28afd

Browse files
bentissJiri Kosina
authored andcommitted
HID: hidpp: terminate retry loop on success
It seems we forgot the normal case to terminate the retry loop, making us asking 3 times each command, which is probably a little bit too much. And remove the ugly "goto exit" that can be replaced by a simpler "break" Fixes: 586e8fe ("HID: logitech-hidpp: Retry commands when device is busy") Suggested-by: Mark Lord <[email protected]> Tested-by: Mark Lord <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 6199d23 commit 7c28afd

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/hid/hid-logitech-hidpp.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
286286
struct hidpp_report *message,
287287
struct hidpp_report *response)
288288
{
289-
int ret;
289+
int ret = -1;
290290
int max_retries = 3;
291291

292292
mutex_lock(&hidpp->send_mutex);
@@ -300,28 +300,28 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
300300
*/
301301
*response = *message;
302302

303-
for (; max_retries != 0; max_retries--) {
303+
for (; max_retries != 0 && ret; max_retries--) {
304304
ret = __hidpp_send_report(hidpp->hid_dev, message);
305305

306306
if (ret) {
307307
dbg_hid("__hidpp_send_report returned err: %d\n", ret);
308308
memset(response, 0, sizeof(struct hidpp_report));
309-
goto exit;
309+
break;
310310
}
311311

312312
if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
313313
5*HZ)) {
314314
dbg_hid("%s:timeout waiting for response\n", __func__);
315315
memset(response, 0, sizeof(struct hidpp_report));
316316
ret = -ETIMEDOUT;
317-
goto exit;
317+
break;
318318
}
319319

320320
if (response->report_id == REPORT_ID_HIDPP_SHORT &&
321321
response->rap.sub_id == HIDPP_ERROR) {
322322
ret = response->rap.params[1];
323323
dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
324-
goto exit;
324+
break;
325325
}
326326

327327
if ((response->report_id == REPORT_ID_HIDPP_LONG ||
@@ -330,13 +330,12 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
330330
ret = response->fap.params[1];
331331
if (ret != HIDPP20_ERROR_BUSY) {
332332
dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
333-
goto exit;
333+
break;
334334
}
335335
dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret);
336336
}
337337
}
338338

339-
exit:
340339
mutex_unlock(&hidpp->send_mutex);
341340
return ret;
342341

0 commit comments

Comments
 (0)