Skip to content

Commit 2b36a97

Browse files
committed
tracing: Switch trace_events_hist.c code over to use guard()
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 <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 59980d9 commit 2b36a97

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5594,25 +5594,19 @@ static int hist_show(struct seq_file *m, void *v)
55945594
{
55955595
struct event_trigger_data *data;
55965596
struct trace_event_file *event_file;
5597-
int n = 0, ret = 0;
5597+
int n = 0;
55985598

5599-
mutex_lock(&event_mutex);
5599+
guard(mutex)(&event_mutex);
56005600

56015601
event_file = event_file_file(m->private);
5602-
if (unlikely(!event_file)) {
5603-
ret = -ENODEV;
5604-
goto out_unlock;
5605-
}
5602+
if (unlikely(!event_file))
5603+
return -ENODEV;
56065604

56075605
list_for_each_entry(data, &event_file->triggers, list) {
56085606
if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
56095607
hist_trigger_show(m, data, n++);
56105608
}
5611-
5612-
out_unlock:
5613-
mutex_unlock(&event_mutex);
5614-
5615-
return ret;
5609+
return 0;
56165610
}
56175611

56185612
static int event_hist_open(struct inode *inode, struct file *file)
@@ -5873,25 +5867,19 @@ static int hist_debug_show(struct seq_file *m, void *v)
58735867
{
58745868
struct event_trigger_data *data;
58755869
struct trace_event_file *event_file;
5876-
int n = 0, ret = 0;
5870+
int n = 0;
58775871

5878-
mutex_lock(&event_mutex);
5872+
guard(mutex)(&event_mutex);
58795873

58805874
event_file = event_file_file(m->private);
5881-
if (unlikely(!event_file)) {
5882-
ret = -ENODEV;
5883-
goto out_unlock;
5884-
}
5875+
if (unlikely(!event_file))
5876+
return -ENODEV;
58855877

58865878
list_for_each_entry(data, &event_file->triggers, list) {
58875879
if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
58885880
hist_trigger_debug_show(m, data, n++);
58895881
}
5890-
5891-
out_unlock:
5892-
mutex_unlock(&event_mutex);
5893-
5894-
return ret;
5882+
return 0;
58955883
}
58965884

58975885
static int event_hist_debug_open(struct inode *inode, struct file *file)

0 commit comments

Comments
 (0)