[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e540d2cd-2c47-4057-9000-8d403247abf6@lunn.ch>
Date: Sat, 5 Oct 2024 20:07:31 +0200
From: Andrew Lunn <andrew@...n.ch>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: netdev@...r.kernel.org, rust-for-linux@...r.kernel.org,
hkallweit1@...il.com, tmgross@...ch.edu, ojeda@...nel.org,
alex.gaynor@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me, a.hindborg@...sung.com,
aliceryhl@...gle.com, anna-maria@...utronix.de, frederic@...nel.org,
tglx@...utronix.de, arnd@...db.de, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v2 3/6] rust: time: Implement addition of Ktime
and Delta
On Sat, Oct 05, 2024 at 09:25:28PM +0900, FUJITA Tomonori wrote:
> Implement Add<Delta> for Ktime to support the operation:
>
> Ktime = Ktime + Delta
>
> This is used to calculate the future time when the timeout will occur.
Since Delta can be negative, it could also be a passed time. For a
timeout, that does not make much sense.
> +impl core::ops::Add<Delta> for Ktime {
> + type Output = Ktime;
> +
> + #[inline]
> + fn add(self, delta: Delta) -> Ktime {
> + // SAFETY: FFI call.
> + let t = unsafe { bindings::ktime_add_ns(self.inner, delta.as_nanos() as u64) };
So you are throwing away the sign bit. What does Rust in the kernel do
if it was a negative delta?
I think the types being used here need more consideration.
Andrew
Powered by blists - more mailing lists