summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYichong Chen <chenyichong@uniontech.com>2026-06-29 09:43:14 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-07-05 16:23:12 -0700
commit9c863994576677c8a32ca09d4a3bb25a918d6d86 (patch)
treed09d60e90ffe3635ade49c90f2a3caaee6430391
parentf435e5acc3ed67e8ed4187bd479e6fd1983ac823 (diff)
downloadlinux-next-9c863994576677c8a32ca09d4a3bb25a918d6d86.tar.gz
linux-next-9c863994576677c8a32ca09d4a3bb25a918d6d86.zip
tools/mm/page_owner_sort: return explicit filter results
Patch series "tools/mm/page_owner_sort: fix filtering and cleanup issues", v5. Patch 1 renames is_need() to filter_record() and makes the filter path return explicit results. Patch 2 fixes the per-record allocation leaks. Patch 3 bounds search_pattern() output copies, addressing the pre-existing issue reported by Sashiko/AI review. This patch (of 3): Rename is_need() to filter_record() and make the filter path return explicit error, skip, and match results. This lets callers distinguish allocation failures from records that simply do not match active filters. Link: https://lore.kernel.org/20260629014316.130307-1-chenyichong@uniontech.com Link: https://lore.kernel.org/20260629014316.130307-2-chenyichong@uniontech.com Signed-off-by: Yichong Chen <chenyichong@uniontech.com> Reviewed-by: Vishal Moola <vishal.moola@gmail.com> Cc: Ye Liu <ye.liu@linux.dev> Cc: Zhen Ni <zhen.ni@easystack.cn> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r--tools/mm/page_owner_sort.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c
index e6954909401c..3c754826cec5 100644
--- a/tools/mm/page_owner_sort.c
+++ b/tools/mm/page_owner_sort.c
@@ -43,6 +43,13 @@ enum FILTER_BIT {
FILTER_TGID = 1<<2,
FILTER_COMM = 1<<3
};
+
+enum FILTER_RESULT {
+ FILTER_ERROR,
+ FILTER_SKIP,
+ FILTER_MATCH
+};
+
enum CULL_BIT {
CULL_PID = 1<<1,
CULL_TGID = 1<<2,
@@ -372,6 +379,9 @@ static char *get_comm(char *buf)
{
char *comm_str = malloc(TASK_COMM_LEN);
+ if (!comm_str)
+ return NULL;
+
memset(comm_str, 0, TASK_COMM_LEN);
search_pattern(&comm_pattern, comm_str, buf);
@@ -450,32 +460,44 @@ static bool match_str_list(const char *str, char **list, int list_size)
return false;
}
-static bool is_need(char *buf)
+static enum FILTER_RESULT filter_record(char *buf)
{
+ char *comm;
+
if ((filter & FILTER_PID) && !match_num_list(get_pid(buf), fc.pids, fc.pids_size))
- return false;
+ return FILTER_SKIP;
if ((filter & FILTER_TGID) &&
!match_num_list(get_tgid(buf), fc.tgids, fc.tgids_size))
- return false;
+ return FILTER_SKIP;
+ if (!(filter & FILTER_COMM))
+ return FILTER_MATCH;
- char *comm = get_comm(buf);
+ comm = get_comm(buf);
+ if (!comm)
+ return FILTER_ERROR;
- if ((filter & FILTER_COMM) &&
- !match_str_list(comm, fc.comms, fc.comms_size)) {
+ if (!match_str_list(comm, fc.comms, fc.comms_size)) {
free(comm);
- return false;
+ return FILTER_SKIP;
}
free(comm);
- return true;
+ return FILTER_MATCH;
}
static bool add_list(char *buf, int len, char *ext_buf)
{
+ enum FILTER_RESULT filter_result;
+
if (list_size == max_size) {
fprintf(stderr, "max_size too small??\n");
return false;
}
- if (!is_need(buf))
+ filter_result = filter_record(buf);
+ if (filter_result == FILTER_ERROR) {
+ fprintf(stderr, "Out of memory\n");
+ return false;
+ }
+ if (filter_result == FILTER_SKIP)
return true;
list[list_size].pid = get_pid(buf);
list[list_size].tgid = get_tgid(buf);