Add reference count checking and switch 'struct mem_info' usage to use accessor functions. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ben Gainey <ben.gainey@arm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Li Dong <lidong@vivo.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Paran Lee <p4ranlee@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sun Haiyong <sunhaiyong@loongson.cn> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Yanteng Si <siyanteng@loongson.cn> Cc: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20240507183545.1236093-8-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
35 lines
712 B
C
35 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;
|
|
}
|