mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Samuel Moelius <sam.moelius@trailofbits.com>
Cc: linux-kernel@vger.kernel.org (open list:LIBRARY CODE)
Subject: Re: [PATCH] lib: interval_tree_test: validate benchmark parameters
Date: Tue, 9 Jun 2026 18:13:46 -0700	[thread overview]
Message-ID: <20260609181346.dc7a09e0b23b8bd6847d6454@linux-foundation.org> (raw)
In-Reply-To: <20260609005446.1241288.1525a5964698.interval-tree-test-small-max-endpoint-div0@trailofbits.com>

On Tue,  9 Jun 2026 00:54:47 +0000 Samuel Moelius <sam.moelius@trailofbits.com> wrote:

> 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.

That makes sense, thanks.

> --- a/lib/interval_tree_test.c
> +++ b/lib/interval_tree_test.c
> @@ -311,6 +311,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;

Perhaps this can be done within the __param macro:

#define __param(type, name, init, msg)					\
	static type name = init;					\
	module_param(name, type, 0444);					\
	if (name <= 0) {						\
		pr_warn(__stringify(name) " must be positive\n");	\
		name = init;						\
	}								\
	MODULE_PARM_DESC(name, msg);

I'll add your patch as-is.  If you prefer the above approach, please send
along a replacement patch.


  reply	other threads:[~2026-06-10  1:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09  0:54 Samuel Moelius
2026-06-10  1:13 ` Andrew Morton [this message]
2026-06-10 17:17   ` Samuel Moelius

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=20260609181346.dc7a09e0b23b8bd6847d6454@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam.moelius@trailofbits.com \
    /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

all inboxes | Powered by JetHome®