Input: omap-keypad - use guard notation when acquiring mutex
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 25 Oct 2024 01:47:08 +0000 (18:47 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 30 Oct 2024 22:54:51 +0000 (15:54 -0700)
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.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/Zxr4nF-igbrmgq85@google.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/omap-keypad.c

index 33df888..9e13f3f 100644 (file)
@@ -156,15 +156,15 @@ static ssize_t omap_kp_enable_store(struct device *dev, struct device_attribute
        if ((state != 1) && (state != 0))
                return -EINVAL;
 
-       mutex_lock(&kp_enable_mutex);
-       if (state != kp_enable) {
-               if (state)
-                       enable_irq(omap_kp->irq);
-               else
-                       disable_irq(omap_kp->irq);
-               kp_enable = state;
+       scoped_guard(mutex, &kp_enable_mutex) {
+               if (state != kp_enable) {
+                       if (state)
+                               enable_irq(omap_kp->irq);
+                       else
+                               disable_irq(omap_kp->irq);
+                       kp_enable = state;
+               }
        }
-       mutex_unlock(&kp_enable_mutex);
 
        return strnlen(buf, count);
 }