diff options
author | Danilo Krummrich <dakr@kernel.org> | 2024-08-05 12:39:15 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2024-08-13 16:05:09 +0200 |
commit | 3634762ead9f828eac6796e0d68e4dfed0f6b4cf (patch) | |
tree | 953347f4a44bd9507887826200f8f59ea3cf408e | |
parent | 58a32cb00d641066657491add0638239f806777f (diff) |
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>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
-rw-r--r-- | rust/kernel/alloc.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs index 820ef6072e02..be2bd0f1e74a 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -34,7 +34,7 @@ use core::{alloc::Layout, ptr::NonNull}; /// They can be combined with the operators `|`, `&`, and `!`. /// /// Values can be used from the [`flags`] module. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub struct Flags(u32); impl Flags { @@ -42,6 +42,11 @@ impl Flags { pub(crate) fn as_raw(self) -> u32 { self.0 } + + /// Check whether `flags` is contained in `self`. + pub fn contains(self, flags: Flags) -> bool { + (self & flags) == flags + } } impl core::ops::BitOr for Flags { |