Re: [PATCH net-next v3 4/8] rust: time: Implement addition of Ktime and Delta
From: FUJITA Tomonori
Date: Thu Oct 17 2024 - 05:32:07 EST
On Wed, 16 Oct 2024 12:54:07 -0700
Boqun Feng <boqun.feng@xxxxxxxxx> 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?