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> 8 9 struct ref_tracker; 10 11 struct ref_tracker_dir { 12 #ifdef CONFIG_REF_TRACKER 13 spinlock_t lock; 14 unsigned int quarantine_avail; 15 refcount_t untracked; 16 bool dead; 17 struct list_head list; /* List of active trackers */ 18 struct list_head quarantine; /* List of dead trackers */ 19 #endif 20 }; 21 22 #ifdef CONFIG_REF_TRACKER 23 static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir, 24 unsigned int quarantine_count) 25 { 26 INIT_LIST_HEAD(&dir->list); 27 INIT_LIST_HEAD(&dir->quarantine); 28 spin_lock_init(&dir->lock); 29 dir->quarantine_avail = quarantine_count; 30 dir->dead = false; 31 refcount_set(&dir->untracked, 1); 32 stack_depot_init(); 33 } 34 35 void ref_tracker_dir_exit(struct ref_tracker_dir *dir); 36 37 void ref_tracker_dir_print(struct ref_tracker_dir *dir, 38 unsigned int display_limit); 39 40 int ref_tracker_alloc(struct ref_tracker_dir *dir, 41 struct ref_tracker **trackerp, gfp_t gfp); 42 43 int ref_tracker_free(struct ref_tracker_dir *dir, 44 struct ref_tracker **trackerp); 45 46 #else /* CONFIG_REF_TRACKER */ 47 48 static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir, 49 unsigned int quarantine_count) 50 { 51 } 52 53 static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir) 54 { 55 } 56 57 static inline void ref_tracker_dir_print(struct ref_tracker_dir *dir, 58 unsigned int display_limit) 59 { 60 } 61 62 static inline int ref_tracker_alloc(struct ref_tracker_dir *dir, 63 struct ref_tracker **trackerp, 64 gfp_t gfp) 65 { 66 return 0; 67 } 68 69 static inline int ref_tracker_free(struct ref_tracker_dir *dir, 70 struct ref_tracker **trackerp) 71 { 72 return 0; 73 } 74 75 #endif 76 77 #endif /* _LINUX_REF_TRACKER_H */ 78