From: Filipe Xavier <felipeaggger@gmail.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
daniel.almeida@collabora.com, rust-for-linux@vger.kernel.org,
felipe_life@live.com
Subject: Re: [PATCH] rust: add new macro for common bitwise operations
Date: Wed, 5 Mar 2025 09:46:16 -0300 [thread overview]
Message-ID: <51800499-e91e-48f5-b7ee-08a4d488add3@gmail.com> (raw)
In-Reply-To: <2025030439-sharpener-overkill-ada2@gregkh>
On 3/4/25 11:09 AM, Greg KH wrote:
> On Tue, Mar 04, 2025 at 09:55:11AM -0300, Filipe Xavier wrote:
>> We have seen a proliferation of mod_whatever::foo::Flags
>> being defined with essentially the same implementation
>> for bitAnd, bitOr, contains and etc.
>>
>> This macro aims to bring a solution for this,
>> allowing to generate these methods for user-defined structs.
>> With some use cases in KMS and VideoCodecs.
>>
>> Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/We.20really.20need.20a.20common.20.60Flags.60.20type
>> Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
>> ---
>> rust/kernel/bitmask.rs | 171 +++++++++++++++++++++++++++++++++++++++++++++++++
>> rust/kernel/lib.rs | 2 +
>> rust/kernel/prelude.rs | 1 +
>> 3 files changed, 174 insertions(+)
>>
>> diff --git a/rust/kernel/bitmask.rs b/rust/kernel/bitmask.rs
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..8d26a541c693a2cb60096059ecb708d895bb3ad1
>> --- /dev/null
>> +++ b/rust/kernel/bitmask.rs
>> @@ -0,0 +1,171 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +//! Bitmask utilities for working with flags in Rust.
>> +
>> +/// Declares a bitmask type with its corresponding flag type.
>> +///
>> +/// This macro generates:
>> +/// - Implementations of common bitwise operations (`BitOr`, `BitAnd`, etc.).
>> +/// - Utility methods such as `.contains()` to check flags.
>> +///
>> +/// # Examples
>> +///
>> +/// Defining and using a bitmask:
>> +/// ```
>> +/// bitmask!(Permissions, Permission, u32);
> Nice, but why not use the same api/names that are already in the kernel
> for this type of functionality in the C .h files? That way we have
> consistent names everywhere?
>
> thanks,
>
> greg k-h
Makes sense, my mistake, I didn't know...
Could you send me the reference of what already exists in the kernel so
I can change it?
Cheers,
Filipe
next prev parent reply other threads:[~2025-03-05 12:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 12:55 [PATCH] rust: add new macro for common bitwise operations Filipe Xavier
2025-03-04 12:57 ` Alice Ryhl
2025-03-10 13:31 ` Miguel Ojeda
2025-03-17 21:36 ` Lyude Paul
2025-03-04 14:09 ` Greg KH
2025-03-05 12:46 ` Filipe Xavier [this message]
2025-03-05 14:18 ` Greg KH
2025-03-14 14:18 ` Daniel Almeida
2025-03-14 15:02 ` Greg KH
2025-03-17 15:00 ` Alice Ryhl
2025-03-10 13:33 ` Miguel Ojeda
2025-03-13 0:40 ` kernel test robot
2025-03-14 14:09 ` Daniel Almeida
2025-03-17 21:40 ` Lyude Paul
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=51800499-e91e-48f5-b7ee-08a4d488add3@gmail.com \
--to=felipeaggger@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=felipe_life@live.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).