summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2024-05-15 22:36:08 +0300
committerIngo Molnar <mingo@kernel.org>2024-11-19 11:23:42 +0300
commitf226805bc5f60adf03783d8e4cbfe303ccecd64e (patch)
tree63054f13581f6171d4ccad02d4654e2f17676dce /include/linux
parentb9c44b91476b67327a521568a854babecc4070ab (diff)
downloadlinux-f226805bc5f60adf03783d8e4cbfe303ccecd64e.tar.xz
perf/core: Check sample_type in perf_sample_save_callchain
Check sample_type in perf_sample_save_callchain() to prevent saving callchain data when it isn't required. Suggested-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Yabin Cui <yabinc@google.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20240515193610.2350456-3-yabinc@google.com
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/perf_event.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f7c0a3f2f502..3ac202d971fb 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1279,6 +1279,11 @@ static inline void perf_sample_save_callchain(struct perf_sample_data *data,
{
int size = 1;
+ if (!(event->attr.sample_type & PERF_SAMPLE_CALLCHAIN))
+ return;
+ if (WARN_ON_ONCE(data->sample_flags & PERF_SAMPLE_CALLCHAIN))
+ return;
+
data->callchain = perf_callchain(event, regs);
size += data->callchain->nr;