Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Use refcount for trace_event_file reference counter

Instead of using an atomic counter for the trace_event_file reference
counter, use the refcount interface. It has various checks to make sure
the reference counting is correct, and will warn if it detects an error
(like refcount_inc() on '0').

Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20240726144208.687cce24@rorschach.local.home
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+5 -5
+1 -1
include/linux/trace_events.h
··· 680 680 * caching and such. Which is mostly OK ;-) 681 681 */ 682 682 unsigned long flags; 683 - atomic_t ref; /* ref count for opened files */ 683 + refcount_t ref; /* ref count for opened files */ 684 684 atomic_t sm_ref; /* soft-mode reference counter */ 685 685 atomic_t tm_ref; /* trigger-mode reference counter */ 686 686 };
+4 -4
kernel/trace/trace_events.c
··· 992 992 993 993 void event_file_get(struct trace_event_file *file) 994 994 { 995 - atomic_inc(&file->ref); 995 + refcount_inc(&file->ref); 996 996 } 997 997 998 998 void event_file_put(struct trace_event_file *file) 999 999 { 1000 - if (WARN_ON_ONCE(!atomic_read(&file->ref))) { 1000 + if (WARN_ON_ONCE(!refcount_read(&file->ref))) { 1001 1001 if (file->flags & EVENT_FILE_FL_FREED) 1002 1002 kmem_cache_free(file_cachep, file); 1003 1003 return; 1004 1004 } 1005 1005 1006 - if (atomic_dec_and_test(&file->ref)) { 1006 + if (refcount_dec_and_test(&file->ref)) { 1007 1007 /* Count should only go to zero when it is freed */ 1008 1008 if (WARN_ON_ONCE(!(file->flags & EVENT_FILE_FL_FREED))) 1009 1009 return; ··· 3003 3003 atomic_set(&file->tm_ref, 0); 3004 3004 INIT_LIST_HEAD(&file->triggers); 3005 3005 list_add(&file->list, &tr->events); 3006 - event_file_get(file); 3006 + refcount_set(&file->ref, 1); 3007 3007 3008 3008 return file; 3009 3009 }