From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Gary Guo" <gary@garyguo.net>,
"Luis Chamberlain" <mcgrof@kernel.org>,
"Petr Pavlu" <petr.pavlu@suse.com>,
"Daniel Gomez" <da.gomez@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Aaron Tomlin" <atomlin@atomlin.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: module_param: return copy from value() for Copy types
Date: Mon, 23 Mar 2026 14:23:14 +0100 [thread overview]
Message-ID: <87fr5qr871.fsf@kernel.org> (raw)
In-Reply-To: <DHA6CNZ4W0DH.388Y1VMS61C7T@garyguo.net>
"Gary Guo" <gary@garyguo.net> writes:
> On Mon Mar 23, 2026 at 12:47 PM GMT, Andreas Hindborg wrote:
>> Rename the existing `value()` method to `value_ref()` which returns a
>> shared reference to the parameter value, and add a new `value()`
>> method on `ModuleParamAccess<T>` where `T: Copy` that returns the
>> value by copy.
>>
>> This provides a more ergonomic API for the common case where the
>> parameter type implements `Copy`, avoiding the need to explicitly
>> dereference the return value at call sites.
>>
>> Currently `value_ref()` has no in-tree callers, but it will be needed
>> when support for non-`Copy` parameter types such as arrays and
>> strings is added.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>> ---
>> This change was suggested at [1].
>>
>> Link: https://lore.kernel.org/r/87cy13swpw.fsf@t14s.mail-host-address-is-not-set [1]
>> ---
>> rust/kernel/module_param.rs | 11 ++++++++++-
>> samples/rust/rust_minimal.rs | 2 +-
>> 2 files changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs
>> index 6a8a7a875643..5dcfe2ba87a1 100644
>> --- a/rust/kernel/module_param.rs
>> +++ b/rust/kernel/module_param.rs
>> @@ -134,7 +134,7 @@ pub const fn new(default: T) -> Self {
>> /// Get a shared reference to the parameter value.
>> // Note: When sysfs access to parameters are enabled, we have to pass in a
>> // held lock guard here.
>> - pub fn value(&self) -> &T {
>> + pub fn value_ref(&self) -> &T {
>> self.value.as_ref().unwrap_or(&self.default)
>> }
>>
>> @@ -146,6 +146,15 @@ pub const fn as_void_ptr(&self) -> *mut c_void {
>> }
>> }
>>
>> +impl<T: Copy> ModuleParamAccess<T> {
>> + /// Get a copy of the parameter value.
>> + // Note: When sysfs access to parameters are enabled, we have to pass in a
>> + // held lock guard here.
>> + pub fn value(&self) -> T {
>
> It's better to keep this close to `value_ref` in the same impl block. The `T:
> Copy` bound doesn't need to be on the impl block, it can be on the item itself
> with
>
> pub fn value(&self) -> T where T: Copy
Cool, I'll do that.
Best regards,
Andreas Hindborg
prev parent reply other threads:[~2026-03-23 13:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 12:47 [PATCH] rust: module_param: return copy from value() for Copy types Andreas Hindborg
2026-03-23 12:49 ` Alice Ryhl
2026-03-23 12:52 ` Gary Guo
2026-03-23 13:23 ` Andreas Hindborg [this message]
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=87fr5qr871.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=atomlin@atomlin.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=da.gomez@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mcgrof@kernel.org \
--cc=ojeda@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--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