diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2024-08-24 22:16:11 -0700 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2024-10-03 08:53:14 -0700 |
commit | d1212ac94e8168eb6f8d317d59303c7752f615ff (patch) | |
tree | a6dc60b03db6e6efe8f645026c5fb5f287fcacf0 | |
parent | 2f39a9fc876e965d79a1ee097f06af87607b9fec (diff) |
Input: ipaq-micro-keys - use guard notation when acquiring mutex and spinlock
This makes the code more compact and error handling more robust
by ensuring that locks are released in all code paths when control
leaves critical section.
Link: https://lore.kernel.org/r/20240825051627.2848495-8-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r-- | drivers/input/keyboard/ipaq-micro-keys.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c index 1d71dd79ffd2..58631bf7ce55 100644 --- a/drivers/input/keyboard/ipaq-micro-keys.c +++ b/drivers/input/keyboard/ipaq-micro-keys.c @@ -54,18 +54,18 @@ static void micro_key_receive(void *data, int len, unsigned char *msg) static void micro_key_start(struct ipaq_micro_keys *keys) { - spin_lock(&keys->micro->lock); + guard(spinlock)(&keys->micro->lock); + keys->micro->key = micro_key_receive; keys->micro->key_data = keys; - spin_unlock(&keys->micro->lock); } static void micro_key_stop(struct ipaq_micro_keys *keys) { - spin_lock(&keys->micro->lock); + guard(spinlock)(&keys->micro->lock); + keys->micro->key = NULL; keys->micro->key_data = NULL; - spin_unlock(&keys->micro->lock); } static int micro_key_open(struct input_dev *input) @@ -141,13 +141,11 @@ static int micro_key_resume(struct device *dev) struct ipaq_micro_keys *keys = dev_get_drvdata(dev); struct input_dev *input = keys->input; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); if (input_device_enabled(input)) micro_key_start(keys); - mutex_unlock(&input->mutex); - return 0; } |