Skip to content

Commit 6e2fdce

Browse files
committed
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 <[email protected]> Link: https://lore.kernel.org/[email protected] Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent b156040 commit 6e2fdce

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/linux/trace_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ struct trace_event_file {
680680
* caching and such. Which is mostly OK ;-)
681681
*/
682682
unsigned long flags;
683-
atomic_t ref; /* ref count for opened files */
683+
refcount_t ref; /* ref count for opened files */
684684
atomic_t sm_ref; /* soft-mode reference counter */
685685
atomic_t tm_ref; /* trigger-mode reference counter */
686686
};

kernel/trace/trace_events.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,18 +992,18 @@ static void remove_subsystem(struct trace_subsystem_dir *dir)
992992

993993
void event_file_get(struct trace_event_file *file)
994994
{
995-
atomic_inc(&file->ref);
995+
refcount_inc(&file->ref);
996996
}
997997

998998
void event_file_put(struct trace_event_file *file)
999999
{
1000-
if (WARN_ON_ONCE(!atomic_read(&file->ref))) {
1000+
if (WARN_ON_ONCE(!refcount_read(&file->ref))) {
10011001
if (file->flags & EVENT_FILE_FL_FREED)
10021002
kmem_cache_free(file_cachep, file);
10031003
return;
10041004
}
10051005

1006-
if (atomic_dec_and_test(&file->ref)) {
1006+
if (refcount_dec_and_test(&file->ref)) {
10071007
/* Count should only go to zero when it is freed */
10081008
if (WARN_ON_ONCE(!(file->flags & EVENT_FILE_FL_FREED)))
10091009
return;
@@ -3003,7 +3003,7 @@ trace_create_new_event(struct trace_event_call *call,
30033003
atomic_set(&file->tm_ref, 0);
30043004
INIT_LIST_HEAD(&file->triggers);
30053005
list_add(&file->list, &tr->events);
3006-
event_file_get(file);
3006+
refcount_set(&file->ref, 1);
30073007

30083008
return file;
30093009
}

0 commit comments

Comments
 (0)