mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
96465e0179
The 'struct mem_info' is created by iter_prepare_mem_entry() at the beginning and destroyed by iter_finish_mem_entry() at the end. So if it's used in a new hist_entry, it should be cloned. Simplify (hopefully) the logic by adding some helper functions and by not holding the refcount in the temporary entry. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: https://lore.kernel.org/r/20240731235505.710436-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
49 lines
1.0 KiB
C
49 lines
1.0 KiB
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;
|
|
}
|
|
|
|
struct mem_info *mem_info__clone(struct mem_info *mi)
|
|
{
|
|
struct mem_info *result = mem_info__new();
|
|
|
|
if (result) {
|
|
addr_map_symbol__copy(mem_info__iaddr(result), mem_info__iaddr(mi));
|
|
addr_map_symbol__copy(mem_info__daddr(result), mem_info__daddr(mi));
|
|
mem_info__data_src(result)->val = mem_info__data_src(mi)->val;
|
|
}
|
|
|
|
return result;
|
|
}
|