summaryrefslogtreecommitdiff
path: root/rust/kernel/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel/time.rs')
-rw-r--r--rust/kernel/time.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index 64c8dcf548d6..874a1023dcdf 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -200,6 +200,29 @@ impl<C: ClockSource> Instant<C> {
pub(crate) fn as_nanos(&self) -> i64 {
self.inner
}
+
+ /// Create an [`Instant`] from a `ktime_t` without checking if it is non-negative.
+ ///
+ /// # Panics
+ ///
+ /// On debug builds, this function will panic if `ktime` is not in the range from 0 to
+ /// `KTIME_MAX`.
+ ///
+ /// # Safety
+ ///
+ /// The caller promises that `ktime` is in the range from 0 to `KTIME_MAX`.
+ #[expect(unused)]
+ #[inline]
+ pub(crate) unsafe fn from_ktime(ktime: bindings::ktime_t) -> Self {
+ debug_assert!(ktime >= 0);
+
+ // INVARIANT: Our safety contract ensures that `ktime` is in the range from 0 to
+ // `KTIME_MAX`.
+ Self {
+ inner: ktime,
+ _c: PhantomData,
+ }
+ }
}
impl<C: ClockSource> core::ops::Sub for Instant<C> {