tracing: Switch trace_events_hist.c code over to use guard()
[ Upstream commit 2b36a97aeeb71b1e4a48bfedc7f21f44aeb1e6fb ] There are a couple functions in trace_events_hist.c that have "goto out" or equivalent on error in order to release locks that were taken. This can be error prone or just simply make the code more complex. Switch every location that ends with unlocking a mutex on error over to using the guard(mutex)() infrastructure to let the compiler worry about releasing locks. This makes the code easier to read and understand. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/20241219201345.694601480@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Stable-dep-of: 0b4ffbe4888a ("tracing: Correct the refcount if the hist/hist_debug file fails to open") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
7de8290a66
commit
387dc88c2c
@@ -5597,25 +5597,19 @@ static int hist_show(struct seq_file *m, void *v)
|
||||
{
|
||||
struct event_trigger_data *data;
|
||||
struct trace_event_file *event_file;
|
||||
int n = 0, ret = 0;
|
||||
int n = 0;
|
||||
|
||||
mutex_lock(&event_mutex);
|
||||
guard(mutex)(&event_mutex);
|
||||
|
||||
event_file = event_file_file(m->private);
|
||||
if (unlikely(!event_file)) {
|
||||
ret = -ENODEV;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (unlikely(!event_file))
|
||||
return -ENODEV;
|
||||
|
||||
list_for_each_entry(data, &event_file->triggers, list) {
|
||||
if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
|
||||
hist_trigger_show(m, data, n++);
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&event_mutex);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int event_hist_open(struct inode *inode, struct file *file)
|
||||
@@ -5876,25 +5870,19 @@ static int hist_debug_show(struct seq_file *m, void *v)
|
||||
{
|
||||
struct event_trigger_data *data;
|
||||
struct trace_event_file *event_file;
|
||||
int n = 0, ret = 0;
|
||||
int n = 0;
|
||||
|
||||
mutex_lock(&event_mutex);
|
||||
guard(mutex)(&event_mutex);
|
||||
|
||||
event_file = event_file_file(m->private);
|
||||
if (unlikely(!event_file)) {
|
||||
ret = -ENODEV;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (unlikely(!event_file))
|
||||
return -ENODEV;
|
||||
|
||||
list_for_each_entry(data, &event_file->triggers, list) {
|
||||
if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
|
||||
hist_trigger_debug_show(m, data, n++);
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&event_mutex);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int event_hist_debug_open(struct inode *inode, struct file *file)
|
||||
|
||||
Reference in New Issue
Block a user