From: "Gary Guo" <gary@garyguo.net>
To: "Aditya Rajan" <adi.dev.github@gmail.com>,
"Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nicolas Schier" <nsc@kernel.org>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-kbuild@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] rust: add projection infrastructure
Date: Sun, 01 Mar 2026 13:10:39 +0000 [thread overview]
Message-ID: <DGRGYFHZF7PF.1Q3MZ7C1SBRL7@garyguo.net> (raw)
In-Reply-To: <DGQZOLAH72HC.2OE3REDD7M7U7@gmail.com>
On Sat Feb 28, 2026 at 11:38 PM GMT, Aditya Rajan wrote:
> On Thu Feb 26, 2026 at 7:46 AM PST, Gary Guo wrote:
>> From: Gary Guo <gary@garyguo.net>
>> diff --git a/rust/kernel/projection.rs b/rust/kernel/projection.rs
>> new file mode 100644
>> index 000000000000..186ec194f2b8
>> --- /dev/null
>> +++ b/rust/kernel/projection.rs
>> +unsafe impl<T> ProjectIndex<[T]> for usize {
>> + type Output = T;
>> +
>> + #[inline(always)]
>> + fn get(self, slice: *mut [T]) -> Option<*mut T> {
>> + if self > slice.len() {
> I am not sure but shouldn't this be `self >= slice.len()` ? I could be wrong but `slice.get(n)` should return `None` for slice 0..n ?
> There is a similar condition somewhere else in the code as well.
Good catch!
The code below
if self.end > slice.len() {
return None;
}
is rightfully `>` as it's okay to have end being equal to the length. I suppose
this is what you mean by "somewhere else in the code"?
This one though should indeed be `>=`, and I've obviously messed this one up.
Best,
Gary
>
> [...]
>
>> + // Check unaligned field. Not all users (e.g. DMA) can handle unaligned
>> + // projections. (e.g. DMA).
> Nit: Comment mentions (e.g. DMA) twice
>
> One question regarding the `in bounds` check otherwise LGTM
>
> Thanks
> Aditya
next prev parent reply other threads:[~2026-03-01 13:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260226154656.3241736-1-gary@kernel.org>
2026-02-26 15:46 ` Gary Guo
2026-02-28 23:38 ` Aditya Rajan
2026-03-01 13:10 ` Gary Guo [this message]
2026-03-02 4:41 ` Aditya Rajan
2026-02-26 15:46 ` [PATCH v2 2/2] rust: dma: use pointer projection infra for `dma_{read,write}` macro Gary Guo
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=DGRGYFHZF7PF.1Q3MZ7C1SBRL7@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=adi.dev.github@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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
all inboxes | Powered by JetHome®