linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kan.liang@linux.intel.com
To: acme@kernel.org, namhyung@kernel.org
Cc: irogers@google.com, jolsa@kernel.org, adrian.hunter@intel.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kan Liang <kan.liang@linux.intel.com>
Subject: [PATCH 3/3] perf mem: Fix the wrong reference in parse_record_events
Date: Thu,  5 Sep 2024 10:07:37 -0700	[thread overview]
Message-ID: <20240905170737.4070743-3-kan.liang@linux.intel.com> (raw)
In-Reply-To: <20240905170737.4070743-1-kan.liang@linux.intel.com>

From: Kan Liang <kan.liang@linux.intel.com>

A segmentation fault can be triggered when running
perf mem record -e ldlat-loads

The commit 35b38a71c92f ("perf mem: Rework command option handling")
moves the OPT_CALLBACK of event from __cmd_record() to cmd_mem().
When invoking the __cmd_record(), the 'mem' has been referenced (&).
So the &mem passed into the parse_record_events() is a double
reference (&&) of the original struct perf_mem mem.
But in the cmd_mem(), the &mem is the single reference (&) of the
original struct perf_mem mem.

Fixes: 35b38a71c92f ("perf mem: Rework command option handling")
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---
 tools/perf/builtin-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index ba1d37bfb916..2b28e356f963 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -47,7 +47,7 @@ struct perf_mem {
 static int parse_record_events(const struct option *opt,
 			       const char *str, int unset __maybe_unused)
 {
-	struct perf_mem *mem = *(struct perf_mem **)opt->value;
+	struct perf_mem *mem = (struct perf_mem *)opt->value;
 	struct perf_pmu *pmu;
 
 	pmu = perf_mem_events_find_pmu();
-- 
2.38.1


      parent reply	other threads:[~2024-09-05 17:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-05 17:07 [PATCH 1/3] perf mem: Check mem_events for all eligible PMUs kan.liang
2024-09-05 17:07 ` [PATCH 2/3] perf mem: Fix missed p-core mem events on ADL and RPL kan.liang
2024-09-05 19:33   ` Arnaldo Carvalho de Melo
2024-09-05 19:47     ` Liang, Kan
2024-09-06 14:17       ` Arnaldo Carvalho de Melo
2024-09-06 16:08         ` Liang, Kan
2024-09-06 20:06           ` Arnaldo Carvalho de Melo
2024-09-08 20:30             ` Liang, Kan
2024-09-11 15:56               ` Arnaldo Carvalho de Melo
2024-09-05 17:07 ` kan.liang [this message]

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=20240905170737.4070743-3-kan.liang@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).