1 /* 2 * Copyright (c) 2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef __QDF_TRACKER_H 20 #define __QDF_TRACKER_H 21 22 #include "qdf_lock.h" 23 #include "qdf_ptr_hash.h" 24 #include "qdf_status.h" 25 #include "qdf_types.h" 26 27 #define QDF_TRACKER_FUNC_SIZE 48 28 29 /** 30 * struct qdf_tracker - a generic type for tracking resources 31 * @leak_title: the string title to use when logging leaks 32 * @track_title: the string title to use when logging double tracking issues 33 * @untrack_title: the string title to use when logging double untracking issues 34 * @lock: lock for simultaneous access to @ht 35 * @ht: the hashtable used for storing tracking information 36 */ 37 struct qdf_tracker { 38 const char *leak_title; 39 const char *track_title; 40 const char *untrack_title; 41 struct qdf_spinlock lock; 42 struct qdf_ptr_hash *ht; 43 }; 44 45 /** 46 * qdf_tracker_declare() - statically declare a qdf_tacker instance 47 * @name: C identifier to use for the new qdf_tracker 48 * @bits: the number of bits to use for hashing the resource pointers 49 * @leak_title: the string title to use when logging leaks 50 * @track_title: the string title to use when logging double tracking issues 51 * @untrack_title: the string title to use when logging double untracking issues 52 */ 53 #define qdf_tracker_declare(name, bits, _leak_title, \ 54 _track_title, _untrack_title) \ 55 qdf_ptr_hash_declare(name ## _ht, bits); \ 56 struct qdf_tracker name = { \ 57 .leak_title = _leak_title, \ 58 .track_title = _track_title, \ 59 .untrack_title = _untrack_title, \ 60 .ht = qdf_ptr_hash_ptr(name ## _ht), \ 61 } 62 63 /** 64 * qdf_tracker_init() - initialize a qdf_tracker 65 * @tracker: the qdf_tracker to initialize 66 * 67 * Return: None 68 */ 69 void qdf_tracker_init(struct qdf_tracker *tracker); 70 71 /** 72 * qdf_tracker_deinit() - de-initialize a qdf_tracker 73 * @tracker: the qdf_tracker to de-initialize 74 * 75 * Return: None 76 */ 77 void qdf_tracker_deinit(struct qdf_tracker *tracker); 78 79 /** 80 * qdf_tracker_track() - track a resource with @tracker 81 * @tracker: the qdf_tracker to track with 82 * @ptr: an opaque pointer to the resource to track 83 * @func: name of the caller function operating on @ptr 84 * @line: line number of the call site operating on @ptr 85 * 86 * Return: QDF_STATUS 87 */ 88 qdf_must_check QDF_STATUS 89 qdf_tracker_track(struct qdf_tracker *tracker, void *ptr, 90 const char *func, uint32_t line); 91 92 /** 93 * qdf_tracker_untrack() - untrack a resource with @tracker 94 * @tracker: the qdf_tracker used to track @ptr 95 * @ptr: an opaque pointer to the resource to untrack 96 * @func: name of the caller function operating on @ptr 97 * @line: line number of the call site operating on @ptr 98 * 99 * Return: None 100 */ 101 void qdf_tracker_untrack(struct qdf_tracker *tracker, void *ptr, 102 const char *func, uint32_t line); 103 104 /** 105 * qdf_tracker_check_for_leaks() - assert @tracker has no tracked resources 106 * for the current debug domain 107 * @tracker: the qdf_tracker to check 108 * 109 * Return: None 110 */ 111 void qdf_tracker_check_for_leaks(struct qdf_tracker *tracker); 112 113 /** 114 * qdf_tracker_lookup() - query tracking information for @ptr 115 * @tracker: the qdf_tracker to check 116 * @ptr: the opaque pointer of the resource to lookup 117 * @out_func: function name provided when @ptr was tracked, populated on success 118 * @out_line: line number provided when @ptr was tracked, populated on success 119 * 120 * Note: @out_func is assumed to be sizeof(QDF_TRACKER_FUNC_SIZE). 121 * 122 * Return: true if @tracker is tracking @ptr 123 */ 124 qdf_must_check bool 125 qdf_tracker_lookup(struct qdf_tracker *tracker, void *ptr, 126 char (*out_func)[QDF_TRACKER_FUNC_SIZE], 127 uint32_t *out_line); 128 129 #endif /* __QDF_TRACKER_H */ 130 131