From nobody Mon Apr 6 09:11:39 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 514A033F5BC for ; Sat, 4 Apr 2026 03:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775274260; cv=none; b=AEEnMq1jUmexiEcQKWpYisMTwVoZyp+KaSn1+yyMcjsorqoKJyfVMVDwTqDfw3iV8tYKo26b2r6TmD38epd3jw7HEbaNHd+MXenHv6Jmy7fpT75qti6QYv6ObUdUacnaPQf2LnRpM6s31Ey/cjxCPSmuY5CefaeizYhe0/guKEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775274260; c=relaxed/simple; bh=lta2fI5qXdYPdhIfm8zOThe6wXUgcAlnODSeXuma/Io=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Tbp01NPEdGsUcMRlU1+yF/I5KmK1954bSZCo6pNYhM+F6fsEKpwsYA+6anVdmF00/g7532y5ZbRKktStcEdJi0rHuduTg/uLTKQpMM8Ib6qMyfQd61S4FxcCf36yjXwu/2F6Gs3E9FCfsa3shwoXd4d9YQ7H6GI+IyUBpFa1rkI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=K1WlAbkD; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K1WlAbkD" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2cc9118dc2eso4313418eec.0 for ; Fri, 03 Apr 2026 20:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775274257; x=1775879057; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KaYE6VTNH1rn50K/H2pN6vOvFrscNqJ0UK5rxmsiNw8=; b=K1WlAbkDko0AElH+mECAW1aZ1b8V/hAehrTlN8X9GtHZABswY3gQf8xjh4lBYuXieC YD4w3G+591vQz5HkD95j9w6QiYFjXomz694eioXORMhI/ecg9GxvbzPSTfNRMUMswDH3 c4zCBtmjFxqSEDR+xMvux6AFKYYxNMwunsOYB6+mhGDJ5VsVzRDWl5k6TQVOuF9WcfY9 8PUzZ9tKtlEdXs7Nx+FxqPWUN4o6ajPqSuZw8f40nMQ9Z+J/g5/YViiI7eZyNl9bcvvh +oe+MH5inKQHBOJsahKjBaJ6K15WbFJ3COu/5bhaNFEPDvvg+qfIWfR4lU3fsy+JcVz6 ZQvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775274257; x=1775879057; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KaYE6VTNH1rn50K/H2pN6vOvFrscNqJ0UK5rxmsiNw8=; b=giujR6ushEUC5fbD2Vpbu6tsqcu7oPwFVJFT3worwyPFrE5oK1CJBnQKyq1lriDHy+ 4Wjx5vDtBtr+k62IGUP84Zgy5/A7zdko5u7y68UilWM4N+TOFtA+Urbb4zHdeUlc2i2J 5Q2hycZJnLwAiWa/H/tTmP4Fq3iVH8aQO/ThdsoQucIa5Mv2jiA+Q1WKGgH7HpAfZ41W VRmuMh87U6O2EIFkIT4sxZU2+0zqCb42Q9vonycMDO33ubOxSidw+Mi4IOmjjs+CaCfX O1vBesg5zX4jKoPl/RTZKvU6OAKsRd4DPEYCtW3OhklRSpq+VPhNtXJZw3RYYJFhWBq7 aakQ== X-Forwarded-Encrypted: i=1; AJvYcCUpPkkwcNy1Mpij/aR/KGNyoLqvlKQm7aJxBCzqriGcAzvkyBnTgyOX4KW8w0JYFuOzXL2XXQlwlG96YxU=@vger.kernel.org X-Gm-Message-State: AOJu0YwWq8CVx5UgqoM8Uin0mNpPB5fhuf2cbPs2hMQhn9L/38aTrxj9 zJSqJQ/l+nRztLv/Iy5NS53rvQLFnw8wZMWL7TT6c4PIoSwhKvTLyj2hHIzymLqOE2B+o9Us2jj kO5L1lOCgfA== X-Received: from dlbvs3.prod.google.com ([2002:a05:7022:3f03:b0:12a:7a40:ea24]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:61f:b0:12b:ec67:3523 with SMTP id a92af1059eb24-12bfb6fa2f7mr2715555c88.9.1775274257068; Fri, 03 Apr 2026 20:44:17 -0700 (PDT) Date: Fri, 3 Apr 2026 20:43:17 -0700 In-Reply-To: <20260404034325.3172592-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260403204017.2919994-1-irogers@google.com> <20260404034325.3172592-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260404034325.3172592-18-irogers@google.com> Subject: [PATCH v6 17/25] perf kmem: Don't pass evsel with sample From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sample contains the evsel and so it is unnecessary to pass the evsel as well. Fix memory leaks on error paths spotted during code review. Signed-off-by: Ian Rogers --- tools/perf/builtin-kmem.c | 44 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index b04f5d578e7a..cafa0eabfbc5 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -171,7 +171,7 @@ static int insert_caller_stat(unsigned long call_site, return 0; } =20 -static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sam= ple *sample) +static int evsel__process_alloc_event(struct perf_sample *sample) { unsigned long ptr =3D perf_sample__intval(sample, "ptr"), call_site =3D perf_sample__intval(sample, "call_site"); @@ -198,7 +198,7 @@ static int evsel__process_alloc_event(struct evsel *evs= el, struct perf_sample *s * If the tracepoint contains the field "node" the tool stats the * cross allocation. */ - if (evsel__field(evsel, "node")) { + if (evsel__field(sample->evsel, "node")) { int node1, node2; =20 node1 =3D cpu__get_node((struct perf_cpu){.cpu =3D sample->cpu}); @@ -243,7 +243,7 @@ static struct alloc_stat *search_alloc_stat(unsigned lo= ng ptr, return NULL; } =20 -static int evsel__process_free_event(struct evsel *evsel __maybe_unused, s= truct perf_sample *sample) +static int evsel__process_free_event(struct perf_sample *sample) { unsigned long ptr =3D perf_sample__intval(sample, "ptr"); struct alloc_stat *s_alloc, *s_caller; @@ -751,8 +751,7 @@ static char *compact_gfp_string(unsigned long gfp_flags) return NULL; } =20 -static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample, - unsigned int gfp_flags) +static int parse_gfp_flags(struct perf_sample *sample, unsigned int gfp_fl= ags) { struct tep_record record =3D { .cpu =3D sample->cpu, @@ -773,7 +772,7 @@ static int parse_gfp_flags(struct evsel *evsel, struct = perf_sample *sample, } =20 trace_seq_init(&seq); - tp_format =3D evsel__tp_format(evsel); + tp_format =3D evsel__tp_format(sample->evsel); if (tp_format) tep_print_event(tp_format->tep, &seq, &record, "%s", TEP_PRINT_INFO); =20 @@ -784,17 +783,21 @@ static int parse_gfp_flags(struct evsel *evsel, struc= t perf_sample *sample, =20 new =3D realloc(gfps, (nr_gfps + 1) * sizeof(*gfps)); if (new =3D=3D NULL) - return -ENOMEM; + goto err_out; =20 gfps =3D new; - new +=3D nr_gfps++; + new +=3D nr_gfps; =20 new->flags =3D gfp_flags; new->human_readable =3D strdup(str + 10); + if(!new->human_readable) + goto err_out; new->compact_str =3D compact_gfp_flags(str + 10); - if (!new->human_readable || !new->compact_str) - return -ENOMEM; - + if (!new->compact_str) { + free(new->human_readable); + goto err_out; + } + nr_gfps++; qsort(gfps, nr_gfps, sizeof(*gfps), gfpcmp); } =20 @@ -803,9 +806,12 @@ static int parse_gfp_flags(struct evsel *evsel, struct= perf_sample *sample, =20 trace_seq_destroy(&seq); return 0; +err_out: + trace_seq_destroy(&seq); + return -ENOMEM; } =20 -static int evsel__process_page_alloc_event(struct evsel *evsel, struct per= f_sample *sample) +static int evsel__process_page_alloc_event(struct perf_sample *sample) { u64 page; unsigned int order =3D perf_sample__intval(sample, "order"); @@ -845,7 +851,7 @@ static int evsel__process_page_alloc_event(struct evsel= *evsel, struct perf_samp return 0; } =20 - if (parse_gfp_flags(evsel, sample, gfp_flags) < 0) + if (parse_gfp_flags(sample, gfp_flags) < 0) return -1; =20 callsite =3D find_callsite(sample); @@ -886,8 +892,7 @@ static int evsel__process_page_alloc_event(struct evsel= *evsel, struct perf_samp return 0; } =20 -static int evsel__process_page_free_event(struct evsel *evsel __maybe_unus= ed, - struct perf_sample *sample) +static int evsel__process_page_free_event(struct perf_sample *sample) { u64 page; unsigned int order =3D perf_sample__intval(sample, "order"); @@ -969,8 +974,7 @@ static bool perf_kmem__skip_sample(struct perf_sample *= sample) return false; } =20 -typedef int (*tracepoint_handler)(struct evsel *evsel, - struct perf_sample *sample); +typedef int (*tracepoint_handler)(struct perf_sample *sample); =20 static int process_sample_event(const struct perf_tool *tool __maybe_unuse= d, union perf_event *event, @@ -988,14 +992,16 @@ static int process_sample_event(const struct perf_too= l *tool __maybe_unused, return -1; } =20 - if (perf_kmem__skip_sample(sample)) + if (perf_kmem__skip_sample(sample)) { + thread__put(thread); return 0; + } =20 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread__tid= (thread)); =20 if (evsel->handler !=3D NULL) { tracepoint_handler f =3D evsel->handler; - err =3D f(evsel, sample); + err =3D f(sample); } =20 thread__put(thread); --=20 2.53.0.1213.gd9a14994de-goog