From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163037AbdDUVjb (ORCPT ); Fri, 21 Apr 2017 17:39:31 -0400 Received: from mail.kernel.org ([198.145.29.136]:50818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1042418AbdDUVdi (ORCPT ); Fri, 21 Apr 2017 17:33:38 -0400 Message-Id: <20170421213332.263379887@goodmis.org> User-Agent: quilt/0.63-1 Date: Fri, 21 Apr 2017 17:30:45 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Andrew Morton Subject: [for-next][PATCH 25/33] ftrace: If the hash for a probe fails to update then free what was initialized References: <20170421213020.875637678@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=0025-ftrace-If-the-hash-for-a-probe-fails-to-update-then-.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" 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) --- kernel/trace/ftrace.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 493c7ff7e860..8394055e6793 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -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); @@ -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 -- 2.10.2