summaryrefslogtreecommitdiff
path: root/samples/ftrace
diff options
context:
space:
mode:
authorSamuel Moelius <sam.moelius@trailofbits.com>2026-06-29 15:26:17 +0000
committerSteven Rostedt <rostedt@goodmis.org>2026-07-28 07:18:50 -0400
commitac00ffdbbc832f4c8ad5312217360d542f7e6690 (patch)
tree5ecca310b72c28b405054543b02cec94782b6df1 /samples/ftrace
parent693dc27c5286cb0fd0d8cf18c3ee924b22154e92 (diff)
downloadlwn-ac00ffdbbc832f4c8ad5312217360d542f7e6690.tar.gz
lwn-ac00ffdbbc832f4c8ad5312217360d542f7e6690.zip
samples/ftrace: Prevent division by zero when nr_function_calls is zero
The ftrace-ops sample exposes nr_function_calls as a module parameter and uses it as the divisor when printing the measured time per call. Loading the module with nr_function_calls=0 skips the benchmark loop and then divides the elapsed time by zero, crashing the kernel during sample module initialization. Keep accepting the parameter value, but report -1LL as the per-call duration when the call count is zero instead of dividing by it. Link: https://patch.msgid.link/20260629152616.107080.e19bfbed249c.ftrace-ops-zero-function-calls-div0@trailofbits.com Assisted-by: Codex:gpt-5.5-cyber-preview Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'samples/ftrace')
-rw-r--r--samples/ftrace/ftrace-ops.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/samples/ftrace/ftrace-ops.c b/samples/ftrace/ftrace-ops.c
index 152ffc1a30b6..8cae38d8b879 100644
--- a/samples/ftrace/ftrace-ops.c
+++ b/samples/ftrace/ftrace-ops.c
@@ -223,7 +223,7 @@ static int __init ftrace_ops_sample_init(void)
pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n",
nr_function_calls, tracee_relevant,
- period, div_u64(period, nr_function_calls));
+ period, nr_function_calls ? div_u64(period, nr_function_calls) : -1LL);
if (persist)
return 0;