Rust for Linux List
 help / color / mirror / Atom feed
From: Sang-Heon Jeon <ekffu200098@gmail.com>
To: a.hindborg@kernel.org, boqun@kernel.org,
	fujita.tomonori@gmail.com, frederic@kernel.org, lyude@redhat.com,
	tglx@kernel.org, anna-maria@linutronix.de, jstultz@google.com,
	sboyd@kernel.org
Cc: rust-for-linux@vger.kernel.org, Sang-Heon Jeon <ekffu200098@gmail.com>
Subject: [PATCH] rust: time: add debug assertions for out-of-range input in fsleep()
Date: Sat,  9 May 2026 02:38:27 +0900	[thread overview]
Message-ID: <20260508173827.1123011-1-ekffu200098@gmail.com> (raw)

fsleep() documents out-of-range input as a bug but does not check
it, unlike udelay(). Add `debug_assert!` calls to catch it in
debug builds.

Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
Hello,

I found this small inconsistency while reading the code. The same
check was applied to udelay() [1] but does not seem to have been
extended to fsleep(). Please let me know if I have misunderstood
anything.

[1] https://lore.kernel.org/all/20251103112958.2961517-2-fujita.tomonori@gmail.com

Best Regards,
Sang-Heon Jeon
---
 rust/kernel/time/delay.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rust/kernel/time/delay.rs b/rust/kernel/time/delay.rs
index b5b1b42797a0..1e699fe647ff 100644
--- a/rust/kernel/time/delay.rs
+++ b/rust/kernel/time/delay.rs
@@ -32,6 +32,9 @@ pub fn fsleep(delta: Delta) {
     // overflow inside fsleep, which could lead to unintentional infinite sleep.
     const MAX_DELTA: Delta = Delta::from_micros(i32::MAX as i64);
 
+    debug_assert!(delta.as_nanos() >= 0);
+    debug_assert!(delta <= MAX_DELTA);
+
     let delta = if (Delta::ZERO..=MAX_DELTA).contains(&delta) {
         delta
     } else {
-- 
2.43.0


             reply	other threads:[~2026-05-08 17:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <qBPUAToMpl5CvVd22lUrJOgsVSuqVYKsjEHpbs1UK-VTO-vN8UFOa35fFMsYOHoBuUp9HcP65ljAxmLQMcGS9w==@protonmail.internalid>
2026-05-08 17:38 ` Sang-Heon Jeon [this message]
2026-05-09  6:41   ` [PATCH] rust: time: add debug assertions for out-of-range input in fsleep() Onur Özkan
2026-05-09  8:08   ` Andreas Hindborg
2026-05-09 12:10     ` Gary Guo
2026-05-09 14:36       ` Andreas Hindborg
2026-05-09 14:50         ` Gary Guo
2026-05-09 17:44           ` Andreas Hindborg

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=20260508173827.1123011-1-ekffu200098@gmail.com \
    --to=ekffu200098@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=boqun@kernel.org \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=jstultz@google.com \
    --cc=lyude@redhat.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@kernel.org \
    /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