ftrace: Comment that ftrace_func_mapper is freed with free_ftrace_hash()
authorSteven Rostedt <rostedt@goodmis.org>
Wed, 16 Apr 2025 20:54:20 +0000 (16:54 -0400)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 8 May 2025 13:36:08 +0000 (09:36 -0400)
The structure ftrace_func_mapper only contains a single field and that is
a ftrace_hash. It is used to abstract it out from a normal hash to control
users of how it gets modified.

The freeing of a ftrace_func_mapper structure is:

  free_ftrace_hash(&mapper->hash);

Without context, this looks like a bug. It should be commented that it is
not a bug and it is freed this way.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/20250416165420.5c717420@gandalf.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index 014cd2cedae35f79769a49ff3901dd6c5b43994b..1af952cba48d2ae5b31f0535456142907da6b773 100644 (file)
@@ -5208,8 +5208,12 @@ struct ftrace_func_map {
        void                            *data;
 };
 
+/*
+ * Note, ftrace_func_mapper is freed by free_ftrace_hash(&mapper->hash).
+ * The hash field must be the first field.
+ */
 struct ftrace_func_mapper {
-       struct ftrace_hash              hash;
+       struct ftrace_hash              hash;   /* Must be first! */
 };
 
 /**
@@ -5344,6 +5348,7 @@ void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
                        }
                }
        }
+       /* This also frees the mapper itself */
        free_ftrace_hash(&mapper->hash);
 }