]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: pxa27x_keypad - use guard notation when acquiring mutex
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 25 Aug 2024 05:16:18 +0000 (22:16 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 3 Oct 2024 15:58:57 +0000 (08:58 -0700)
This 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/20240825051627.2848495-15-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/pxa27x_keypad.c

index 3724363d140e5f99163dbe97da8fa4900700011d..38ec619aa359068d2092fbd16479f52e22b47d32 100644 (file)
@@ -682,7 +682,7 @@ static int pxa27x_keypad_resume(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
        struct input_dev *input_dev = keypad->input_dev;
-       int ret = 0;
+       int error;
 
        /*
         * If the keypad is used as wake up source, the clock is not turned
@@ -691,19 +691,19 @@ static int pxa27x_keypad_resume(struct device *dev)
        if (device_may_wakeup(&pdev->dev)) {
                disable_irq_wake(keypad->irq);
        } else {
-               mutex_lock(&input_dev->mutex);
+               guard(mutex)(&input_dev->mutex);
 
                if (input_device_enabled(input_dev)) {
                        /* Enable unit clock */
-                       ret = clk_prepare_enable(keypad->clk);
-                       if (!ret)
-                               pxa27x_keypad_config(keypad);
-               }
+                       error = clk_prepare_enable(keypad->clk);
+                       if (error)
+                               return error;
 
-               mutex_unlock(&input_dev->mutex);
+                       pxa27x_keypad_config(keypad);
+               }
        }
 
-       return ret;
+       return 0;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops,