diff options
| author | Ian Rogers <[email protected]> | 2024-05-07 18:35:44 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2024-05-07 21:06:44 +0000 |
| commit | 1a8c2e0177df250093b482b0c0034b53fdc5409f (patch) | |
| tree | f5e622e705588a39e1c06bbd4172bfa1ddf7db56 /tools/perf/util/mem-info.c | |
| parent | perf mem-info: Move mem-info out of mem-events and symbol (diff) | |
| download | kernel-1a8c2e0177df250093b482b0c0034b53fdc5409f.tar.gz kernel-1a8c2e0177df250093b482b0c0034b53fdc5409f.zip | |
perf mem-info: Add reference count checking
Add reference count checking and switch 'struct mem_info' usage to use
accessor functions.
Signed-off-by: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Athira Rajeev <[email protected]>
Cc: Ben Gainey <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: James Clark <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: K Prateek Nayak <[email protected]>
Cc: Kajol Jain <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Li Dong <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Paran Lee <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ravi Bangoria <[email protected]>
Cc: Sun Haiyong <[email protected]>
Cc: Tim Chen <[email protected]>
Cc: Yanteng Si <[email protected]>
Cc: Yicong Yang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/perf/util/mem-info.c')
| -rw-r--r-- | tools/perf/util/mem-info.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/tools/perf/util/mem-info.c b/tools/perf/util/mem-info.c index ff0dfdb5369a..27d67721a695 100644 --- a/tools/perf/util/mem-info.c +++ b/tools/perf/util/mem-info.c @@ -4,25 +4,32 @@ struct mem_info *mem_info__get(struct mem_info *mi) { - if (mi) - refcount_inc(&mi->refcnt); - return mi; + struct mem_info *result; + + if (RC_CHK_GET(result, mi)) + refcount_inc(mem_info__refcnt(mi)); + + return result; } void mem_info__put(struct mem_info *mi) { - if (mi && refcount_dec_and_test(&mi->refcnt)) { - addr_map_symbol__exit(&mi->iaddr); - addr_map_symbol__exit(&mi->daddr); - free(mi); + if (mi && refcount_dec_and_test(mem_info__refcnt(mi))) { + addr_map_symbol__exit(mem_info__iaddr(mi)); + addr_map_symbol__exit(mem_info__daddr(mi)); + RC_CHK_FREE(mi); + } else { + RC_CHK_PUT(mi); } } struct mem_info *mem_info__new(void) { - struct mem_info *mi = zalloc(sizeof(*mi)); + struct mem_info *result = NULL; + RC_STRUCT(mem_info) *mi = zalloc(sizeof(*mi)); + + if (ADD_RC_CHK(result, mi)) + refcount_set(mem_info__refcnt(result), 1); - if (mi) - refcount_set(&mi->refcnt, 1); - return mi; + return result; } |
