Skip to content

Commit 8b0cb3a

Browse files
committed
ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash()
The ftrace_lock is taken for most of the ftrace_graph_set_hash() function throughout the end. Use guard to take the ftrace_lock to simplify the exit paths. 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 9687bbf commit 8b0cb3a

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

kernel/trace/ftrace.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6816,12 +6816,10 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
68166816

68176817
func_g.len = strlen(func_g.search);
68186818

6819-
mutex_lock(&ftrace_lock);
6819+
guard(mutex)(&ftrace_lock);
68206820

6821-
if (unlikely(ftrace_disabled)) {
6822-
mutex_unlock(&ftrace_lock);
6821+
if (unlikely(ftrace_disabled))
68236822
return -ENODEV;
6824-
}
68256823

68266824
do_for_each_ftrace_rec(pg, rec) {
68276825

@@ -6837,7 +6835,7 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
68376835
if (entry)
68386836
continue;
68396837
if (add_hash_entry(hash, rec->ip) == NULL)
6840-
goto out;
6838+
return 0;
68416839
} else {
68426840
if (entry) {
68436841
free_hash_entry(hash, entry);
@@ -6846,13 +6844,8 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer)
68466844
}
68476845
}
68486846
} while_for_each_ftrace_rec();
6849-
out:
6850-
mutex_unlock(&ftrace_lock);
68516847

6852-
if (fail)
6853-
return -EINVAL;
6854-
6855-
return 0;
6848+
return fail ? -EINVAL : 0;
68566849
}
68576850

68586851
static ssize_t

0 commit comments

Comments
 (0)