1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef _LINUX_REF_TRACKER_H
3 #define _LINUX_REF_TRACKER_H
4 #include <linux/refcount.h>
5 #include <linux/types.h>
6 #include <linux/spinlock.h>
7 #include <linux/stackdepot.h>
11 struct ref_tracker_dir {
12 #ifdef CONFIG_REF_TRACKER
14 unsigned int quarantine_avail;
16 refcount_t no_tracker;
18 struct list_head list; /* List of active trackers */
19 struct list_head quarantine; /* List of dead trackers */
24 #ifdef CONFIG_REF_TRACKER
26 static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
27 unsigned int quarantine_count,
30 INIT_LIST_HEAD(&dir->list);
31 INIT_LIST_HEAD(&dir->quarantine);
32 spin_lock_init(&dir->lock);
33 dir->quarantine_avail = quarantine_count;
35 refcount_set(&dir->untracked, 1);
36 refcount_set(&dir->no_tracker, 1);
37 strscpy(dir->name, name, sizeof(dir->name));
41 void ref_tracker_dir_exit(struct ref_tracker_dir *dir);
43 void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
44 unsigned int display_limit);
46 void ref_tracker_dir_print(struct ref_tracker_dir *dir,
47 unsigned int display_limit);
49 int ref_tracker_dir_snprint(struct ref_tracker_dir *dir, char *buf, size_t size);
51 int ref_tracker_alloc(struct ref_tracker_dir *dir,
52 struct ref_tracker **trackerp, gfp_t gfp);
54 int ref_tracker_free(struct ref_tracker_dir *dir,
55 struct ref_tracker **trackerp);
57 #else /* CONFIG_REF_TRACKER */
59 static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
60 unsigned int quarantine_count,
65 static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
69 static inline void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
70 unsigned int display_limit)
74 static inline void ref_tracker_dir_print(struct ref_tracker_dir *dir,
75 unsigned int display_limit)
79 static inline int ref_tracker_dir_snprint(struct ref_tracker_dir *dir,
80 char *buf, size_t size)
85 static inline int ref_tracker_alloc(struct ref_tracker_dir *dir,
86 struct ref_tracker **trackerp,
92 static inline int ref_tracker_free(struct ref_tracker_dir *dir,
93 struct ref_tracker **trackerp)
100 #endif /* _LINUX_REF_TRACKER_H */