Re: [RFC PATCH 03/14] ftrace: Fix cleanup in error path of register_ftrace_direct()

From: Steven Rostedt
Date: Mon Nov 30 2020 - 21:37:15 EST


On Thu, 26 Nov 2020 23:38:40 +0530
"Naveen N. Rao" <naveen.n.rao@xxxxxxxxxxxxxxxxxx> wrote:

> We need to remove hash entry if register_ftrace_function() fails.
> Consolidate the cleanup to be done after register_ftrace_function() at
> the end.

Reviewed-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>

-- Steve

>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@xxxxxxxxxxxxxxxxxx>
> ---
> kernel/trace/ftrace.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 9c1bba8cc51b03..3844a4a1346a9c 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -5136,8 +5136,6 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr)
> __add_hash_entry(direct_functions, entry);
>
> ret = ftrace_set_filter_ip(&direct_ops, ip, 0, 0);
> - if (ret)
> - remove_hash_entry(direct_functions, entry);
>
> if (!ret && !(direct_ops.flags & FTRACE_OPS_FL_ENABLED)) {
> ret = register_ftrace_function(&direct_ops);
> @@ -5146,6 +5144,7 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr)
> }
>
> if (ret) {
> + remove_hash_entry(direct_functions, entry);
> kfree(entry);
> if (!direct->count) {
> list_del_rcu(&direct->next);