Re: [PATCH v2 1/2] rust: add projection infrastructure

From: Aditya Rajan

Date: Sat Feb 28 2026 - 18:38:42 EST


On Thu Feb 26, 2026 at 7:46 AM PST, Gary Guo wrote:
> From: Gary Guo <gary@xxxxxxxxxxx>
> 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.

[...]

> + // 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