Skip to content

Commit

Permalink
ftrace: If the hash for a probe fails to update then free what was in…
Browse files Browse the repository at this point in the history
…itialized

If the ftrace_hash_move_and_update_ops() fails, and an ops->free() function
exists, then it needs to be called on all the ops that were added by this
registration.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
rostedt committed Apr 21, 2017
1 parent eee8ded commit 8d70725
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4003,7 +4003,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
ret = ftrace_hash_move_and_update_ops(&ops->ops, orig_hash,
hash, 1);
if (ret < 0)
goto out_unlock;
goto err_unlock;

if (list_empty(&ops->list))
list_add(&ops->list, &ftrace_func_probes);
Expand All @@ -4021,6 +4021,20 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
free_ftrace_hash(hash);

return ret;

err_unlock:
if (!ops->free)
goto out_unlock;

/* Failed to do the move, need to call the free functions */
for (i = 0; i < size; i++) {
hlist_for_each_entry(entry, &hash->buckets[i], hlist) {
if (ftrace_lookup_ip(old_hash, entry->ip))
continue;
ops->free(ops, entry->ip, NULL);
}
}
goto out_unlock;
}

int
Expand Down

0 comments on commit 8d70725

Please sign in to comment.