From f94c21dfd02e98aa0fcb9b453a1198e76ede60e7 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Mon, 17 Apr 2023 22:11:58 -0300 Subject: [PATCH] perf namespaces: Introduce nsinfo__refcnt() accessor to avoid accessing ->refcnt directly To reduces the use of RC_CHK_ACCESS(nsi). Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/namespaces.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c index 214a8391e07c..2f9fb1e2769c 100644 --- a/tools/perf/util/namespaces.c +++ b/tools/perf/util/namespaces.c @@ -204,11 +204,15 @@ struct nsinfo *nsinfo__copy(const struct nsinfo *nsi) return nnsi; } +static refcount_t *nsinfo__refcnt(struct nsinfo *nsi) +{ + return &RC_CHK_ACCESS(nsi)->refcnt; +} + static void nsinfo__delete(struct nsinfo *nsi) { if (nsi) { - WARN_ONCE(refcount_read(&RC_CHK_ACCESS(nsi)->refcnt) != 0, - "nsinfo refcnt unbalanced\n"); + WARN_ONCE(refcount_read(nsinfo__refcnt(nsi)) != 0, "nsinfo refcnt unbalanced\n"); zfree(&RC_CHK_ACCESS(nsi)->mntns_path); RC_CHK_FREE(nsi); } @@ -219,14 +223,14 @@ struct nsinfo *nsinfo__get(struct nsinfo *nsi) struct nsinfo *result; if (RC_CHK_GET(result, nsi)) - refcount_inc(&RC_CHK_ACCESS(nsi)->refcnt); + refcount_inc(nsinfo__refcnt(nsi)); return result; } void nsinfo__put(struct nsinfo *nsi) { - if (nsi && refcount_dec_and_test(&RC_CHK_ACCESS(nsi)->refcnt)) + if (nsi && refcount_dec_and_test(nsinfo__refcnt(nsi))) nsinfo__delete(nsi); else RC_CHK_PUT(nsi);