Skip to content

Commit 076796f

Browse files
committed
tracing: Switch trace_events_filter.c code over to use guard()
There are a couple functions in trace_events_filter.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 63c7264 commit 076796f

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,13 +2405,11 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
24052405
struct event_filter *filter = NULL;
24062406
int err = 0;
24072407

2408-
mutex_lock(&event_mutex);
2408+
guard(mutex)(&event_mutex);
24092409

24102410
/* Make sure the system still has events */
2411-
if (!dir->nr_events) {
2412-
err = -ENODEV;
2413-
goto out_unlock;
2414-
}
2411+
if (!dir->nr_events)
2412+
return -ENODEV;
24152413

24162414
if (!strcmp(strstrip(filter_string), "0")) {
24172415
filter_free_subsystem_preds(dir, tr);
@@ -2422,7 +2420,7 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
24222420
tracepoint_synchronize_unregister();
24232421
filter_free_subsystem_filters(dir, tr);
24242422
__free_filter(filter);
2425-
goto out_unlock;
2423+
return 0;
24262424
}
24272425

24282426
err = create_system_filter(dir, filter_string, &filter);
@@ -2434,8 +2432,6 @@ int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
24342432
__free_filter(system->filter);
24352433
system->filter = filter;
24362434
}
2437-
out_unlock:
2438-
mutex_unlock(&event_mutex);
24392435

24402436
return err;
24412437
}
@@ -2612,17 +2608,15 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
26122608
struct event_filter *filter = NULL;
26132609
struct trace_event_call *call;
26142610

2615-
mutex_lock(&event_mutex);
2611+
guard(mutex)(&event_mutex);
26162612

26172613
call = event->tp_event;
26182614

2619-
err = -EINVAL;
26202615
if (!call)
2621-
goto out_unlock;
2616+
return -EINVAL;
26222617

2623-
err = -EEXIST;
26242618
if (event->filter)
2625-
goto out_unlock;
2619+
return -EEXIST;
26262620

26272621
err = create_filter(NULL, call, filter_str, false, &filter);
26282622
if (err)
@@ -2637,9 +2631,6 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
26372631
if (err || ftrace_event_is_function(call))
26382632
__free_filter(filter);
26392633

2640-
out_unlock:
2641-
mutex_unlock(&event_mutex);
2642-
26432634
return err;
26442635
}
26452636

0 commit comments

Comments
 (0)