Skip to content

Commit 909037c

Browse files
Danilo Krummrichojeda
authored andcommitted
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>
1 parent 4a28ab4 commit 909037c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rust/kernel/alloc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ use core::{alloc::Layout, ptr::NonNull};
3535
/// They can be combined with the operators `|`, `&`, and `!`.
3636
///
3737
/// Values can be used from the [`flags`] module.
38-
#[derive(Clone, Copy)]
38+
#[derive(Clone, Copy, PartialEq)]
3939
pub struct Flags(u32);
4040

4141
impl Flags {
4242
/// Get the raw representation of this flag.
4343
pub(crate) fn as_raw(self) -> u32 {
4444
self.0
4545
}
46+
47+
/// Check whether `flags` is contained in `self`.
48+
pub fn contains(self, flags: Flags) -> bool {
49+
(self & flags) == flags
50+
}
4651
}
4752

4853
impl core::ops::BitOr for Flags {

0 commit comments

Comments
 (0)