]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ftrace: Add ftrace_hash_remove function
authorJiri Olsa <jolsa@kernel.org>
Sat, 6 Jun 2026 12:39:27 +0000 (14:39 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 7 Jun 2026 17:03:00 +0000 (10:03 -0700)
Adding ftrace_hash_remove function that removes all entries
from struct ftrace_hash object without freeing them.

It will be used in following changes where entries are allocated
as part of another structure and are free-ed separately.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260606123955.345967-3-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/ftrace.h
kernel/trace/ftrace.c

index 02c24bf766cedc4fa0421f9f33554333b89b4db2..b55ec9b25bb3c298fde4ebcfdcd387209a6dc69c 100644 (file)
@@ -415,6 +415,7 @@ struct ftrace_hash *alloc_ftrace_hash(int size_bits);
 void free_ftrace_hash(struct ftrace_hash *hash);
 struct ftrace_func_entry *add_ftrace_hash_entry_direct(struct ftrace_hash *hash,
                                                       unsigned long ip, unsigned long direct);
+void ftrace_hash_remove(struct ftrace_hash *hash);
 
 /* The hash used to know what functions callbacks trace */
 struct ftrace_ops_hash {
index 57ab01fd00bda3bafa472c2b4b788aed7e43bc0b..45548b0200eb47b796acfbf005d27aefec7f5ed6 100644 (file)
@@ -1249,6 +1249,25 @@ remove_hash_entry(struct ftrace_hash *hash,
        hash->count--;
 }
 
+void ftrace_hash_remove(struct ftrace_hash *hash)
+{
+       struct ftrace_func_entry *entry;
+       struct hlist_head *hhd;
+       struct hlist_node *tn;
+       int size;
+       int i;
+
+       if (!hash || !hash->count)
+               return;
+       size = 1 << hash->size_bits;
+       for (i = 0; i < size; i++) {
+               hhd = &hash->buckets[i];
+               hlist_for_each_entry_safe(entry, tn, hhd, hlist)
+                       remove_hash_entry(hash, entry);
+       }
+       FTRACE_WARN_ON(hash->count);
+}
+
 static void ftrace_hash_clear(struct ftrace_hash *hash)
 {
        struct hlist_head *hhd;