mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-06 05:06:29 +00:00
Input: n64joy - use guard notation when acquiring mutex
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. Link: https://lore.kernel.org/r/20240904043104.1030257-5-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
63ade96711
commit
d68ed9b580
@ -191,35 +191,32 @@ static void n64joy_poll(struct timer_list *t)
|
||||
static int n64joy_open(struct input_dev *dev)
|
||||
{
|
||||
struct n64joy_priv *priv = input_get_drvdata(dev);
|
||||
int err;
|
||||
|
||||
err = mutex_lock_interruptible(&priv->n64joy_mutex);
|
||||
if (err)
|
||||
return err;
|
||||
scoped_guard(mutex_intr, &priv->n64joy_mutex) {
|
||||
if (!priv->n64joy_opened) {
|
||||
/*
|
||||
* We could use the vblank irq, but it's not important
|
||||
* if the poll point slightly changes.
|
||||
*/
|
||||
timer_setup(&priv->timer, n64joy_poll, 0);
|
||||
mod_timer(&priv->timer, jiffies + msecs_to_jiffies(16));
|
||||
}
|
||||
|
||||
if (!priv->n64joy_opened) {
|
||||
/*
|
||||
* We could use the vblank irq, but it's not important if
|
||||
* the poll point slightly changes.
|
||||
*/
|
||||
timer_setup(&priv->timer, n64joy_poll, 0);
|
||||
mod_timer(&priv->timer, jiffies + msecs_to_jiffies(16));
|
||||
priv->n64joy_opened++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
priv->n64joy_opened++;
|
||||
|
||||
mutex_unlock(&priv->n64joy_mutex);
|
||||
return err;
|
||||
return -EINTR;
|
||||
}
|
||||
|
||||
static void n64joy_close(struct input_dev *dev)
|
||||
{
|
||||
struct n64joy_priv *priv = input_get_drvdata(dev);
|
||||
|
||||
mutex_lock(&priv->n64joy_mutex);
|
||||
guard(mutex)(&priv->n64joy_mutex);
|
||||
|
||||
if (!--priv->n64joy_opened)
|
||||
del_timer_sync(&priv->timer);
|
||||
mutex_unlock(&priv->n64joy_mutex);
|
||||
}
|
||||
|
||||
static const u64 __initconst scandata[] ____cacheline_aligned = {
|
||||
|
Loading…
Reference in New Issue
Block a user