summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2024-10-27 22:50:18 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2024-11-05 14:17:32 -0800
commit6b6b40ff05ab43b603abd7ae1821892307421d49 (patch)
treeb8490439d409ba693c14ee87a5f44101d44cd03d
parent229ba714e52f7f29f41c1aa2e9f49feef3629322 (diff)
downloadlwn-6b6b40ff05ab43b603abd7ae1821892307421d49.tar.gz
lwn-6b6b40ff05ab43b603abd7ae1821892307421d49.zip
Input: maple_keyb - use guard notation when acquiring mutex
Using guard notation makes the code more compact and error handling more robust by ensuring that mutexes are released in all code paths when control leaves critical section. Link: https://lore.kernel.org/r/Zx8mGiWOw1Av28TX@google.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/keyboard/maple_keyb.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index 91a1d2958109..1a8f1fa53fbb 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -132,14 +132,11 @@ static void dc_kbd_callback(struct mapleq *mq)
* We should always get the lock because the only
* time it may be locked is if the driver is in the cleanup phase.
*/
- if (likely(mutex_trylock(&maple_keyb_mutex))) {
-
+ scoped_guard(mutex_try, &maple_keyb_mutex) {
if (buf[1] == mapledev->function) {
memcpy(kbd->new, buf + 2, 8);
dc_scan_kbd(kbd);
}
-
- mutex_unlock(&maple_keyb_mutex);
}
}
@@ -211,14 +208,12 @@ static int remove_maple_kbd(struct device *dev)
struct maple_device *mdev = to_maple_dev(dev);
struct dc_kbd *kbd = maple_get_drvdata(mdev);
- mutex_lock(&maple_keyb_mutex);
+ guard(mutex)(&maple_keyb_mutex);
input_unregister_device(kbd->dev);
kfree(kbd);
maple_set_drvdata(mdev, NULL);
-
- mutex_unlock(&maple_keyb_mutex);
return 0;
}