Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: alloc: implement `contains` for `Flags`

Provide a simple helper function to check whether given flags do
contain one or multiple other flags.

This is used by a subsequent patch implementing the Cmalloc `Allocator`
to check for __GFP_ZERO.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20241004154149.93856-25-dakr@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Danilo Krummrich and committed by
Miguel Ojeda
909037ce 4a28ab46

+6 -1
+6 -1
rust/kernel/alloc.rs
··· 35 35 /// They can be combined with the operators `|`, `&`, and `!`. 36 36 /// 37 37 /// Values can be used from the [`flags`] module. 38 - #[derive(Clone, Copy)] 38 + #[derive(Clone, Copy, PartialEq)] 39 39 pub struct Flags(u32); 40 40 41 41 impl Flags { 42 42 /// Get the raw representation of this flag. 43 43 pub(crate) fn as_raw(self) -> u32 { 44 44 self.0 45 + } 46 + 47 + /// Check whether `flags` is contained in `self`. 48 + pub fn contains(self, flags: Flags) -> bool { 49 + (self & flags) == flags 45 50 } 46 51 } 47 52