Add the ref_trace_final_put tracepoint to __refcount_sub_and_test() and refcount_dec_if_one() This tracepoint fires when a refcount_t reaches zero, capturing the caller address, the function name, and the refcount_t address. Signed-off-by: Eugene Mavick --- include/linux/refcount.h | 2 ++ lib/refcount.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/refcount.h b/include/linux/refcount.h index ba7657ced281..70d07a462da1 100644 --- a/include/linux/refcount.h +++ b/include/linux/refcount.h @@ -107,6 +107,7 @@ #include #include #include +#include struct mutex; @@ -393,6 +394,7 @@ bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp) if (old > 0 && old == i) { smp_acquire__after_ctrl_dep(); + do_trace_ref_final_put(r); return true; } diff --git a/lib/refcount.c b/lib/refcount.c index a207a8f22b3c..cd7e32df3919 100644 --- a/lib/refcount.c +++ b/lib/refcount.c @@ -7,6 +7,7 @@ #include #include #include +#include #define REFCOUNT_WARN(str) WARN_ONCE(1, "refcount_t: " str ".\n") @@ -56,7 +57,12 @@ bool refcount_dec_if_one(refcount_t *r) { int val = 1; - return atomic_try_cmpxchg_release(&r->refs, &val, 0); + bool ret = atomic_try_cmpxchg_release(&r->refs, &val, 0); + + if (ret) + do_trace_ref_final_put(r); + + return ret; } EXPORT_SYMBOL(refcount_dec_if_one); -- 2.51.2