qdf_tracker.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #ifndef __QDF_TRACKER_H
  19. #define __QDF_TRACKER_H
  20. #include "qdf_lock.h"
  21. #include "qdf_ptr_hash.h"
  22. #include "qdf_status.h"
  23. #include "qdf_types.h"
  24. #define QDF_TRACKER_FUNC_SIZE 48
  25. /**
  26. * struct qdf_tracker - a generic type for tracking resources
  27. * @leak_title: the string title to use when logging leaks
  28. * @track_title: the string title to use when logging double tracking issues
  29. * @untrack_title: the string title to use when logging double untracking issues
  30. * @lock: lock for simultaneous access to @ht
  31. * @ht: the hashtable used for storing tracking information
  32. */
  33. struct qdf_tracker {
  34. const char *leak_title;
  35. const char *track_title;
  36. const char *untrack_title;
  37. struct qdf_spinlock lock;
  38. struct qdf_ptr_hash *ht;
  39. };
  40. /**
  41. * qdf_tracker_declare() - statically declare a qdf_tacker instance
  42. * @name: C identifier to use for the new qdf_tracker
  43. * @bits: the number of bits to use for hashing the resource pointers
  44. * @leak_title: the string title to use when logging leaks
  45. * @track_title: the string title to use when logging double tracking issues
  46. * @untrack_title: the string title to use when logging double untracking issues
  47. */
  48. #define qdf_tracker_declare(name, bits, _leak_title, \
  49. _track_title, _untrack_title) \
  50. qdf_ptr_hash_declare(name ## _ht, bits); \
  51. struct qdf_tracker name = { \
  52. .leak_title = _leak_title, \
  53. .track_title = _track_title, \
  54. .untrack_title = _untrack_title, \
  55. .ht = qdf_ptr_hash_ptr(name ## _ht), \
  56. }
  57. /**
  58. * qdf_tracker_init() - initialize a qdf_tracker
  59. * @tracker: the qdf_tracker to initialize
  60. *
  61. * Return: None
  62. */
  63. void qdf_tracker_init(struct qdf_tracker *tracker);
  64. /**
  65. * qdf_tracker_deinit() - de-initialize a qdf_tracker
  66. * @tracker: the qdf_tracker to de-initialize
  67. *
  68. * Return: None
  69. */
  70. void qdf_tracker_deinit(struct qdf_tracker *tracker);
  71. /**
  72. * qdf_tracker_track() - track a resource with @tracker
  73. * @tracker: the qdf_tracker to track with
  74. * @ptr: an opaque pointer to the resource to track
  75. * @func: name of the caller function operating on @ptr
  76. * @line: line number of the call site operating on @ptr
  77. *
  78. * Return: QDF_STATUS
  79. */
  80. qdf_must_check QDF_STATUS
  81. qdf_tracker_track(struct qdf_tracker *tracker, void *ptr,
  82. const char *func, uint32_t line);
  83. /**
  84. * qdf_tracker_untrack() - untrack a resource with @tracker
  85. * @tracker: the qdf_tracker used to track @ptr
  86. * @ptr: an opaque pointer to the resource to untrack
  87. * @func: name of the caller function operating on @ptr
  88. * @line: line number of the call site operating on @ptr
  89. *
  90. * Return: None
  91. */
  92. void qdf_tracker_untrack(struct qdf_tracker *tracker, void *ptr,
  93. const char *func, uint32_t line);
  94. /**
  95. * qdf_tracker_check_for_leaks() - assert @tracker has no tracked resources
  96. * for the current debug domain
  97. * @tracker: the qdf_tracker to check
  98. *
  99. * Return: None
  100. */
  101. void qdf_tracker_check_for_leaks(struct qdf_tracker *tracker);
  102. /**
  103. * qdf_tracker_lookup() - query tracking information for @ptr
  104. * @tracker: the qdf_tracker to check
  105. * @ptr: the opaque pointer of the resource to lookup
  106. * @out_func: function name provided when @ptr was tracked, populated on success
  107. * @out_line: line number provided when @ptr was tracked, populated on success
  108. *
  109. * Note: @out_func is assumed to be sizeof(QDF_TRACKER_FUNC_SIZE).
  110. *
  111. * Return: true if @tracker is tracking @ptr
  112. */
  113. qdf_must_check bool
  114. qdf_tracker_lookup(struct qdf_tracker *tracker, void *ptr,
  115. char (*out_func)[QDF_TRACKER_FUNC_SIZE],
  116. uint32_t *out_line);
  117. #endif /* __QDF_TRACKER_H */