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] [day] [month] [year] [list]
Date: Tue, 30 Jan 2024 21:10:54 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Christina Quast <contact@...istina-quast.de>
Cc: Miguel Ojeda <ojeda@...nel.org>, 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>, 
	Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...sung.com>, 
	Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: prelude: add bit function

Hi Christina,

Thanks for the patch! Please see below.

On Tue, Jan 30, 2024 at 8:48 PM Christina Quast
<contact@...istina-quast.de> wrote:
>
> In order to create masks easily, the define BIT() is used in C code.
> This commit adds the same functionality to the rust kernel.
>
> To use it, include the following into your rust file:
> use kernel::prelude::bit

This is the prelude, i.e. the point is that it does not need to be `use`d.

Did you check the `rust` branch? We had something like this there.

> diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs
> index ae21600970b3..16e483de2f27 100644
> --- a/rust/kernel/prelude.rs
> +++ b/rust/kernel/prelude.rs

Please note that the prelude is meant to re-export existing
functionality elsewhere in the `kernel` crate, not to define items
there.

> +/// # Arguments
> +///
> +/// * `n` - A `u32` that specifies the bit position (zero-based index)

We don't use "Arguments"-like sections. Please see other functions'
documentation to see how we usually do it.

> +/// # Example

Please use the plural.

> +/// ```
> +/// let b = bit(2);
> +/// assert_eq!(b, 4);

The example is not closed.

> +#[inline]
> +pub const fn bit(n: u32) -> u32 {
> +    1 << n
> +}

Should it be a generic?

Cheers,
Miguel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ