[PATCH 14/18] HID: logitech-hidpp: use guard() for send_mutex
From: Dmitry Torokhov
Date: Mon Nov 09 2026 - 01:12:58 EST
Manual mutex_lock() and mutex_unlock() calls force early loop exits to
break to a shared unlock path instead of returning directly. Convert
hidpp_send_message_sync() to use guard(mutex) so lock release is bound
to the function scope and busy-retry exits can return immediately.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 3a3baeb9fbb9..bf13e5fbe142 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -361,24 +361,22 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp,
int ret;
int max_retries = 3;
- mutex_lock(&hidpp->send_mutex);
+ guard(mutex)(&hidpp->send_mutex);
do {
ret = __do_hidpp_send_message_sync(hidpp, message, response);
if (response->report_id == REPORT_ID_HIDPP_SHORT &&
ret != HIDPP_ERROR_BUSY)
- break;
+ return ret;
if ((response->report_id == REPORT_ID_HIDPP_LONG ||
response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
ret != HIDPP20_ERROR_BUSY)
- break;
+ return ret;
dbg_hid("%s:got busy hidpp error %02X, retrying\n", __func__, ret);
} while (--max_retries);
- mutex_unlock(&hidpp->send_mutex);
return ret;
-
}
/*
--
2.56.0.506.g506a7eabc5-goog