summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorKosumi Chan <chankocyo@gmail.com>2026-07-11 04:23:27 -0400
committerMiguel Ojeda <ojeda@kernel.org>2026-08-10 06:44:10 +0200
commit39a309f432a9914af242a7a63eacfb390878c2ed (patch)
treef36d52046625777dfbab4e8dbc69fc7512309c8a /rust/kernel
parent168b4f9aa5792ebef2cb9312ca0d8c796e35d692 (diff)
downloadlinux-39a309f432a9914af242a7a63eacfb390878c2ed.tar.gz
linux-39a309f432a9914af242a7a63eacfb390878c2ed.zip
rust: impl_flags: use bit helper in example
Use bit_u32() instead of open-coding shifts in the impl_flags! example. This demonstrates the checked bit helper and ensures that bit positions remain within the underlying u32 type. Suggested-by: Miguel Ojeda <ojeda@kernel.org> Link: https://github.com/Rust-for-Linux/linux/issues/1244 Assisted-by: OpenCode:openai/gpt-5.6-sol Signed-off-by: Kosumi Chan <chankocyo@gmail.com> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/rust-for-linux/2026071054-hazing-antirust-8e40@gregkh/ Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://patch.msgid.link/20260711082327.3062227-1-chankocyo@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/impl_flags.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/rust/kernel/impl_flags.rs b/rust/kernel/impl_flags.rs
index e2bd7639da12..fdf44d5eea9c 100644
--- a/rust/kernel/impl_flags.rs
+++ b/rust/kernel/impl_flags.rs
@@ -19,7 +19,10 @@
/// # Examples
///
/// ```
-/// use kernel::impl_flags;
+/// use kernel::{
+/// bits::bit_u32,
+/// impl_flags, //
+/// };
///
/// impl_flags!(
/// /// Represents multiple permissions.
@@ -30,13 +33,13 @@
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// pub enum Permission {
/// /// Read permission.
-/// Read = 1 << 0,
+/// Read = bit_u32(0),
///
/// /// Write permission.
-/// Write = 1 << 1,
+/// Write = bit_u32(1),
///
/// /// Execute permission.
-/// Execute = 1 << 2,
+/// Execute = bit_u32(2),
/// }
/// );
///