From: Gary Guo via B4 Relay <devnull+gary.garyguo.net@kernel.org>
To: "Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>
Cc: rust-for-linux@vger.kernel.org, Gary Guo <gary@garyguo.net>
Subject: [PATCH v2] rust: macros: drop underscores from `#[optional]` methods
Date: Mon, 30 Nov 2026 16:44:47 +0000 [thread overview]
Message-ID: <20261130-dev-optional-v2-1-c29e08707002@garyguo.net> (raw)
From: Gary Guo <gary@garyguo.net>
In the `vtable` macro, `#[optional]` methods do not have a body, so they
should not require underscore-prefixing the function parameters just like
mandatory trait methods. Add `#[allow(unused_variables)]` to make
underscore unnecessary and drop the prefix from existing users.
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/rust-for-linux/CANiq72neqitKHftQ9UVJaKLkcUdX8uAWLtoE08-G784mqX+H9w@mail.gmail.com/
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Gary Guo <gary@garyguo.net>
---
Changes in v2:
- Also remove prefix from compat_ioctl (Sashiko)
- Link to v1: https://patch.msgid.link/20261126-dev-optional-v1-1-9e8d3a807d9b@garyguo.net
---
rust/kernel/miscdevice.rs | 32 ++++++++++++++------------------
rust/macros/vtable.rs | 2 ++
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
index 900676ea6bbc..3a672f4ac914 100644
--- a/rust/kernel/miscdevice.rs
+++ b/rust/kernel/miscdevice.rs
@@ -179,18 +179,18 @@ fn release(device: Self::File, _file: &File) {
/// `vma`.
#[optional]
fn mmap(
- _device: <Self::File as ForeignOwnable>::Borrowed<'_>,
- _file: &File,
- _vma: &VmaNew,
+ device: <Self::File as ForeignOwnable>::Borrowed<'_>,
+ file: &File,
+ vma: &VmaNew,
) -> Result;
/// Read from this miscdevice.
#[optional]
- fn read_iter(_kiocb: Kiocb<'_, Self::File>, _iov: &mut IovIterDest<'_>) -> Result<usize>;
+ fn read_iter(kiocb: Kiocb<'_, Self::File>, iov: &mut IovIterDest<'_>) -> Result<usize>;
/// Write to this miscdevice.
#[optional]
- fn write_iter(_kiocb: Kiocb<'_, Self::File>, _iov: &mut IovIterSource<'_>) -> Result<usize>;
+ fn write_iter(kiocb: Kiocb<'_, Self::File>, iov: &mut IovIterSource<'_>) -> Result<usize>;
/// Handler for ioctls.
///
@@ -199,10 +199,10 @@ fn mmap(
/// [`kernel::ioctl`]: mod@crate::ioctl
#[optional]
fn ioctl(
- _device: <Self::File as ForeignOwnable>::Borrowed<'_>,
- _file: &File,
- _cmd: u32,
- _arg: usize,
+ device: <Self::File as ForeignOwnable>::Borrowed<'_>,
+ file: &File,
+ cmd: u32,
+ arg: usize,
) -> Result<isize>;
/// Handler for ioctls.
@@ -215,19 +215,15 @@ fn ioctl(
#[cfg(CONFIG_COMPAT)]
#[optional]
fn compat_ioctl(
- _device: <Self::File as ForeignOwnable>::Borrowed<'_>,
- _file: &File,
- _cmd: u32,
- _arg: usize,
+ device: <Self::File as ForeignOwnable>::Borrowed<'_>,
+ file: &File,
+ cmd: u32,
+ arg: usize,
) -> Result<isize>;
/// Show info for this fd.
#[optional]
- fn show_fdinfo(
- _device: <Self::File as ForeignOwnable>::Borrowed<'_>,
- _m: &SeqFile,
- _file: &File,
- );
+ fn show_fdinfo(device: <Self::File as ForeignOwnable>::Borrowed<'_>, m: &SeqFile, file: &File);
}
/// A vtable for the file operations of a Rust miscdevice.
diff --git a/rust/macros/vtable.rs b/rust/macros/vtable.rs
index 981ad2e49647..aa41cb2f3ba9 100644
--- a/rust/macros/vtable.rs
+++ b/rust/macros/vtable.rs
@@ -79,6 +79,8 @@ fn handle_trait(mut item: ItemTrait) -> Result<ItemTrait> {
}));
// Ensure that the function is never code generated unless used.
fn_item.attrs.push(parse_quote!(#[inline]));
+ // Injected default implementation does not use function parameters.
+ fn_item.attrs.push(parse_quote!(#[allow(unused_variables)]));
}
// We don't know on the implementation-site whether a method is required or provided
---
base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
change-id: 20261126-dev-optional-50abc27e06cc
Best regards,
--
Gary Guo <gary@garyguo.net>
reply other threads:[~2026-11-30 16:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261130-dev-optional-v2-1-c29e08707002@garyguo.net \
--to=devnull+gary.garyguo.net@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox