All of lore.kernel.org
 help / color / mirror / Atom feed
From: kosumi <chankocyo@gmail.com>
To: ojeda@kernel.org
Cc: boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com,
	lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
	tmgross@umich.edu, dakr@kernel.org, daniel.almeida@collabora.com,
	tamird@kernel.org, acourbot@nvidia.com, work@onurozkan.dev,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] rust: impl_flags: use bit helper in example
Date: Sat, 11 Jul 2026 03:15:51 -0400	[thread overview]
Message-ID: <20260711071551.3035420-1-chankocyo@gmail.com> (raw)

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 <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


             reply	other threads:[~2026-07-11  7:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-11  7:15 kosumi [this message]
2026-07-11  7:57 ` [PATCH] rust: impl_flags: use bit helper in example Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260711071551.3035420-1-chankocyo@gmail.com \
    --to=chankocyo@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.