From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust: module: add `THIS_MODULE` const to `ModuleMetadata` trait
Date: Mon, 25 May 2026 20:45:43 +1000 [thread overview]
Message-ID: <review-patch1-20260521-fix-fops-owner-v2-1-fd99079c5a04@linux.dev> (raw)
In-Reply-To: <20260521-fix-fops-owner-v2-1-fd99079c5a04@linux.dev>
Patch Review
This patch adds `const THIS_MODULE: ThisModule` to the `ModuleMetadata` trait, moves the `THIS_MODULE` static from the `module!` macro body into the `ModuleMetadata` impl for the module type, and updates `__init` to use the trait const.
The key change in `rust/kernel/lib.rs`:
```rust
const THIS_MODULE: ThisModule;
```
And in `rust/macros/module.rs`, the old `static THIS_MODULE` (with `#[cfg(MODULE)]` / `#[cfg(not(MODULE))]` variants) becomes:
```rust
impl ::kernel::ModuleMetadata for #type_ {
const NAME: &'static ::kernel::str::CStr = #name_cstr;
#[cfg(MODULE)]
const THIS_MODULE: ::kernel::ThisModule = {
extern "C" {
static __this_module: ::kernel::types::Opaque<::kernel::bindings::module>;
}
unsafe { ::kernel::ThisModule::from_ptr(__this_module.get()) }
};
#[cfg(not(MODULE))]
const THIS_MODULE: ::kernel::ThisModule = unsafe {
::kernel::ThisModule::from_ptr(::core::ptr::null_mut())
};
}
```
**Observations:**
1. **`static` → `const` semantics for `THIS_MODULE`**: The old `static THIS_MODULE` had a stable address. Making it a `const` means each use site can potentially get its own copy. However, `ThisModule` is just a wrapper around `*mut module` — a pointer-sized value — so this should be fine. The pointer *value* (i.e., the address of `__this_module`) is the important thing, not the address of the `ThisModule` wrapper itself. Callers that need a `&ThisModule` reference (like `__init`) will take a reference to a temporary, which is valid in Rust for const promotion. This is correct.
2. The `SAFETY` comment is preserved and appropriate — `__this_module` is kernel-constructed and lives for the module lifetime. The `from_ptr(null_mut())` path for built-in is consistent with the previous behavior.
3. The `__init` call site change from `&super::super::THIS_MODULE` to `&<super::super::LocalModule as ::kernel::ModuleMetadata>::THIS_MODULE` is verbose but correct — the fully-qualified syntax avoids ambiguity.
**No issues found.**
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-25 10:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 7:52 [PATCH v2 0/7] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
2026-05-21 7:52 ` [PATCH v2 1/7] rust: module: add `THIS_MODULE` const to `ModuleMetadata` trait Alvin Sun
2026-05-25 10:45 ` Claude Code Review Bot [this message]
2026-05-21 7:52 ` [PATCH v2 2/7] rust: macros: auto-insert ThisModule in #[vtable] Alvin Sun
2026-05-25 10:45 ` Claude review: " Claude Code Review Bot
2026-05-21 7:52 ` [PATCH v2 3/7] rust: doctest: add LocalModule fallback for #[vtable] ThisModule Alvin Sun
2026-05-25 10:45 ` Claude review: " Claude Code Review Bot
2026-05-21 7:52 ` [PATCH v2 4/7] rust: drm: set fops.owner from driver module pointer Alvin Sun
2026-05-25 10:45 ` Claude review: " Claude Code Review Bot
2026-05-21 7:52 ` [PATCH v2 5/7] rust: miscdevice: " Alvin Sun
2026-05-25 10:45 ` Claude review: " Claude Code Review Bot
2026-05-21 7:52 ` [PATCH v2 6/7] rust: configfs: use `LocalModule` for `THIS_MODULE` Alvin Sun
2026-05-25 10:45 ` Claude review: " Claude Code Review Bot
2026-05-21 7:52 ` [PATCH v2 7/7] block: rnull: " Alvin Sun
2026-05-25 10:45 ` Claude review: " Claude Code Review Bot
2026-05-25 10:45 ` Claude review: Fix missing fops.owner in Rust DRM/misc abstractions Claude Code Review Bot
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=review-patch1-20260521-fix-fops-owner-v2-1-fd99079c5a04@linux.dev \
--to=claude-review@example.com \
--cc=dri-devel-reviews@example.com \
/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