]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: st-keyscan - use guard notation when acquiring mutex
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 25 Aug 2024 05:16:20 +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-17-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/st-keyscan.c

index 0d27324af809b2a01be24248a93ce172bf4c7158..e53ef4c670e4b87745ef6fdcaf3def3bf047e114 100644 (file)
@@ -216,14 +216,13 @@ static int keyscan_suspend(struct device *dev)
        struct st_keyscan *keypad = platform_get_drvdata(pdev);
        struct input_dev *input = keypad->input_dev;
 
-       mutex_lock(&input->mutex);
+       guard(mutex)(&input->mutex);
 
        if (device_may_wakeup(dev))
                enable_irq_wake(keypad->irq);
        else if (input_device_enabled(input))
                keyscan_stop(keypad);
 
-       mutex_unlock(&input->mutex);
        return 0;
 }
 
@@ -232,17 +231,19 @@ static int keyscan_resume(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct st_keyscan *keypad = platform_get_drvdata(pdev);
        struct input_dev *input = keypad->input_dev;
-       int retval = 0;
+       int error;
 
-       mutex_lock(&input->mutex);
+       guard(mutex)(&input->mutex);
 
-       if (device_may_wakeup(dev))
+       if (device_may_wakeup(dev)) {
                disable_irq_wake(keypad->irq);
-       else if (input_device_enabled(input))
-               retval = keyscan_start(keypad);
+       } else if (input_device_enabled(input)) {
+               error = keyscan_start(keypad);
+               if (error)
+                       return error;
+       }
 
-       mutex_unlock(&input->mutex);
-       return retval;
+       return 0;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(keyscan_dev_pm_ops,