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

index e15a93619e827ff93659d8441dd2aeb14a287329..b92268ddfd84215a57a5f1091edb87df13970832 100644 (file)
@@ -521,13 +521,11 @@ static int __maybe_unused imx_kbd_noirq_suspend(struct device *dev)
        struct input_dev *input_dev = kbd->input_dev;
        unsigned short reg_val = readw(kbd->mmio_base + KPSR);
 
-       /* imx kbd can wake up system even clock is disabled */
-       mutex_lock(&input_dev->mutex);
-
-       if (input_device_enabled(input_dev))
-               clk_disable_unprepare(kbd->clk);
-
-       mutex_unlock(&input_dev->mutex);
+       scoped_guard(mutex, &input_dev->mutex) {
+               /* imx kbd can wake up system even clock is disabled */
+               if (input_device_enabled(input_dev))
+                       clk_disable_unprepare(kbd->clk);
+       }
 
        if (device_may_wakeup(&pdev->dev)) {
                if (reg_val & KBD_STAT_KPKD)
@@ -547,23 +545,20 @@ static int __maybe_unused imx_kbd_noirq_resume(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct imx_keypad *kbd = platform_get_drvdata(pdev);
        struct input_dev *input_dev = kbd->input_dev;
-       int ret = 0;
+       int error;
 
        if (device_may_wakeup(&pdev->dev))
                disable_irq_wake(kbd->irq);
 
-       mutex_lock(&input_dev->mutex);
+       guard(mutex)(&input_dev->mutex);
 
        if (input_device_enabled(input_dev)) {
-               ret = clk_prepare_enable(kbd->clk);
-               if (ret)
-                       goto err_clk;
+               error = clk_prepare_enable(kbd->clk);
+               if (error)
+                       return error;
        }
 
-err_clk:
-       mutex_unlock(&input_dev->mutex);
-
-       return ret;
+       return 0;
 }
 
 static const struct dev_pm_ops imx_kbd_pm_ops = {