Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+2 -7
+2 -7
drivers/input/keyboard/maple_keyb.c
··· 132 132 * We should always get the lock because the only 133 133 * time it may be locked is if the driver is in the cleanup phase. 134 134 */ 135 - if (likely(mutex_trylock(&maple_keyb_mutex))) { 136 - 135 + scoped_guard(mutex_try, &maple_keyb_mutex) { 137 136 if (buf[1] == mapledev->function) { 138 137 memcpy(kbd->new, buf + 2, 8); 139 138 dc_scan_kbd(kbd); 140 139 } 141 - 142 - mutex_unlock(&maple_keyb_mutex); 143 140 } 144 141 } 145 142 ··· 208 211 struct maple_device *mdev = to_maple_dev(dev); 209 212 struct dc_kbd *kbd = maple_get_drvdata(mdev); 210 213 211 - mutex_lock(&maple_keyb_mutex); 214 + guard(mutex)(&maple_keyb_mutex); 212 215 213 216 input_unregister_device(kbd->dev); 214 217 kfree(kbd); 215 218 216 219 maple_set_drvdata(mdev, NULL); 217 - 218 - mutex_unlock(&maple_keyb_mutex); 219 220 return 0; 220 221 } 221 222