[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241017.183141.1257175603297746364.fujita.tomonori@gmail.com>
Date: Thu, 17 Oct 2024 18:31:41 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: boqun.feng@...il.com
Cc: fujita.tomonori@...il.com, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, andrew@...n.ch, 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,
jstultz@...gle.com, sboyd@...nel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v3 4/8] rust: time: Implement addition of
Ktime and Delta
On Wed, 16 Oct 2024 12:54:07 -0700
Boqun Feng <boqun.feng@...il.com> wrote:
>> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
>> index 8c00854db58c..9b0537b63cf7 100644
>> --- a/rust/kernel/time.rs
>> +++ b/rust/kernel/time.rs
>> @@ -155,3 +155,14 @@ pub fn as_secs(self) -> i64 {
>> self.nanos / NSEC_PER_SEC
>> }
>> }
>> +
>> +impl core::ops::Add<Delta> for Ktime {
>> + type Output = Ktime;
>> +
>> + #[inline]
>> + fn add(self, delta: Delta) -> Ktime {
>> + Ktime {
>> + inner: self.inner + delta.as_nanos(),
>
> What if overflow happens in this addition? Is the expectation that user
> should avoid overflows?
Yes, I'll add a comment.
> I asked because we have ktime_add_safe() which saturate at
> KTIME_SEC_MAX.
We could add the Rust version of add_safe method. But looks like
ktime_add_safe() is used by only some core systems so we don't need to
add it now?
Powered by blists - more mailing lists