* [PATCH v2] rust: impl_flags: use bit helper in example
@ 2026-07-11 8:23 Kosumi Chan
2026-07-11 9:27 ` Miguel Ojeda
2026-07-11 12:39 ` Alexandre Courbot
0 siblings, 2 replies; 3+ messages in thread
From: Kosumi Chan @ 2026-07-11 8:23 UTC (permalink / raw)
To: ojeda
Cc: boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross,
dakr, daniel.almeida, tamird, acourbot, work, rust-for-linux,
linux-kernel
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>
---
Changes in v2:
- Use a full name for the author and Signed-off-by identities.
v1: https://lore.kernel.org/rust-for-linux/20260711071551.3035420-1-chankocyo@gmail.com/
rust/kernel/impl_flags.rs | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/impl_flags.rs b/rust/kernel/impl_flags.rs
index e2bd7639d..fdf44d5ee 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),
/// }
/// );
///
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rust: impl_flags: use bit helper in example
2026-07-11 8:23 [PATCH v2] rust: impl_flags: use bit helper in example Kosumi Chan
@ 2026-07-11 9:27 ` Miguel Ojeda
2026-07-11 12:39 ` Alexandre Courbot
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-07-11 9:27 UTC (permalink / raw)
To: Kosumi Chan, Greg Kroah-Hartman
Cc: ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, daniel.almeida, tamird, acourbot, work,
rust-for-linux, linux-kernel
On Sat, Jul 11, 2026 at 10:23 AM Kosumi Chan <chankocyo@gmail.com> wrote:
>
> 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>
Looks fine, thanks.
I think I will add:
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/rust-for-linux/2026071054-hazing-antirust-8e40@gregkh/
since Greg suggested the original change/idea even if not the one here.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rust: impl_flags: use bit helper in example
2026-07-11 8:23 [PATCH v2] rust: impl_flags: use bit helper in example Kosumi Chan
2026-07-11 9:27 ` Miguel Ojeda
@ 2026-07-11 12:39 ` Alexandre Courbot
1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Courbot @ 2026-07-11 12:39 UTC (permalink / raw)
To: Kosumi Chan
Cc: ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, daniel.almeida, tamird, work, rust-for-linux,
linux-kernel
On Sat Jul 11, 2026 at 5:23 PM JST, Kosumi Chan wrote:
> 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>
Why not. :)
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-11 12:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-11 8:23 [PATCH v2] rust: impl_flags: use bit helper in example Kosumi Chan
2026-07-11 9:27 ` Miguel Ojeda
2026-07-11 12:39 ` Alexandre Courbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox