Skip to content

Commit 06294cf

Browse files
committed
ftrace: Use guard for match_records()
The ftrace_lock is held for most of match_records() until the end of the function. Use guard to make error paths simpler. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 6348a3f commit 06294cf

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

kernel/trace/ftrace.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,15 +4829,13 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
48294829
mod_g.len = strlen(mod_g.search);
48304830
}
48314831

4832-
mutex_lock(&ftrace_lock);
4832+
guard(mutex)(&ftrace_lock);
48334833

48344834
if (unlikely(ftrace_disabled))
4835-
goto out_unlock;
4835+
return 0;
48364836

4837-
if (func_g.type == MATCH_INDEX) {
4838-
found = add_rec_by_index(hash, &func_g, clear_filter);
4839-
goto out_unlock;
4840-
}
4837+
if (func_g.type == MATCH_INDEX)
4838+
return add_rec_by_index(hash, &func_g, clear_filter);
48414839

48424840
do_for_each_ftrace_rec(pg, rec) {
48434841

@@ -4846,16 +4844,12 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
48464844

48474845
if (ftrace_match_record(rec, &func_g, mod_match, exclude_mod)) {
48484846
ret = enter_record(hash, rec, clear_filter);
4849-
if (ret < 0) {
4850-
found = ret;
4851-
goto out_unlock;
4852-
}
4847+
if (ret < 0)
4848+
return ret;
48534849
found = 1;
48544850
}
48554851
cond_resched();
48564852
} while_for_each_ftrace_rec();
4857-
out_unlock:
4858-
mutex_unlock(&ftrace_lock);
48594853

48604854
return found;
48614855
}

0 commit comments

Comments
 (0)