Thread (4 messages) 4 messages, 2 authors, 14d ago
COOLING14d

[PATCH] samples/ftrace: reject zero ftrace-ops call count

From: Samuel Moelius <hidden>
Date: 2026-06-09 00:44:53
Also in: lkml
Subsystem: the rest · Maintainer: Linus Torvalds

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.

Reject a zero call count before registering any ftrace ops.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <redacted>
---
 samples/ftrace/ftrace-ops.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/samples/ftrace/ftrace-ops.c b/samples/ftrace/ftrace-ops.c
index 68d6685c80bd..d5adaa61484f 100644
--- a/samples/ftrace/ftrace-ops.c
+++ b/samples/ftrace/ftrace-ops.c
@@ -190,6 +190,11 @@ static int __init ftrace_ops_sample_init(void)
 		tracer_irrelevant = ops_func_count;
 	}
 
+	if (!nr_function_calls) {
+		pr_err("nr_function_calls must be non-zero\n");
+		return -EINVAL;
+	}
+
 	pr_info("registering:\n"
 		"  relevant ops: %u\n"
 		"    tracee: %ps\n"
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help