Skip to content

Commit 6b6b40f

Browse files
committed
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>
1 parent 229ba71 commit 6b6b40f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

drivers/input/keyboard/maple_keyb.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,11 @@ static void dc_kbd_callback(struct mapleq *mq)
132132
* We should always get the lock because the only
133133
* time it may be locked is if the driver is in the cleanup phase.
134134
*/
135-
if (likely(mutex_trylock(&maple_keyb_mutex))) {
136-
135+
scoped_guard(mutex_try, &maple_keyb_mutex) {
137136
if (buf[1] == mapledev->function) {
138137
memcpy(kbd->new, buf + 2, 8);
139138
dc_scan_kbd(kbd);
140139
}
141-
142-
mutex_unlock(&maple_keyb_mutex);
143140
}
144141
}
145142

@@ -211,14 +208,12 @@ static int remove_maple_kbd(struct device *dev)
211208
struct maple_device *mdev = to_maple_dev(dev);
212209
struct dc_kbd *kbd = maple_get_drvdata(mdev);
213210

214-
mutex_lock(&maple_keyb_mutex);
211+
guard(mutex)(&maple_keyb_mutex);
215212

216213
input_unregister_device(kbd->dev);
217214
kfree(kbd);
218215

219216
maple_set_drvdata(mdev, NULL);
220-
221-
mutex_unlock(&maple_keyb_mutex);
222217
return 0;
223218
}
224219

0 commit comments

Comments
 (0)