mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 11:06:41 -05:00
rv: Convert to use lock guard
Convert to use lock guard to tidy up the code. Signed-off-by: Nam Cao <namcao@linutronix.de> Reviewed-by: Gabriele Monaco <gmonaco@redhat.com> Link: https://lore.kernel.org/r/dbefeb868093c40d4b29fd6b57294a6aa011b719.1763370183.git.namcao@linutronix.de Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
This commit is contained in:
@@ -375,15 +375,13 @@ static ssize_t monitor_enable_write_data(struct file *filp, const char __user *u
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
if (val)
|
||||
retval = rv_enable_monitor(mon);
|
||||
else
|
||||
retval = rv_disable_monitor(mon);
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
|
||||
return retval ? : count;
|
||||
}
|
||||
|
||||
@@ -568,7 +566,7 @@ static void disable_all_monitors(void)
|
||||
struct rv_monitor *mon;
|
||||
int enabled = 0;
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
list_for_each_entry(mon, &rv_monitors_list, list)
|
||||
enabled += __rv_disable_monitor(mon, false);
|
||||
@@ -581,8 +579,6 @@ static void disable_all_monitors(void)
|
||||
*/
|
||||
tracepoint_synchronize_unregister();
|
||||
}
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
}
|
||||
|
||||
static int enabled_monitors_open(struct inode *inode, struct file *file)
|
||||
@@ -623,7 +619,7 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user
|
||||
if (!len)
|
||||
return count;
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
retval = -EINVAL;
|
||||
|
||||
@@ -644,13 +640,11 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user
|
||||
else
|
||||
retval = rv_disable_monitor(mon);
|
||||
|
||||
if (!retval)
|
||||
retval = count;
|
||||
|
||||
break;
|
||||
if (retval)
|
||||
return retval;
|
||||
return count;
|
||||
}
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -737,7 +731,7 @@ static ssize_t monitoring_on_write_data(struct file *filp, const char __user *us
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
if (val)
|
||||
turn_monitoring_on_with_reset();
|
||||
@@ -750,8 +744,6 @@ static ssize_t monitoring_on_write_data(struct file *filp, const char __user *us
|
||||
*/
|
||||
tracepoint_synchronize_unregister();
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -784,28 +776,26 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
list_for_each_entry(r, &rv_monitors_list, list) {
|
||||
if (strcmp(monitor->name, r->name) == 0) {
|
||||
pr_info("Monitor %s is already registered\n", monitor->name);
|
||||
retval = -EEXIST;
|
||||
goto out_unlock;
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent && rv_is_nested_monitor(parent)) {
|
||||
pr_info("Parent monitor %s is already nested, cannot nest further\n",
|
||||
parent->name);
|
||||
retval = -EINVAL;
|
||||
goto out_unlock;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
monitor->parent = parent;
|
||||
|
||||
retval = create_monitor_dir(monitor, parent);
|
||||
if (retval)
|
||||
goto out_unlock;
|
||||
return retval;
|
||||
|
||||
/* keep children close to the parent for easier visualisation */
|
||||
if (parent)
|
||||
@@ -813,9 +803,7 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)
|
||||
else
|
||||
list_add_tail(&monitor->list, &rv_monitors_list);
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
return retval;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -826,13 +814,12 @@ int rv_register_monitor(struct rv_monitor *monitor, struct rv_monitor *parent)
|
||||
*/
|
||||
int rv_unregister_monitor(struct rv_monitor *monitor)
|
||||
{
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
rv_disable_monitor(monitor);
|
||||
list_del(&monitor->list);
|
||||
destroy_monitor_dir(monitor);
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,9 +233,7 @@ monitor_reactors_write(struct file *file, const char __user *user_buf,
|
||||
seq_f = file->private_data;
|
||||
mon = seq_f->private;
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
|
||||
retval = -EINVAL;
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
list_for_each_entry(reactor, &rv_reactors_list, list) {
|
||||
if (strcmp(ptr, reactor->name) != 0)
|
||||
@@ -243,13 +241,10 @@ monitor_reactors_write(struct file *file, const char __user *user_buf,
|
||||
|
||||
monitor_swap_reactors(mon, reactor);
|
||||
|
||||
retval = count;
|
||||
break;
|
||||
return count;
|
||||
}
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
|
||||
return retval;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -310,18 +305,14 @@ static int __rv_register_reactor(struct rv_reactor *reactor)
|
||||
*/
|
||||
int rv_register_reactor(struct rv_reactor *reactor)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (strlen(reactor->name) >= MAX_RV_REACTOR_NAME_SIZE) {
|
||||
pr_info("Reactor %s has a name longer than %d\n",
|
||||
reactor->name, MAX_RV_MONITOR_NAME_SIZE);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
retval = __rv_register_reactor(reactor);
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
return retval;
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
return __rv_register_reactor(reactor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,9 +323,8 @@ int rv_register_reactor(struct rv_reactor *reactor)
|
||||
*/
|
||||
int rv_unregister_reactor(struct rv_reactor *reactor)
|
||||
{
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
list_del(&reactor->list);
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -390,7 +380,7 @@ static ssize_t reacting_on_write_data(struct file *filp, const char __user *user
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
mutex_lock(&rv_interface_lock);
|
||||
guard(mutex)(&rv_interface_lock);
|
||||
|
||||
if (val)
|
||||
turn_reacting_on();
|
||||
@@ -403,8 +393,6 @@ static ssize_t reacting_on_write_data(struct file *filp, const char __user *user
|
||||
*/
|
||||
tracepoint_synchronize_unregister();
|
||||
|
||||
mutex_unlock(&rv_interface_lock);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user