* [PATCH] Input: omap-keypad - use guard notation when acquiring mutex
@ 2024-10-25 1:47 Dmitry Torokhov
2024-10-28 14:31 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2024-10-25 1:47 UTC (permalink / raw)
To: linux-input
Cc: Tony Lindgren, Uwe Kleine-König, Linus Walleij, linux-kernel
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.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/keyboard/omap-keypad.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c
index 33df8885b599..9e13f3f70a81 100644
--- a/drivers/input/keyboard/omap-keypad.c
+++ b/drivers/input/keyboard/omap-keypad.c
@@ -156,15 +156,15 @@ static ssize_t omap_kp_enable_store(struct device *dev, struct device_attribute
if ((state != 1) && (state != 0))
return -EINVAL;
- mutex_lock(&kp_enable_mutex);
- if (state != kp_enable) {
- if (state)
- enable_irq(omap_kp->irq);
- else
- disable_irq(omap_kp->irq);
- kp_enable = state;
+ scoped_guard(mutex, &kp_enable_mutex) {
+ if (state != kp_enable) {
+ if (state)
+ enable_irq(omap_kp->irq);
+ else
+ disable_irq(omap_kp->irq);
+ kp_enable = state;
+ }
}
- mutex_unlock(&kp_enable_mutex);
return strnlen(buf, count);
}
--
2.47.0.163.g1226f6d8fa-goog
--
Dmitry
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Input: omap-keypad - use guard notation when acquiring mutex
2024-10-25 1:47 [PATCH] Input: omap-keypad - use guard notation when acquiring mutex Dmitry Torokhov
@ 2024-10-28 14:31 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2024-10-28 14:31 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: linux-input, Tony Lindgren, Uwe Kleine-König, linux-kernel
On Fri, Oct 25, 2024 at 3:47 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> 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.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-28 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 1:47 [PATCH] Input: omap-keypad - use guard notation when acquiring mutex Dmitry Torokhov
2024-10-28 14:31 ` Linus Walleij
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.