Files
linux/tools/perf/util/mem-info.c
T
Ian Rogers 1a8c2e0177 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]>
2024-05-07 18:06:44 -03:00

36 lines
712 B
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/zalloc.h>
#include "mem-info.h"
struct mem_info *mem_info__get(struct mem_info *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(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 *result = NULL;
RC_STRUCT(mem_info) *mi = zalloc(sizeof(*mi));
if (ADD_RC_CHK(result, mi))
refcount_set(mem_info__refcnt(result), 1);
return result;
}