diff options
| author | Samuel Moelius <sam.moelius@trailofbits.com> | 2026-06-09 00:54:47 +0000 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-06-17 15:37:47 -0700 |
| commit | c1fff9794a165b6b64ae4ad9b54c00bc94e7daed (patch) | |
| tree | 073fe150d654abb3405209cefe8e25c2ef78d64f /lib | |
| parent | 22920541c35a9f23f219038ba5874c843a7c4419 (diff) | |
| download | linux-c1fff9794a165b6b64ae4ad9b54c00bc94e7daed.tar.gz linux-c1fff9794a165b6b64ae4ad9b54c00bc94e7daed.zip | |
lib: interval_tree_test: validate benchmark parameters
The interval tree runtime test accepts module parameters that are later
used as divisors while generating randomized intervals and while reporting
average timings. For example, max_endpoint=1 makes the generated interval
end value zero and the next modulo operation divides by that zero value.
Reject non-positive counts and require max_endpoint to provide at least
one non-zero generated endpoint before the test allocates state or starts
the benchmark.
[akpm@linux-foundation.org: include printk.h for pr_warn()]
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
Link: https://lore.kernel.org/20260609005446.1241288.1525a5964698.interval-tree-test-small-max-endpoint-div0@trailofbits.com
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/interval_tree_test.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c index 16200feacbf3..eba2d3e28980 100644 --- a/lib/interval_tree_test.c +++ b/lib/interval_tree_test.c @@ -4,6 +4,7 @@ #include <linux/interval_tree.h> #include <linux/prandom.h> #include <linux/slab.h> +#include <linux/printk.h> #include <asm/timex.h> #include <linux/bitmap.h> #include <linux/maple_tree.h> @@ -311,6 +312,27 @@ static inline int span_iteration_check(void) {return 0; } static int interval_tree_test_init(void) { + if (nnodes <= 0) { + pr_warn("nnodes must be positive\n"); + return -EINVAL; + } + if (nsearches <= 0) { + pr_warn("nsearches must be positive\n"); + return -EINVAL; + } + if (perf_loops <= 0) { + pr_warn("perf_loops must be positive\n"); + return -EINVAL; + } + if (search_loops <= 0) { + pr_warn("search_loops must be positive\n"); + return -EINVAL; + } + if (max_endpoint < 2) { + pr_warn("max_endpoint must be at least 2\n"); + return -EINVAL; + } + nodes = kmalloc_objs(struct interval_tree_node, nnodes); if (!nodes) return -ENOMEM; |
