From: Alvin Sun Date: Tue, 19 May 2026 14:26:19 +0800 Subject: [PATCH 7/8] rust: miscdevice: add `ThisModule` associated type to `MiscDevice` trait MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260519-fix-fops-owner-v1-7-2ded9830da14@linux.dev> References: <20260519-fix-fops-owner-v1-0-2ded9830da14@linux.dev> In-Reply-To: <20260519-fix-fops-owner-v1-0-2ded9830da14@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779171975; l=1248; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=w1EoH2KiN5QmfxawPU8PJaSlqVT8J3DiMsT2xzxxCS8=; b=2boe+1XQRLD4hO3skU1aJJQcbDXlgDARy7PBUJ88luhYe/WLmSsDSDrEExQl2YbOWZ2Tl8h0e pmNkBMmnQSyAdamOhFMpfzrTeCuM7HWH36VOSdl/5OJbzmR7hEcHgBQ X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 List-Id: B4 Relay Submissions Add a `ThisModule` associated type bound by `ModuleMetadata` to the `MiscDevice` trait, and use it to set the miscdevice fops owner field instead of defaulting to null. Signed-off-by: Alvin Sun --- rust/kernel/miscdevice.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index 05a6b6b9770f2..007caaae62697 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -38,6 +38,7 @@ ForeignOwnable, Opaque, // }, + ModuleMetadata, // }; use core::{ marker::PhantomData, @@ -137,6 +138,9 @@ pub trait MiscDevice: Sized { /// What kind of pointer should `Self` be wrapped in. type Ptr: ForeignOwnable + Send + Sync; + /// The module implementing this driver. + type ThisModule: ModuleMetadata; + /// Called when the misc device is opened. /// /// The returned pointer will be stored as the private data for the file. @@ -441,6 +445,7 @@ impl MiscdeviceVTable { } else { None }, + owner: ::MODULE_PTR, ..pin_init::zeroed() }; -- 2.43.0