From: Markus Elfring <Markus.Elfring@web.de>
To: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
James Clark <james.clark@linaro.org>,
Mike Leach <mike.leach@linaro.org>,
Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Leo Yan <leo.yan@arm.com>,
Tamas Zsoldos <tamas.zsoldos@arm.com>
Subject: [PATCH] coresight: trbe: Use scope-based resource management in arm_trbe_alloc_buffer()
Date: Tue, 9 Sep 2025 14:28:42 +0200 [thread overview]
Message-ID: <3663eb06-6a98-461b-8fcb-6891165d107f@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 9 Sep 2025 14:20:06 +0200
Scope-based resource management became supported for some
programming interfaces by contributions of Peter Zijlstra on 2023-05-26.
See also the commit 54da6a0924311c7cf5015533991e44fb8eb12773 ("locking:
Introduce __cleanup() based infrastructure").
* Thus use the attribute “__free(kfree)”.
* Reduce the scopes for the local variables “buf” and “pglist”.
* Omit four kfree() calls accordingly.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/hwtracing/coresight/coresight-trbe.c | 21 ++++++++------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c
index 8f9bbef71f23..1b0d58bf8613 100644
--- a/drivers/hwtracing/coresight/coresight-trbe.c
+++ b/drivers/hwtracing/coresight/coresight-trbe.c
@@ -733,8 +733,6 @@ static void *arm_trbe_alloc_buffer(struct coresight_device *csdev,
struct perf_event *event, void **pages,
int nr_pages, bool snapshot)
{
- struct trbe_buf *buf;
- struct page **pglist;
int i;
/*
@@ -746,32 +744,29 @@ static void *arm_trbe_alloc_buffer(struct coresight_device *csdev,
if (nr_pages < 2)
return NULL;
- buf = kzalloc_node(sizeof(*buf), GFP_KERNEL, trbe_alloc_node(event));
+ struct trbe_buf *buf __free(kfree) = kzalloc_node(sizeof(*buf),
+ GFP_KERNEL,
+ trbe_alloc_node(event));
if (!buf)
return NULL;
- pglist = kcalloc(nr_pages, sizeof(*pglist), GFP_KERNEL);
- if (!pglist) {
- kfree(buf);
+ struct page **pglist __free(kfree) = kcalloc(nr_pages, sizeof(*pglist), GFP_KERNEL);
+ if (!pglist)
return NULL;
- }
for (i = 0; i < nr_pages; i++)
pglist[i] = virt_to_page(pages[i]);
buf->trbe_base = (unsigned long)vmap(pglist, nr_pages, VM_MAP, PAGE_KERNEL);
- if (!buf->trbe_base) {
- kfree(pglist);
- kfree(buf);
+ if (!buf->trbe_base)
return NULL;
- }
+
buf->trbe_limit = buf->trbe_base + nr_pages * PAGE_SIZE;
buf->trbe_write = buf->trbe_base;
buf->snapshot = snapshot;
buf->nr_pages = nr_pages;
buf->pages = pages;
- kfree(pglist);
- return buf;
+ return_ptr(buf);
}
static void arm_trbe_free_buffer(void *config)
--
2.51.0
next reply other threads:[~2025-09-09 12:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 12:28 Markus Elfring [this message]
2025-09-12 4:25 ` Anshuman Khandual
2025-09-12 6:00 ` Markus Elfring
2025-09-12 10:27 ` Leo Yan
2025-09-12 12:37 ` Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3663eb06-6a98-461b-8fcb-6891165d107f@web.de \
--to=markus.elfring@web.de \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=james.clark@linaro.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.leach@linaro.org \
--cc=suzuki.poulose@arm.com \
--cc=tamas.zsoldos@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®