lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 27 May 2024 10:31:35 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alice Ryhl <aliceryhl@...gle.com>, Miguel Ojeda <ojeda@...nel.org>, Andrew Morton <akpm@...ux-foundation.org>
Cc: Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...sung.com>, Marco Elver <elver@...gle.com>, Kees Cook <keescook@...omium.org>, Coly Li <colyli@...e.de>, Paolo Abeni <pabeni@...hat.com>, Pierre Gondois <pierre.gondois@....com>, Ingo Molnar <mingo@...nel.org>, Jakub Kicinski <kuba@...nel.org>, Wei Yang <richard.weiyang@...il.com>, Matthew Wilcox <willy@...radead.org>, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v2 6/9] rust: list: add iterators

On 06.05.24 11:53, Alice Ryhl wrote:
> Rust Binder has lists containing stuff such as all contexts or all
> processes, and sometimes need to iterate over them. This patch enables

typo: need -> needs

> Rust Binder to do that using a normal for loop.
> 
> The iterator returns the ArcBorrow type, so it is possible to grab a
> refcount to values while iterating.
> 
> Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>

Two documentation nits below, with those fixed:

Reviewed-by: Benno Lossin <benno.lossin@...ton.me>

> ---
>  rust/kernel/list.rs | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 102 insertions(+)
> 
> diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
> index d0ff29a3e5d1..e36afc7ee44a 100644
> --- a/rust/kernel/list.rs
> +++ b/rust/kernel/list.rs
> @@ -5,7 +5,9 @@
>  //! A linked list implementation.
> 
>  use crate::init::PinInit;
> +use crate::sync::ArcBorrow;
>  use crate::types::Opaque;
> +use core::iter::{DoubleEndedIterator, FusedIterator};
>  use core::marker::PhantomData;
>  use core::ptr;
> 
> @@ -435,6 +437,17 @@ pub fn push_all_back(&mut self, other: &mut List<T, ID>) {
>          // INVARIANT: The other list is now empty, so update its pointer.
>          other.first = ptr::null_mut();
>      }
> +
> +    /// Creates an iterator over the list.
> +    pub fn iter(&self) -> Iter<'_, T, ID> {
> +        // INVARIANT: If the list is empty, both pointers are null. Otherwise, both pointers point
> +        // at the first element of the same list.
> +        Iter {
> +            current: self.first,
> +            stop: self.first,
> +            _ty: PhantomData,
> +        }
> +    }
>  }
> 
>  impl<T: ?Sized + ListItem<ID>, const ID: u64> Default for List<T, ID> {
> @@ -450,3 +463,92 @@ fn drop(&mut self) {
>          }
>      }
>  }
> +
> +/// An iterator into a [`List`].

I would use "over" instead of "into".

> +///
> +/// # Invariants
> +///
> +/// * There must be a [`List`] that is immutably borrowed for the duration of `'a`.
> +/// * The `current` pointer is null or points at a value in that [`List`].
> +/// * The `stop` pointer is equal to the `first` field of the [`List`].

the -> that

---
Cheers,
Benno

> +#[derive(Clone)]
> +pub struct Iter<'a, T: ?Sized + ListItem<ID>, const ID: u64 = 0> {
> +    current: *mut ListLinksFields,
> +    stop: *mut ListLinksFields,
> +    _ty: PhantomData<&'a ListArc<T, ID>>,
> +}


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ