mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-28 06:44:36 -05:00
Input: kxtj9 - use guard notation when acquiring mutex/disabling irq
Using guard notation makes the code more compact and error handling more robust by ensuring that mutexes are released and interrupts are re-enabled 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-7-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
@@ -314,9 +314,8 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr,
|
||||
return error;
|
||||
|
||||
/* Lock the device to prevent races with open/close (and itself) */
|
||||
mutex_lock(&input_dev->mutex);
|
||||
|
||||
disable_irq(client->irq);
|
||||
guard(mutex)(&input_dev->mutex);
|
||||
guard(disable_irq)(&client->irq);
|
||||
|
||||
/*
|
||||
* Set current interval to the greater of the minimum interval or
|
||||
@@ -326,9 +325,6 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr,
|
||||
|
||||
kxtj9_update_odr(tj9, tj9->last_poll_interval);
|
||||
|
||||
enable_irq(client->irq);
|
||||
mutex_unlock(&input_dev->mutex);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -504,12 +500,11 @@ static int kxtj9_suspend(struct device *dev)
|
||||
struct kxtj9_data *tj9 = i2c_get_clientdata(client);
|
||||
struct input_dev *input_dev = tj9->input_dev;
|
||||
|
||||
mutex_lock(&input_dev->mutex);
|
||||
guard(mutex)(&input_dev->mutex);
|
||||
|
||||
if (input_device_enabled(input_dev))
|
||||
kxtj9_disable(tj9);
|
||||
|
||||
mutex_unlock(&input_dev->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -519,12 +514,11 @@ static int kxtj9_resume(struct device *dev)
|
||||
struct kxtj9_data *tj9 = i2c_get_clientdata(client);
|
||||
struct input_dev *input_dev = tj9->input_dev;
|
||||
|
||||
mutex_lock(&input_dev->mutex);
|
||||
guard(mutex)(&input_dev->mutex);
|
||||
|
||||
if (input_device_enabled(input_dev))
|
||||
kxtj9_enable(tj9);
|
||||
|
||||
mutex_unlock(&input_dev->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user