]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: cma3000_d0x - use guard notation when acquiring mutex
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 4 Sep 2024 04:42:24 +0000 (21:42 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 3 Oct 2024 16:10:35 +0000 (09:10 -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: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240904044244.1042174-5-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/cma3000_d0x.c

index 0c68e924a1ccdc1dc11279fe37ad6ba86f189aeb..cfc12332bee149d03015ba33b1fd7358605c54ae 100644 (file)
@@ -217,15 +217,13 @@ static int cma3000_open(struct input_dev *input_dev)
 {
        struct cma3000_accl_data *data = input_get_drvdata(input_dev);
 
-       mutex_lock(&data->mutex);
+       guard(mutex)(&data->mutex);
 
        if (!data->suspended)
                cma3000_poweron(data);
 
        data->opened = true;
 
-       mutex_unlock(&data->mutex);
-
        return 0;
 }
 
@@ -233,40 +231,34 @@ static void cma3000_close(struct input_dev *input_dev)
 {
        struct cma3000_accl_data *data = input_get_drvdata(input_dev);
 
-       mutex_lock(&data->mutex);
+       guard(mutex)(&data->mutex);
 
        if (!data->suspended)
                cma3000_poweroff(data);
 
        data->opened = false;
-
-       mutex_unlock(&data->mutex);
 }
 
 void cma3000_suspend(struct cma3000_accl_data *data)
 {
-       mutex_lock(&data->mutex);
+       guard(mutex)(&data->mutex);
 
        if (!data->suspended && data->opened)
                cma3000_poweroff(data);
 
        data->suspended = true;
-
-       mutex_unlock(&data->mutex);
 }
 EXPORT_SYMBOL(cma3000_suspend);
 
 
 void cma3000_resume(struct cma3000_accl_data *data)
 {
-       mutex_lock(&data->mutex);
+       guard(mutex)(&data->mutex);
 
        if (data->suspended && data->opened)
                cma3000_poweron(data);
 
        data->suspended = false;
-
-       mutex_unlock(&data->mutex);
 }
 EXPORT_SYMBOL(cma3000_resume);