From: "Danilo Krummrich" <dakr@kernel.org>
To: "Gary Guo" <gary@garyguo.net>
Cc: "FUJITA Tomonori" <tomo@flapping.org>, <boqun@kernel.org>,
<aliceryhl@google.com>, <lyude@redhat.com>,
<daniel.almeida@collabora.com>, <work@onurozkan.dev>,
<ojeda@kernel.org>, <bjorn3_gh@protonmail.com>,
<lossin@kernel.org>, <a.hindborg@kernel.org>, <tmgross@umich.edu>,
<tamird@kernel.org>, <acourbot@nvidia.com>,
<viro@zeniv.linux.org.uk>, <brauner@kernel.org>, <jack@suse.cz>,
<linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>,
<linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH v3 1/5] rust: task: add safe schedule_timeout() wrapper
Date: Tue, 17 Nov 2026 14:14:10 +0100 [thread overview]
Message-ID: <DMXIHAWC8YGT.33OH5RY5OPPBE@kernel.org> (raw)
In-Reply-To: <DMXGYAQZB33R.4BWEI96XQXL6@garyguo.net>
On Tue Nov 17, 2026 at 1:02 PM CET, Gary Guo wrote:
> On Tue Nov 17, 2026 at 11:56 AM GMT, Danilo Krummrich wrote:
>> On Tue Nov 17, 2026 at 12:40 PM CET, Gary Guo wrote:
>>> On Tue Nov 17, 2026 at 12:45 AM GMT, FUJITA Tomonori wrote:
>>>> On Tue, 17 Nov 2026 01:14:42 +0100
>>>> Danilo Krummrich <dakr@kernel.org> wrote:
>>>>
>>>>> +pub fn schedule_timeout(timeout: Delta<Jiffy>) -> Delta<Jiffy> {
>>>>> + let timeout = timeout.as_jiffies().max(0);
>>>>
>>>> In earlier reviews of my patches, Gary asked me to use the function
>>>> syntax or clamp() for this instead of the method syntax [1][2]:
>>>>
>>>> let timeout = isize::max(timeout.as_jiffies(), 0);
>>>
>>> Yes, please do. I'm okay with either `isize::max` or `cmp::max`.
>>
>> The examples in [1][2] both seemed to be able to avoid a cast with this, which
>> isn't the case for this patch. There also doesn't seem to be any ambiguity in
>> the extression used in this patch. So I don't see why changing it would be
>> better.
>
> The ambiguity is "the maximum value returned will be 0" and "the minimum value
> returned will be 0". The answer is always the latter but I'd avoid the mental
> gymnastics.
To me clearly both
a.max(b) (1)
max(a, b) (2)
read as the maximum of a and b.
IIUC, what you are saying is that people may read (1) as
a.at_max(b)
which would indeed be equivalent to min(a, b).
If this is indeed commonly the case I'd suggest to raise this to become a common
rule (ideally with a lint), such that we avoid this to be discussed in reviews.
Personally, I prefer (1) for the expression above, but I don't care too much, so
I'm fine to change it. (In case I don't need to respin I'll change it on apply.)
Thanks,
Danilo
next prev parent reply other threads:[~2026-11-17 13:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 0:14 [PATCH v3 0/5] rust: sync: add WaitQueue infrastructure Danilo Krummrich
2026-11-17 0:14 ` [PATCH v3 1/5] rust: task: add safe schedule_timeout() wrapper Danilo Krummrich
2026-11-17 0:45 ` FUJITA Tomonori
2026-11-17 11:40 ` Gary Guo
2026-11-17 11:56 ` Danilo Krummrich
2026-11-17 12:02 ` Gary Guo
2026-11-17 13:14 ` Danilo Krummrich [this message]
2026-11-17 14:16 ` Alice Ryhl
2026-11-17 0:14 ` [PATCH v3 2/5] rust: sync: add WaitQueue infrastructure Danilo Krummrich
2026-11-17 11:59 ` Gary Guo
2026-11-17 14:16 ` Alice Ryhl
2026-11-17 0:14 ` [PATCH v3 3/5] rust: sync: convert CondVar and PollCondVar to use WaitQueue Danilo Krummrich
2026-11-17 14:16 ` Alice Ryhl
2026-11-17 0:14 ` [PATCH v3 4/5] rust: sync: condvar: use task::schedule_timeout() Danilo Krummrich
2026-11-17 14:16 ` Alice Ryhl
2026-11-17 0:14 ` [PATCH v3 5/5] rust: sync: condvar: add non-exclusive freezable waiting Danilo Krummrich
2026-11-17 14:16 ` Alice Ryhl
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=DMXIHAWC8YGT.33OH5RY5OPPBE@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=tomo@flapping.org \
--cc=viro@zeniv.linux.org.uk \
--cc=work@onurozkan.dev \
/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