From nobody Sun Feb 8 02:41:07 2026 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FBA92459D4 for ; Thu, 1 Jan 2026 05:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244895; cv=none; b=UvUYR4yEYSA2buRYZ+GwI+0mIxg8BVa3NArfDRfblmfd1YPWAVhXtsgA4SsFXFe3pRuF5Jt686t+N/HYedqR01jWpbSC7h2ZxBu+AUCDrser7ljdbsvlbX94VjbwduNJNNp7H1JWMsdn8di7kuKqE0eroWY91WyYXgXISjbStlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244895; c=relaxed/simple; bh=oU8AXbLPxfdc2yPuZDO/6a4+snqR12Lb8r8RXRuzo3k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nqd9fQLQD+Ydlx0jk1wTkaX6J57yCS8dHwNr68MfO4IN3f3ndHQmy6JBuMlpXJCI3LQ1RdnfVeQel2xF9K8ukKAkRzwMbsxzkzFKADdIPJYdeirvdquifAy4zCLCIVszspKGDG7EdLevq4eBSlj3blmxmz+wzdowoGa5Gvgkwdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dAoxeEDV; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dAoxeEDV" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-37a34702a20so77397771fa.3 for ; Wed, 31 Dec 2025 21:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244891; x=1767849691; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yHOwRzURK3HvR3V48oWkPaPLxKL+jt3ZSgRna/0IJ4U=; b=dAoxeEDV4GElskcjlC3fnacaYdAKC82LNc/oN/g0rYBPStYWlIJmy1Kw20o85dtcbz evawp3YLd6O51yoEzEBKdD4KiAm9Sxy1X4mGgX3WlzOecZHRObdYdCHxDpOLR86XHeT+ lKpM+Z0cuLTO1Hmzwn9yyhbsNiEEje5u3tcnf+yYlcnfR4cGjFtedpRqsdP7Q7EKwOap x7wsilHJx8xDFNmVKCNiXtioXA+m4mrDHBBJ4o26o6i7+ahcIu72SBS95Sw11UFINBpR XV1E1mF7vak2XGv99xdifiVHAMeY19lr4l3PNWDSTMtnNTQbWNeUFpiAX/t7vn3ZjkUj VXsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244891; x=1767849691; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=yHOwRzURK3HvR3V48oWkPaPLxKL+jt3ZSgRna/0IJ4U=; b=q/5NoEk2YI7VrXg0Z6bJoKsdPvak9GNs7Yf93gmcruwVpamaiDxUkzq8ndZwdOXc0z WF2qltnp6oVec0tGCuxZYaR7gIKpQoyy4fkAxv0wtuj4M+qBIY95frVbGkm1LJFude+m ZaBuUPOQri0SFbj7C1nEMbbFo1C9MZxJ+deNCEr55rFC/Rc4m1R2lLp9CoAIQ3wZbewj 0CjCa3fWE6Lo703Pbzkm+9j38fh2lhRuvq33ZuwEprIU3g/0IAS2RyiL68ZfvUF2bhKz Bhwc+ZRIt+VQOjM3qLBgtZaHnNMx2DOe8s3T6zOBuninoecHrKNMUJOn9/+mye8pPwz0 hPTQ== X-Forwarded-Encrypted: i=1; AJvYcCUG3shIQcDbCs8aIBfvp0zJRZ/b7AZgS6E4L5xG7YpiR8hqKEw/kgakyMuIrk3Oh7ZEVNT/LHnCe59veNU=@vger.kernel.org X-Gm-Message-State: AOJu0YyFJK/hswVHLspYHuiqivgTKpSmzPLK7cDk1lWDAIO9Iw7Hq4wB zPnLwW5mBZoU2DkmrHP63rJ8g2YBouX6bVSeGlH+S5I1Q8YGGHxE/Xp0 X-Gm-Gg: AY/fxX45Ry5hom9Fa3OO2sQR/GyJYeefiqymExgzkKmVAYJdRNFv8L037iTHsuQK/JS 6ZnBgv9YNVDB+FqSGCOWOS9kPbxJ5jVbUtZ9ghZd44gu/nFB2Z4R0hiwQG/NEyH6HZtYoFu4l4c NsFXmJzj8TUcBxJwidCJHlMvgHg3k014OzV5Kig1chaRhmAOI9RU4PpzuJGY75BK5Wuh39Zr9ok 8KctCzhcNFPEh+qyPHRRZUZFcRSg3Yv+MXxFpvOCfst6T7MiCDf+g9wdNwa0y5QHUH2Sng4tSTj y90CeFVtDDMaI++voKKt4n7jXKJRmTZIv4IkFbUeOdg4vTLVNqrk+DCwZ9f5te2kwOXrwAZ7OCM 10L5AXBQTejl7L+fk9wUlD+zdmUsOssZ9e5lKLfDt+7cEiGPPad6Hkc6Kq/UxEwrKuH27ucaP2J gHrtrhoS+mAP8ApAxbWNrKFQHizTHNmlgHgOGrmtUt0UaViCF87rSHxHuTZS9YIri9vE7Glk0xZ QpPkA== X-Google-Smtp-Source: AGHT+IHEv+kPqKymr4VXmqTi30FJOewT0NTEHSBAdMfCqJgglKj7HSTDJFJDDr6fr8BgfLO462XPUw== X-Received: by 2002:a05:651c:b12:b0:37a:432f:8ecc with SMTP id 38308e7fff4ca-381216724dcmr135823501fa.33.1767244890832; Wed, 31 Dec 2025 21:21:30 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:29 -0800 (PST) From: Kari Argillander Date: Thu, 01 Jan 2026 07:20:45 +0200 Subject: [PATCH RFC 1/6] rust: Enable const_refs_to_static feature Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-this_module_fix-v1-1-46ae3e5605a0@gmail.com> References: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> In-Reply-To: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> 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 , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=837; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=oU8AXbLPxfdc2yPuZDO/6a4+snqR12Lb8r8RXRuzo3k=; b=IGihzG2buaIXq6V07kPH6f84Q1eDKB0tLDVGw2tPrNwji1/UqRfEH5cLGqRiecwlWj8R9P3WQ KHN72I+wjixDD6J81u60QyxyE/AWhjyCf1H9TuHy54eIUeQ2OQ04qoX X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Enable the const_refs_to_static Rust feature to allow taking references to static items in const contexts. This is required for using ThisModule when constructing static Rust structures. The Rust support already relies on features available in Rust 1.83, and const_refs_to_static has been available since Rust 1.78. Signed-off-by: Kari Argillander --- rust/kernel/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index f812cf120042..69a798fbb563 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -36,6 +36,7 @@ #![feature(const_option)] #![feature(const_ptr_write)] #![feature(const_refs_to_cell)] +#![feature(const_refs_to_static)] // // Expected to become stable. #![feature(arbitrary_self_types)] --=20 2.43.0 From nobody Sun Feb 8 02:41:07 2026 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDFC12472A2 for ; Thu, 1 Jan 2026 05:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244899; cv=none; b=NFPtJAOvz/g3RO/aSSpZ1ScbYDGlZvZRz77N9GYbGNg3gJtk5QwEXV4qDW5WQDO3svTYpP8k3LJTXN7aTWfrEbubqYoqtCKryr/Lwii+po6lV7bAwPuvtv/X+BjKHbgTsha5KLv+b0P4HEShj8BtxnCLLXF+ofpo6J/L8SIhHps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244899; c=relaxed/simple; bh=mU7s+7tWle8pm/zSL/diWG1twIvZ0xjTqsG/iAaLFVs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pa2oGqOEI2EdNcXZfpBQb2c6ftr1I9ICPXr+vf5KtZBoFTjczMsJvmrChnXD2FbG9JzZCsJ3jTlg9/dRr9bMXFJ43e8DXQj9ZCc+FRPZABh4rVBuSZQuzUF4TtNVuzZyIbmkpaCgOb2NuSua3tvMCvHSQizP8EY8ebLaHB7vplo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EhsAcM2J; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EhsAcM2J" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-37d96f97206so84676111fa.3 for ; Wed, 31 Dec 2025 21:21:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244896; x=1767849696; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Rd8KgyV6F2j/qbBvIqB4YfMbMB7FNH9gnCb0sBOPwfY=; b=EhsAcM2JNjP8uGkuj4KLoD3okLmvDAhpRQfXYb6JxePqzeivU3TSoycT5XPqG8HYwL a4KBjXCBeZEz3DgRcrI61R2tN9I/op4oFd3pVkKdYOOP99ibeXEUMOISHFOupLfttrhx eH/qPGrI0u2a1oUYeUON1+FPFTWiZ3TVspFDY2GnM636HSnIJ8Dqjx8ael7+7xb3tk18 uJMpwJ48Gv0B5qH8mI8BNYbwk2jv56n+MPqPXbJQsFDryQuKC8KT/0HGeRCZB/kIueeb IVLnzaLpfnV6D9Maq/5ZbbExZPhHO0PLhmGQ7HTaskketkp54in57NNy4EEyMEAk5tSU MY7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244896; x=1767849696; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Rd8KgyV6F2j/qbBvIqB4YfMbMB7FNH9gnCb0sBOPwfY=; b=Uupfp6e/x9gYGn+3eEmiAusOQgQkmUJ31CUVXji2kjS1b4PvK1u1Hj63OI6XaA+ZFO jS3/PoU6mgNzXzPlG2FSNlCTBQWkAJc80zFYooI43QESI3Mt1Gc9pY6N0FsM1gRz4mC4 xjjrtGqvGjkXSwi91vC7uMRGXGvvawmhYkN7NZIg0e/yHk/MzkgnAMNEZvXZTqmYudbw YDx5yjYxrA2D7aT6NSfGowqvmpnVpZekqJF2q+ncSoLxEAO0Lf4ajeqTVc4Y6BvVuw45 zF23UYJjTyxC6W1hDf+2vfK48ZAU8z8udVntEvnsK1KvFzSMYOey7Haa9QytNUPGsJsz q/hQ== X-Forwarded-Encrypted: i=1; AJvYcCU3E+QXRX8sGvB6pn69OYKerxhYyMOpA1Y7YO0jjkbWh5VXUII5jhgDReRJI5Nb90FraebO1SF25TINCo0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1hhrK/9pbi/HO+88lmXMN8uHAIlvowmlaxbBVCH/G935g/wq4 qB5qJJfjco7k1SVfmN1RNTrKaoCqTWjNL618VvHfDozi1vn52hbml9Yk X-Gm-Gg: AY/fxX49gu62mf51wWR91NUtt9/YjjYBnuwX5KU9nHwWif4Kh+RmAN8A75qURoGu0Za lPzF2pdFL5RB6uDThv4TR0Z837DhQM5OW3jmL958Es8e73/4nXXCzHBkFjXGFv4vt0S8VM75j/o xDxdel7/gr9dJIvKxwD3hiMqHp85PCqXAoDWXr3KxpdSGMu0hhXQYf5wqMK1BjrajB6/SdBo6af hQR4OL6wXIlQo4jxjOkgkaF08VmeCuX2UwoOejK59KBFtv/kn/Yn92axNQ2nUV3v5LILR6rAZrN arKf2HlFLQvOkA2ZnGuXTzvXyIl3PvYpMiQU+d/OaAhc4w4CFmlO9JGdI+WZRte0uzJeY3VcF9p jrvL+bmPzvyxdnDCKfcHdd6q5QFH8Br0fPxFSEtys6YyzvpgzApm09HoxR5DIStcpQbre2azuBV 8x0qvmzWMGbd05km0J10kkIwnltUZVNjwO/ko6DVWuwGCSB0LoohuSfMGyTQxsW0gKWLHV0WLEP 5dSSRr/rofQEEYf X-Google-Smtp-Source: AGHT+IGRQFvH4f88ZR5TKWqHF2jFP4khZugE+rhqFElCpV/e1k3ApZo6w/n7a0Bu3kCAQWxd13ewgg== X-Received: by 2002:a05:651c:30ca:b0:382:60a5:331e with SMTP id 38308e7fff4ca-38260a537b8mr69604671fa.28.1767244895673; Wed, 31 Dec 2025 21:21:35 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:33 -0800 (PST) From: Kari Argillander Date: Thu, 01 Jan 2026 07:20:46 +0200 Subject: [PATCH RFC 2/6] rust: WIP: Introduce ThisModule trait and THIS_MODULE impl Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-this_module_fix-v1-2-46ae3e5605a0@gmail.com> References: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> In-Reply-To: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> 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 , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=5717; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=mU7s+7tWle8pm/zSL/diWG1twIvZ0xjTqsG/iAaLFVs=; b=/GQEca3eN2s3ciSbXCmGhgObb8BIPcjCfeRRMtC0Uh/y5Lr4prsvIJqfmeLcMLuXGTf8x3FF7 C3/y0olv51EDa8VyGRLe5r57ole2bM00+sMDk4fEy7Tk2SwHQg4FAbp X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= --- rust/kernel/lib.rs | 61 +++++++++++++++++++++++++++++++++++------------= ---- rust/macros/module.rs | 36 ++++++++++++++++++------------ 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 69a798fbb563..224410745734 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -205,31 +205,54 @@ pub trait ModuleMetadata { const NAME: &'static crate::str::CStr; } =20 -/// Equivalent to `THIS_MODULE` in the C API. -/// -/// C header: [`include/linux/init.h`](srctree/include/linux/init.h) -pub struct ThisModule(*mut bindings::module); +pub mod this_module { + //! TODO + //! + //! # For driver cretors + //! + //! For each module we define own custom THIS_MODULE in + //! [`macros::module::module`]. Mechanism is equivalent to `THIS_MODUL= E` in + //! the [C API](srctree/include/linux/init.h). + //! + //! TODO + //! + //! # For abstraction creators + //! + //! TODO =20 -// SAFETY: `THIS_MODULE` may be used from all threads within a module. -unsafe impl Sync for ThisModule {} + /// See [`this_module`] + pub trait ThisModule { + /// TODO Doc + const OWNER: ModuleWrapper; + } =20 -impl ThisModule { - /// Creates a [`ThisModule`] given the `THIS_MODULE` pointer. - /// - /// # Safety - /// - /// The pointer must be equal to the right `THIS_MODULE`. - pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> ThisModule= { - ThisModule(ptr) + /// See [`this_module`] + pub struct ModuleWrapper { + ptr: *mut bindings::module, } =20 - /// Access the raw pointer for this module. - /// - /// It is up to the user to use it correctly. - pub const fn as_ptr(&self) -> *mut bindings::module { - self.0 + impl ModuleWrapper { + /// Get the raw pointer to the underlying `struct module`. + /// + /// TODO: Should be only available for kernel create. + pub const fn as_ptr(&self) -> *mut bindings::module { + self.ptr + } + + /// Only meant to use in [`macros::module::module`]. + /// + /// # Safety + /// + /// - Only modules are allowed to create non null `ModuleWrapper`s. + /// - The pointer must point to a valid `struct module` provided b= y the + /// kernel. + #[doc(hidden)] + pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> Self { + ModuleWrapper { ptr } + } } } +pub use this_module::*; =20 #[cfg(not(testlib))] #[panic_handler] diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 80cb9b16f5aa..6b8753d122cc 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -371,20 +371,28 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { /// Used by the printing macros, e.g. [`info!`]. const __LOG_PREFIX: &[u8] =3D b\"{name}\\0\"; =20 - // SAFETY: `__this_module` is constructed by the kernel at loa= d time and will not be - // freed until the module is unloaded. - #[cfg(MODULE)] - static THIS_MODULE: ::kernel::ThisModule =3D unsafe {{ - extern \"C\" {{ - static __this_module: ::kernel::types::Opaque<::kernel= ::bindings::module>; - }} + /// THIS_MODULE for \"{name}\". See more at [`kernel::this_mod= ule`]. + #[allow(non_camel_case_types)] + pub struct THIS_MODULE; + + impl ::kernel::prelude::ThisModule for THIS_MODULE {{ + #[cfg(not(MODULE))]=20 + const OWNER: ::kernel::this_module::ModuleWrapper =3D unsa= fe {{ + ::kernel::this_module::ModuleWrapper::from_ptr(::core:= :ptr::null_mut()) + }}; =20 - ::kernel::ThisModule::from_ptr(__this_module.get()) - }}; - #[cfg(not(MODULE))] - static THIS_MODULE: ::kernel::ThisModule =3D unsafe {{ - ::kernel::ThisModule::from_ptr(::core::ptr::null_mut()) - }}; + #[cfg(MODULE)] + // SAFETY: + // - `__this_module` is constructed by the kernel at modul= e load time. + // - We use check that we are module so we can create non-= null ModuleWrapper. + const OWNER: ::kernel::this_module::ModuleWrapper =3D unsa= fe {{ + extern \"C\" {{ + static __this_module: ::kernel::types::Opaque<::ke= rnel::bindings::module>; + }} + =20 + ::kernel::this_module::ModuleWrapper::from_ptr(__this_= module.get()) + }}; + }} =20 /// The `LocalModule` type is the type of the module created b= y `module!`, /// `module_pci_driver!`, `module_platform_driver!`, etc. @@ -502,7 +510,7 @@ mod __module_init {{ /// This function must only be called once. unsafe fn __init() -> ::kernel::ffi::c_int {{ let initer =3D - <{type_} as ::kernel::InPlaceModule>::init(&su= per::super::THIS_MODULE); + <{type_} as ::kernel::InPlaceModule>::init::(); // SAFETY: No data race, since `__MOD` can only be= accessed by this module // and there only `__init` and `__exit` access it.= These functions are only // called once and `__exit` cannot be called befor= e or during `__init`. --=20 2.43.0 From nobody Sun Feb 8 02:41:07 2026 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4348221545 for ; Thu, 1 Jan 2026 05:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244906; cv=none; b=GJUgClARIzxmD6UcjNwFwefelA939jrBHmPS2GS0tjz6LD8Omr1Uaxj41bnUavzV32mEg3unVdQLNdPsWd02n/sl8bK3vYeHC4srs+KKj4oDq2yaGKajDgT8kgf21zwBsLtRjsOmSBTX1XZkIHomQMsoPEIrqlusDd0syhfj1mY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244906; c=relaxed/simple; bh=kV4DkY3TtJnlHn45QNA7Ft8lFKQx+oLspMvgwXtsboA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tcsnfbvYj5yI4YT0oaM+tspsRTWunQ80y+rryt6JYI/K8UFlGNjvBLPphQEtlMiKpx+p8jxvvmUf5R25J0Zw2GUDD+zz76D+5FIIERLuWPbaoMU69juPajRtPn2Mwxp6PppjOLLdo3qMIo/EO5Luf3oTJhAED4uIIkMAbgNKpfg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MjCtWA55; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MjCtWA55" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-37d13ddaa6aso76600641fa.1 for ; Wed, 31 Dec 2025 21:21:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244901; x=1767849701; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ffSbuz17L8vVbkn/GTSFMF7fhgC1j9yn2MGyslUVfLA=; b=MjCtWA550aEi9VoN7jJW3+GpzpMd+jba2j2dp/QLtSrv0Rs1HP/wonjqCRzenHEfS/ QGU8wti1FcsVFJhn6kHROxjJpyokCX/gESxP9uvfXbV5jn2BPl3JZSoVgk+0sUHDJNGN uxHmibSiNFv4e3HWewDasonzbNusinb/4G2UMddrio+WxJaHrfMsk4zR4cvDyE/P8tEw jBRa/X4z+RoSSnLmW1eyTws9ou60BBImtYZSBXq12ZvHcfQIe+HQ4uzV8KFoMMNuJFv/ UlGznN+vmu20brJjUuZM8+GNKGX6uTvzaJ+KgXutAiqAe0tKvTaE3mkdmo3vObMa0QHg nJbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244901; x=1767849701; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ffSbuz17L8vVbkn/GTSFMF7fhgC1j9yn2MGyslUVfLA=; b=F4xV82ucyBBzkvyx4LFYcifdTIQWv46NQy0xqpb6bzyr+vZ3O19jfOFGcrHqf9FDpm lVefzcFGKHKX9k1TjBik89Ez9rDfLUzCBIrvuZ0oHsRnlAWg13crybfsALnXlzPOcK3l NkeMypndQvw137HMSMYulrg3azzLggeHHDhHteVp2ydg9tWqtqUSbJ2zgsZNPjuobBVa 1pu0BM0OGGPoHKPb/uJfxfIi+DM9PRE9cwqUlRthTqCfUf1A3dQBjYd7ZRgdBnsjEGY0 H/a6jeHnDK6duLPMSEr7GryhKoi529q6FWcGNgOGZ57NZo6kMcxwIfsW/8b2CeKCgE/m Fo5g== X-Forwarded-Encrypted: i=1; AJvYcCW54fII62hLPR4TnvFQZ4vXX65ZqrgSYKZUW8INNxtcdDTY6OhcOA9uFucS2KrSdfZVFbbJeU0iQufeRSg=@vger.kernel.org X-Gm-Message-State: AOJu0YxHb/FdmdWwZyrN+VdiOz5UUGD2ppiU8CpcXCUh1W0wi/Vlx0Wx +jxIEFf8g8RjT1G93ZrDKas8POhTvoG4/Sbe2FjJyH58koro0wZYXtFh X-Gm-Gg: AY/fxX7S99worYf7z2J+kELLVgA9k7IX0+TsS2Q8+jZRP3ENaFidRL18jc6PvHW1YMr MoiDNE+XulwdeTbSAy2JYfQ5/2tPFC+1qSD6p0h+9nPX7kqDRinni8rgsgMat26nHX+Ne60vUMu 9pOr2IHiMDfx4K5N2psCOeZqFJ2WqAFbqkFkRAdYNejgHFhBDymkiDews76a6IajEzne/lier4/ RdDYugGOI/kjE8n0TCgQaySMSwQwrBMi9Lasu/O3sAeS1iyHeRJIKWSqJH+craWzV8tvkOQ1stM 6u3Civ8R/WpgjWxlCmy42FwNIBCOEmLuFx8Nz2LBTtAMJtCFKL/rWfYazAqgQ4JG+4MPoE0TjMM cCmMoYvS03/13Io4VQD0bWlf0r3YUVUuSLtFLNUZgdKUVuGUcrT99NMqFNURNAbO4N0S6TpVEIK U+srygGutzr1EmxCQWVp8w8URuuBHIi3JNeiXSqv28EmlkYBFN9upIFe0YiOGdVHk1uQyTv1G4h IGSyQ== X-Google-Smtp-Source: AGHT+IGLqj0ZDWmmxkTrWd4nad4rwkLFukXDL7htB6nyYsiBPkASQFcnEz38louFRmEn5A9Lzx7JHg== X-Received: by 2002:a05:651c:221a:b0:37c:c370:60a3 with SMTP id 38308e7fff4ca-38121313ec1mr111357941fa.0.1767244900598; Wed, 31 Dec 2025 21:21:40 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:38 -0800 (PST) From: Kari Argillander Date: Thu, 01 Jan 2026 07:20:47 +0200 Subject: [PATCH RFC 3/6] rust: WIP: use ThisModule trait for initializing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-this_module_fix-v1-3-46ae3e5605a0@gmail.com> References: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> In-Reply-To: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> 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 , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=22402; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=kV4DkY3TtJnlHn45QNA7Ft8lFKQx+oLspMvgwXtsboA=; b=+2FpexS0WtXNE6vKdS0mOYAZUdjY2u4guztXgs4ZztyxnPyjmfXSFxqyMMmr8cqDPqCt6c0xm d9MHAh93ng1DGDpjRd9emw3nfIsZ0Tg5u1+1FuaRr+ezB4mjh8xqXKZ X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Now that ThisModule is trait we can use it for initializing. This way we can also use it in const context. This does matter in later on. --- drivers/android/binder/rust_binder_main.rs | 2 +- drivers/block/rnull/configfs.rs | 2 +- drivers/block/rnull/rnull.rs | 2 +- rust/kernel/auxiliary.rs | 9 ++------- rust/kernel/configfs.rs | 19 +++++++++---------- rust/kernel/driver.rs | 17 +++++------------ rust/kernel/drm/gem/mod.rs | 4 ++-- rust/kernel/i2c.rs | 8 ++------ rust/kernel/lib.rs | 8 ++++---- rust/kernel/net/phy.rs | 16 ++++++++-------- rust/kernel/pci.rs | 9 ++------- rust/kernel/platform.rs | 9 ++------- rust/kernel/usb.rs | 9 ++------- samples/rust/rust_configfs.rs | 2 +- samples/rust/rust_driver_auxiliary.rs | 6 +++--- samples/rust/rust_driver_faux.rs | 2 +- samples/rust/rust_minimal.rs | 2 +- samples/rust/rust_misc_device.rs | 2 +- samples/rust/rust_print_main.rs | 2 +- 19 files changed, 49 insertions(+), 81 deletions(-) diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index c79a9e742240..169fe552e32a 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -282,7 +282,7 @@ fn ptr_align(value: usize) -> Option { struct BinderModule {} =20 impl kernel::Module for BinderModule { - fn init(_module: &'static kernel::ThisModule) -> Result { + fn init() -> Result { // SAFETY: The module initializer never runs twice, so we only cal= l this once. unsafe { crate::context::CONTEXTS.init() }; =20 diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs= .rs index 6713a6d92391..a581c97219c7 100644 --- a/drivers/block/rnull/configfs.rs +++ b/drivers/block/rnull/configfs.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 =20 -use super::{NullBlkDevice, THIS_MODULE}; +use super::NullBlkDevice; use kernel::{ block::mq::gen_disk::{GenDisk, GenDiskBuilder}, c_str, diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index a9d5e575a2c4..c9dff74489c1 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -36,7 +36,7 @@ struct NullBlkModule { } =20 impl kernel::InPlaceModule for NullBlkModule { - fn init(_module: &'static ThisModule) -> impl PinInit { + fn init() -> impl PinInit { pr_info!("Rust null_blk loaded\n"); =20 try_pin_init!(Self { diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs index 56f3c180e8f6..323074322505 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -12,7 +12,6 @@ error::{from_result, to_result, Result}, prelude::*, types::Opaque, - ThisModule, }; use core::{ marker::PhantomData, @@ -28,11 +27,7 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::auxiliary_driver; =20 - unsafe fn register( - adrv: &Opaque, - name: &'static CStr, - module: &'static ThisModule, - ) -> Result { + unsafe fn register(adrv: &Opaque, name: = &'static CStr) -> Result { // SAFETY: It's safe to set the fields of `struct auxiliary_driver= ` on initialization. unsafe { (*adrv.get()).name =3D name.as_char_ptr(); @@ -43,7 +38,7 @@ unsafe fn register( =20 // SAFETY: `adrv` is guaranteed to be a valid `RegType`. to_result(unsafe { - bindings::__auxiliary_driver_register(adrv.get(), module.0, na= me.as_char_ptr()) + bindings::__auxiliary_driver_register(adrv.get(), M::OWNER.as_= ptr(), name.as_char_ptr()) }) } =20 diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 466fb7f40762..f6f0a32e06d1 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -744,17 +744,17 @@ macro_rules! impl_item_type { ($tpe:ty) =3D> { impl ItemType<$tpe, Data> { #[doc(hidden)] - pub const fn new_with_child_ctor( - owner: &'static ThisModule, + pub const fn new_with_child_ctor( attributes: &'static AttributeList, ) -> Self where Data: GroupOperations, Child: 'static, + M: ThisModule, { Self { item_type: Opaque::new(bindings::config_item_type { - ct_owner: owner.as_ptr(), + ct_owner: M::OWNER.as_ptr(), ct_group_ops: GroupOperationsVTable::= ::vtable_ptr().cast_mut(), ct_item_ops: ItemOperationsVTable::<$tpe, Data>::v= table_ptr().cast_mut(), ct_attrs: core::ptr::from_ref(attributes).cast_mut= ().cast(), @@ -765,13 +765,12 @@ pub const fn new_with_child_ctor( } =20 #[doc(hidden)] - pub const fn new( - owner: &'static ThisModule, + pub const fn new( attributes: &'static AttributeList, ) -> Self { Self { item_type: Opaque::new(bindings::config_item_type { - ct_owner: owner.as_ptr(), + ct_owner: M::OWNER.as_ptr(), ct_group_ops: core::ptr::null_mut(), ct_item_ops: ItemOperationsVTable::<$tpe, Data>::v= table_ptr().cast_mut(), ct_attrs: core::ptr::from_ref(attributes).cast_mut= ().cast(), @@ -1019,8 +1018,8 @@ macro_rules! configfs_attrs { const [<$no_child:upper>]: bool =3D true; =20 static [< $data:upper _TPE >] : $crate::configfs::Item= Type<$container, $data> =3D - $crate::configfs::ItemType::<$container, $data>::n= ew::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] + $crate::configfs::ItemType::<$container, $data>::n= ew::( + &[<$ data:upper _ATTRS >] ); )? =20 @@ -1028,8 +1027,8 @@ macro_rules! configfs_attrs { static [< $data:upper _TPE >]: $crate::configfs::ItemType<$container, $data> =3D $crate::configfs::ItemType::<$container, $data= >:: - new_with_child_ctor::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] + new_with_child_ctor::( + &[<$ data:upper _ATTRS >] ); )? =20 diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index 9beae2e3d57e..7c4ad24bb48a 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -118,11 +118,7 @@ pub unsafe trait RegistrationOps { /// /// On success, `reg` must remain pinned and valid until the matching = call to /// [`RegistrationOps::unregister`]. - unsafe fn register( - reg: &Opaque, - name: &'static CStr, - module: &'static ThisModule, - ) -> Result; + unsafe fn register(reg: &Opaque, name: &= 'static CStr) -> Result; =20 /// Unregisters a driver previously registered with [`RegistrationOps:= :register`]. /// @@ -155,7 +151,7 @@ unsafe impl Send for Registration {} =20 impl Registration { /// Creates a new instance of the registration object. - pub fn new(name: &'static CStr, module: &'static ThisModule) -> impl P= inInit { + pub fn new(name: &'static CStr) -> impl PinInit { try_pin_init!(Self { reg <- Opaque::try_ffi_init(|ptr: *mut T::RegType| { // SAFETY: `try_ffi_init` guarantees that `ptr` is valid f= or write. @@ -166,7 +162,7 @@ pub fn new(name: &'static CStr, module: &'static ThisMo= dule) -> impl PinInit) = }; =20 // SAFETY: `drv` is guaranteed to be pinned until `T::unre= gister`. - unsafe { T::register(drv, name, module) } + unsafe { T::register::(drv, name) } }), }) } @@ -197,13 +193,10 @@ struct DriverModule { } =20 impl $crate::InPlaceModule for DriverModule { - fn init( - module: &'static $crate::ThisModule - ) -> impl ::pin_init::PinInit { + fn init() -> impl ::pin_init::PinInit= { $crate::try_pin_init!(Self { - _driver <- $crate::driver::Registration::new( + _driver <- $crate::driver::Registration::new::( ::NAME, - module, ), }) } diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index bdaac839dacc..1d9f78752946 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -292,10 +292,10 @@ impl AllocImpl for Object { }; } =20 -pub(super) const fn create_fops() -> bindings::file_operations { +pub(super) const fn create_fops() -> bindings::file_operati= ons { let mut fops: bindings::file_operations =3D pin_init::zeroed(); =20 - fops.owner =3D core::ptr::null_mut(); + fops.owner =3D M::OWNER.as_ptr(); fops.open =3D Some(bindings::drm_open); fops.release =3D Some(bindings::drm_release); fops.unlocked_ioctl =3D Some(bindings::drm_ioctl); diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index 491e6cc25cf4..bc154506b16f 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -97,11 +97,7 @@ macro_rules! i2c_device_table { unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::i2c_driver; =20 - unsafe fn register( - idrv: &Opaque, - name: &'static CStr, - module: &'static ThisModule, - ) -> Result { + unsafe fn register(idrv: &Opaque, name: = &'static CStr) -> Result { build_assert!( T::ACPI_ID_TABLE.is_some() || T::OF_ID_TABLE.is_some() || T::I= 2C_ID_TABLE.is_some(), "At least one of ACPI/OF/Legacy tables must be present when re= gistering an i2c driver" @@ -134,7 +130,7 @@ unsafe fn register( } =20 // SAFETY: `idrv` is guaranteed to be a valid `RegType`. - to_result(unsafe { bindings::i2c_register_driver(module.0, idrv.ge= t()) }) + to_result(unsafe { bindings::i2c_register_driver(M::OWNER.as_ptr()= , idrv.get()) }) } =20 unsafe fn unregister(idrv: &Opaque) { diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 224410745734..6d4563662a02 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -173,7 +173,7 @@ pub trait Module: Sized + Sync + Send { /// should do. /// /// Equivalent to the `module_init` macro in the C API. - fn init(module: &'static ThisModule) -> error::Result; + fn init() -> error::Result; } =20 /// A module that is pinned and initialised in-place. @@ -181,13 +181,13 @@ pub trait InPlaceModule: Sync + Send { /// Creates an initialiser for the module. /// /// It is called when the module is loaded. - fn init(module: &'static ThisModule) -> impl pin_init::PinInit; + fn init() -> impl pin_init::PinInit; } =20 impl InPlaceModule for T { - fn init(module: &'static ThisModule) -> impl pin_init::PinInit { + fn init() -> impl pin_init::PinInit= { let initer =3D move |slot: *mut Self| { - let m =3D ::init(module)?; + let m =3D ::init::()?; =20 // SAFETY: `slot` is valid for write per the contract with `pi= n_init_from_closure`. unsafe { slot.write(m) }; diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index bf6272d87a7b..5fc90d949d60 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -648,10 +648,7 @@ unsafe impl Send for Registration {} =20 impl Registration { /// Registers a PHY driver. - pub fn register( - module: &'static crate::ThisModule, - drivers: Pin<&'static mut [DriverVTable]>, - ) -> Result { + pub fn register(drivers: Pin<&'static mut [DriverVTable= ]>) -> Result { if drivers.is_empty() { return Err(code::EINVAL); } @@ -659,7 +656,11 @@ pub fn register( // the `drivers` slice are initialized properly. `drivers` will no= t be moved. // So it's just an FFI call. to_result(unsafe { - bindings::phy_drivers_register(drivers[0].0.get(), drivers.len= ().try_into()?, module.0) + bindings::phy_drivers_register( + drivers[0].0.get(), + drivers.len().try_into()?, + M::OWNER.as_ptr(), + ) })?; // INVARIANT: The `drivers` slice is successfully registered to th= e kernel via `phy_drivers_register`. Ok(Registration { drivers }) @@ -891,12 +892,11 @@ struct Module { [$($crate::net::phy::create_phy_driver::<$driver>()),+]; =20 impl $crate::Module for Module { - fn init(module: &'static $crate::ThisModule) -> Result { + fn init() -> Result { // SAFETY: The anonymous constant guarantees that nobo= dy else can access // the `DRIVERS` static. The array is used only in the= C side. let drivers =3D unsafe { &mut DRIVERS }; - let mut reg =3D $crate::net::phy::Registration::regist= er( - module, + let mut reg =3D $crate::net::phy::Registration::regist= er::( ::core::pin::Pin::static_mut(drivers), )?; Ok(Module { _reg: reg }) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 82e128431f08..792560ca8020 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -20,7 +20,6 @@ prelude::*, str::CStr, types::Opaque, - ThisModule, // }; use core::{ marker::PhantomData, @@ -55,11 +54,7 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::pci_driver; =20 - unsafe fn register( - pdrv: &Opaque, - name: &'static CStr, - module: &'static ThisModule, - ) -> Result { + unsafe fn register(pdrv: &Opaque, name: = &'static CStr) -> Result { // SAFETY: It's safe to set the fields of `struct pci_driver` on i= nitialization. unsafe { (*pdrv.get()).name =3D name.as_char_ptr(); @@ -70,7 +65,7 @@ unsafe fn register( =20 // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. to_result(unsafe { - bindings::__pci_register_driver(pdrv.get(), module.0, name.as_= char_ptr()) + bindings::__pci_register_driver(pdrv.get(), M::OWNER.as_ptr(),= name.as_char_ptr()) }) } =20 diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index ed889f079cab..67d46231600e 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -14,7 +14,6 @@ of, prelude::*, types::Opaque, - ThisModule, }; =20 use core::{ @@ -31,11 +30,7 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::platform_driver; =20 - unsafe fn register( - pdrv: &Opaque, - name: &'static CStr, - module: &'static ThisModule, - ) -> Result { + unsafe fn register(pdrv: &Opaque, name: = &'static CStr) -> Result { let of_table =3D match T::OF_ID_TABLE { Some(table) =3D> table.as_ptr(), None =3D> core::ptr::null(), @@ -56,7 +51,7 @@ unsafe fn register( } =20 // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. - to_result(unsafe { bindings::__platform_driver_register(pdrv.get()= , module.0) }) + to_result(unsafe { bindings::__platform_driver_register(pdrv.get()= , M::OWNER.as_ptr()) }) } =20 unsafe fn unregister(pdrv: &Opaque) { diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index d10b65e9fb6a..c6ee98d12875 100644 --- a/rust/kernel/usb.rs +++ b/rust/kernel/usb.rs @@ -13,7 +13,6 @@ prelude::*, str::CStr, types::{AlwaysRefCounted, Opaque}, - ThisModule, }; use core::{ marker::PhantomData, @@ -32,11 +31,7 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::usb_driver; =20 - unsafe fn register( - udrv: &Opaque, - name: &'static CStr, - module: &'static ThisModule, - ) -> Result { + unsafe fn register(udrv: &Opaque, name: = &'static CStr) -> Result { // SAFETY: It's safe to set the fields of `struct usb_driver` on i= nitialization. unsafe { (*udrv.get()).name =3D name.as_char_ptr(); @@ -47,7 +42,7 @@ unsafe fn register( =20 // SAFETY: `udrv` is guaranteed to be a valid `RegType`. to_result(unsafe { - bindings::usb_register_driver(udrv.get(), module.0, name.as_ch= ar_ptr()) + bindings::usb_register_driver(udrv.get(), M::OWNER.as_ptr(), n= ame.as_char_ptr()) }) } =20 diff --git a/samples/rust/rust_configfs.rs b/samples/rust/rust_configfs.rs index 0ccc7553ef39..858b2a45238d 100644 --- a/samples/rust/rust_configfs.rs +++ b/samples/rust/rust_configfs.rs @@ -42,7 +42,7 @@ fn new() -> impl PinInit { } =20 impl kernel::InPlaceModule for RustConfigfs { - fn init(_module: &'static ThisModule) -> impl PinInit { + fn init() -> impl PinInit { pr_info!("Rust configfs sample (init)\n"); =20 // Define a subsystem with the data type `Configuration`, two diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index 5761ea314f44..e996dca19454 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -111,10 +111,10 @@ struct SampleModule { } =20 impl InPlaceModule for SampleModule { - fn init(module: &'static kernel::ThisModule) -> impl PinInit { + fn init() -> impl PinInit { try_pin_init!(Self { - _pci_driver <- driver::Registration::new(MODULE_NAME, module), - _aux_driver <- driver::Registration::new(MODULE_NAME, module), + _pci_driver <- driver::Registration::new::(MODULE_NAME), + _aux_driver <- driver::Registration::new::(MODULE_NAME), }) } } diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_fa= ux.rs index ecc9fd378cbd..f66452c0390c 100644 --- a/samples/rust/rust_driver_faux.rs +++ b/samples/rust/rust_driver_faux.rs @@ -17,7 +17,7 @@ struct SampleModule { } =20 impl Module for SampleModule { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { pr_info!("Initialising Rust Faux Device Sample\n"); =20 let reg =3D faux::Registration::new(c_str!("rust-faux-sample-devic= e"), None)?; diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 8eb9583571d7..c3696e69d67b 100644 --- a/samples/rust/rust_minimal.rs +++ b/samples/rust/rust_minimal.rs @@ -23,7 +23,7 @@ struct RustMinimal { } =20 impl kernel::Module for RustMinimal { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { pr_info!("Rust minimal sample (init)\n"); pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); pr_info!( diff --git a/samples/rust/rust_misc_device.rs b/samples/rust/rust_misc_devi= ce.rs index d69bc33dbd99..3f1acb6818a5 100644 --- a/samples/rust/rust_misc_device.rs +++ b/samples/rust/rust_misc_device.rs @@ -129,7 +129,7 @@ struct RustMiscDeviceModule { } =20 impl kernel::InPlaceModule for RustMiscDeviceModule { - fn init(_module: &'static ThisModule) -> impl PinInit { + fn init() -> impl PinInit { pr_info!("Initialising Rust Misc Device Sample\n"); =20 let options =3D MiscDeviceOptions { diff --git a/samples/rust/rust_print_main.rs b/samples/rust/rust_print_main= .rs index 4095c72afeab..b60ff0683a0e 100644 --- a/samples/rust/rust_print_main.rs +++ b/samples/rust/rust_print_main.rs @@ -59,7 +59,7 @@ fn arc_dyn_print(arc: &Arc) { } =20 impl kernel::Module for RustPrint { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { pr_info!("Rust printing macros sample (init)\n"); =20 pr_emerg!("Emergency message (level 0) without args\n"); --=20 2.43.0 From nobody Sun Feb 8 02:41:07 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37460231845 for ; Thu, 1 Jan 2026 05:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244910; cv=none; b=CK6b2ADdrAdQ0f0Wj13//3huyniAobHJiDYVEMCGHVtTYQqO8C4hnJTkr6jB1DLLXhnQqF53inl+pz34EDdJPODkW6xjWeDIboYei7xGrGSg+35xWn/L7iA9QKP7LXmWieMgmKJA2i1NwulsoyDjuTQAsKv5GGHP6eXY8seeQs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244910; c=relaxed/simple; bh=nhvDkK7TuHB4MoV4yw6dY467Y+N4XGakk6DbHpWFzd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fQBnmgk3CaPo8ZKTOychHdHQScpl34rVqKl7mMnQMWkDtGMyW+uUaWXDpx9J9xze9nPdqmW75EnW5Vc7Xt7DHRD5eeOt2VotWBoTZczuuZNbIuNpNH3vhF3Ece6zvjTV7vIe1U2In0lN7tLeE0QGLg+M9fVpMXQEtSFpqqhzDQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ju6NoZ4E; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ju6NoZ4E" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5945510fd7aso9138876e87.0 for ; Wed, 31 Dec 2025 21:21:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244906; x=1767849706; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=m/ANztT2H+RPjRwH4Tsn7VpWSZebBDPsBIwtoPyunNo=; b=Ju6NoZ4EdUJ+YcU0nQtl91qWUEYRJuGnIbFyD3FiTNgEkRoOyXqroW4QNht0iT1aTI g0d/UDJPPHEjG0wXPV2QlVtx6UT63rTdMdj0sfDKHRXZ0vSeoNRVx3vT/1Qa8Vuivht1 bC9VDDwNFuOT9wdwhaRh9fp2+kGr3O7OehBa/mNDhrEoagdnICeAIb/vjoQuGyt6qFAJ lgJ//1q7IohtPGMD+a+yANVugBoT0MPVUiwatSPy7UC4cten2Xk8OC9gMoOhu1IA8+Z4 TDD/t3pqMiA1XkhSvguINfHYVeB7aEkVGWtDuzozRyiEk2LmpD87gD17MqZKfOEmZCK7 VYIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244906; x=1767849706; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=m/ANztT2H+RPjRwH4Tsn7VpWSZebBDPsBIwtoPyunNo=; b=UT/IzV3LpHqIpYorUOt+iLRxBkWWEK9jetcFA3lbXETv0tnidypfoZZypmZ+snVjlV qgbwX5r2KEAaxoVmbSOoJf2+Gh5L4t02h/LnAVZIhhGQs5EapSGCAB6LBJPoyyU9WVAs uGfp0G9B6i6AUl4eMaJ0AwYXJvmUdRKVskd3bNJGWGU5eSDrPX81UTkfw+FnVF7bfTFV sqzIlvkEZT15jejVqh2JfuMaaXct9FYYNk01Yz4iY/Ud5fCy1XWbjRR9e02TVGE/2pwg QStRxtzzYkCaQ5A5rjSosv360mrduH624JpR/+dN5InsA76VLyt/RZ/rYSrteU4z6/Uw 3QKQ== X-Forwarded-Encrypted: i=1; AJvYcCUnC8oc/MYkm2hlH2yGp+v9FKMiwtNyaf9rw4aitIxa1EVL4OGW/y0c7HWXhxDDSjHusOksBuyi/3SmyXM=@vger.kernel.org X-Gm-Message-State: AOJu0YzWsRdOVfH4L9LmCtd+cUF120Hb7I/CBZgjmXfARVCBaaWWnOA+ VFXVEcHqUTfsJywJncZYnvD7+rjwzhzt38nC6Vo+CF2Pz/GVelZUZsi3 X-Gm-Gg: AY/fxX6fvLOEp5eUP6itKQcvwJwWAn13yiyungB33Nlbm2RUcMV8PjrAnGVvVzdgbAh ZoNgZa9vmo8AahWHKTYVYJmnCzglZY4KTTwnW9/YSsNMRXwQkiOJNs/DvqfNiM9HJ3V3v+S/E90 DKZUeXTSxLB1fyN1al/M4q5ps3jiz/lAzENOXo8QXzEkkVtvi7NZo16C5O5VkpNX/uuPe9uRDS+ mJEubGE+tp9UhmBnA7GSpXnmgoOmZRylwDkj8reOPyPBzZkWZA7UTBEuibPhMvcQs7TDflYBmDf oMRgLk74fnIpFEHzxnYJD8L0tt5J18lnhbVu2P6+8L0F+JNfF0IVDdokRrwt4tXEdHRCrGizJJi I2oTBUel3EuYseSgWvKTaikjcXMBmCxVk6TTQNfWR9CQH1rXFi35MugTFIcCkKyRgk2Ex52gs4U IlXiUjEBeMRK+gF2ds5taZTr5py5UhQYZtZ+b2gE06e2Rm5Te7hqc95e+3Jn9JOzygYAcJbDsBc 2SgLA== X-Google-Smtp-Source: AGHT+IEY8zKF0VLVmG6TtPAYOSCfHkImpLYAYGmmru2k+1hlQ5fmMzzDNTll7nlIB5lVGkBEHsJVnA== X-Received: by 2002:a05:6512:131c:b0:593:ffa:6988 with SMTP id 2adb3069b0e04-59a17d9707fmr13645549e87.21.1767244905984; Wed, 31 Dec 2025 21:21:45 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:43 -0800 (PST) From: Kari Argillander Date: Thu, 01 Jan 2026 07:20:48 +0200 Subject: [PATCH RFC 4/6] rust: WIP: use ThisModule trait to fix some missing owners Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-this_module_fix-v1-4-46ae3e5605a0@gmail.com> References: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> In-Reply-To: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> 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 , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=9015; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=nhvDkK7TuHB4MoV4yw6dY467Y+N4XGakk6DbHpWFzd0=; b=LQy58ByfuHjMPZSnA9a2ozCKWq2Y3Fs4/M6Cjv7nmjYk01qfXvfcVsmWkq4egQIxeok8J69Op Z2gArtuoOyuBaqKqaIIhTViELLVZ9f5EjAfc727JvOm0cfPtMH4Kwtm X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Some places do not define owner and we have null pointer dereference bugs which we can fix with this. I have tested miscdevice that it actually works. --- drivers/android/binder/rust_binder_main.rs | 2 +- drivers/block/rnull/rnull.rs | 1 + drivers/gpu/drm/nova/driver.rs | 1 + drivers/gpu/drm/tyr/driver.rs | 1 + lib/find_bit_benchmark_rust.rs | 2 +- rust/kernel/block/mq/gen_disk.rs | 31 ++++----------------------= ---- rust/kernel/block/mq/operations.rs | 12 ++++++++++++ rust/kernel/drm/device.rs | 2 +- rust/kernel/drm/driver.rs | 3 +++ rust/kernel/miscdevice.rs | 4 ++++ samples/rust/rust_misc_device.rs | 1 + 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index 169fe552e32a..7877503c639e 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -311,7 +311,7 @@ unsafe impl Sync for AssertSync {} let zeroed_ops =3D unsafe { core::mem::MaybeUninit::zeroed().assume_in= it() }; =20 let ops =3D kernel::bindings::file_operations { - owner: THIS_MODULE.as_ptr(), + owner: ::OWNER.as_ptr(), poll: Some(rust_binder_poll), unlocked_ioctl: Some(rust_binder_ioctl), compat_ioctl: Some(bindings::compat_ptr_ioctl), diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index c9dff74489c1..3360a0f50fc6 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -75,6 +75,7 @@ struct QueueData { #[vtable] impl Operations for NullBlkDevice { type QueueData =3D KBox; + type ThisModule =3D THIS_MODULE; =20 #[inline(always)] fn queue_rq(queue_data: &QueueData, rq: ARef>, _is_l= ast: bool) -> Result { diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs index 2246d8e104e0..a49c9848ce2e 100644 --- a/drivers/gpu/drm/nova/driver.rs +++ b/drivers/gpu/drm/nova/driver.rs @@ -57,6 +57,7 @@ fn probe(adev: &auxiliary::Device, _info: &Self::Id= Info) -> impl PinInit; diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs index 264c2362237a..a84825dbd008 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -180,6 +180,7 @@ fn drop(self: Pin<&mut Self>) { =20 #[vtable] impl drm::Driver for TyrDriver { + type ThisModule =3D crate::THIS_MODULE; type Data =3D TyrData; type File =3D File; type Object =3D drm::gem::Object; diff --git a/lib/find_bit_benchmark_rust.rs b/lib/find_bit_benchmark_rust.rs index 6bdc51de2f30..420a1855b08a 100644 --- a/lib/find_bit_benchmark_rust.rs +++ b/lib/find_bit_benchmark_rust.rs @@ -88,7 +88,7 @@ fn find_bit_test() { } =20 impl kernel::Module for Benchmark { - fn init(_module: &'static ThisModule) -> Result { + fn init() -> Result { find_bit_test(); // Return error so test module can be inserted again without rmmod. Err(code::EINVAL) diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index 1ce815c8cdab..f5839829d0b7 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -7,7 +7,7 @@ =20 use crate::{ bindings, - block::mq::{Operations, TagSet}, + block::mq::{operations::OperationsVTable, Operations, TagSet}, error::{self, from_err_ptr, Result}, fmt::{self, Write}, prelude::*, @@ -126,32 +126,9 @@ pub fn build( ) })?; =20 - const TABLE: bindings::block_device_operations =3D bindings::block= _device_operations { - submit_bio: None, - open: None, - release: None, - ioctl: None, - compat_ioctl: None, - check_events: None, - unlock_native_capacity: None, - getgeo: None, - set_read_only: None, - swap_slot_free_notify: None, - report_zones: None, - devnode: None, - alternative_gpt_sector: None, - get_unique_id: None, - // TODO: Set to THIS_MODULE. Waiting for const_refs_to_static = feature to - // be merged (unstable in rustc 1.78 which is staged for linux= 6.10) - // - owner: core::ptr::null_mut(), - pr_ops: core::ptr::null_mut(), - free_disk: None, - poll_bio: None, - }; - - // SAFETY: `gendisk` is a valid pointer as we initialized it above - unsafe { (*gendisk).fops =3D &TABLE }; + unsafe { + (*gendisk).fops =3D OperationsVTable::::build_block_device_= operations(); + } =20 let mut writer =3D NullTerminatedFormatter::new( // SAFETY: `gendisk` points to a valid and initialized instanc= e. We diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/oper= ations.rs index 8ad46129a52c..3e0e8baa7d07 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -31,6 +31,8 @@ pub trait Operations: Sized { /// Data associated with the `struct request_queue` that is allocated = for /// the `GenDisk` associated with this `Operations` implementation. type QueueData: ForeignOwnable; + /// TODO Doc + type ThisModule: ThisModule; =20 /// Called by the kernel to queue a request with the driver. If `is_la= st` is /// `false`, the driver is allowed to defer committing the request. @@ -283,4 +285,14 @@ impl OperationsVTable { pub(crate) const fn build() -> &'static bindings::blk_mq_ops { &Self::VTABLE } + + const BLOCK_OPS: bindings::block_device_operations =3D bindings::block= _device_operations { + owner: T::ThisModule::OWNER.as_ptr(), + ..pin_init::zeroed() + }; + + pub(crate) const fn build_block_device_operations() -> &'static bindin= gs::block_device_operations + { + &Self::BLOCK_OPS + } } diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 3ce8f62a0056..a740c87933d0 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -92,7 +92,7 @@ impl Device { fops: &Self::GEM_FOPS, }; =20 - const GEM_FOPS: bindings::file_operations =3D drm::gem::create_fops(); + const GEM_FOPS: bindings::file_operations =3D drm::gem::create_fops::<= T::ThisModule>(); =20 /// Create a new `drm::Device` for a `drm::Driver`. pub fn new(dev: &device::Device, data: impl PinInit) -= > Result> { diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index f30ee4c6245c..ae8f7d3b9156 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -99,6 +99,9 @@ pub trait AllocImpl: super::private::Sealed + drm::gem::I= ntoGEMObject { /// drm_driver` to be registered in the DRM subsystem. #[vtable] pub trait Driver { + /// TODO Doc + type ThisModule: ThisModule; + /// Context data associated with the DRM driver type Data: Sync + Send; =20 diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index d698cddcb4a5..08346c52d574 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -116,6 +116,9 @@ pub trait MiscDevice: Sized { /// What kind of pointer should `Self` be wrapped in. type Ptr: ForeignOwnable + Send + Sync; =20 + /// TODO Docs + type ThisModule: ThisModule; + /// Called when the misc device is opened. /// /// The returned pointer will be stored as the private data for the fi= le. @@ -389,6 +392,7 @@ impl MiscdeviceVTable { } =20 const VTABLE: bindings::file_operations =3D bindings::file_operations { + owner: T::ThisModule::OWNER.as_ptr(), open: Some(Self::open), release: Some(Self::release), mmap: if T::HAS_MMAP { Some(Self::mmap) } else { None }, diff --git a/samples/rust/rust_misc_device.rs b/samples/rust/rust_misc_devi= ce.rs index 3f1acb6818a5..78d239b26dcc 100644 --- a/samples/rust/rust_misc_device.rs +++ b/samples/rust/rust_misc_device.rs @@ -157,6 +157,7 @@ struct RustMiscDevice { #[vtable] impl MiscDevice for RustMiscDevice { type Ptr =3D Pin>; + type ThisModule =3D THIS_MODULE; =20 fn open(_file: &File, misc: &MiscDeviceRegistration) -> Result>> { let dev =3D ARef::from(misc.device()); --=20 2.43.0 From nobody Sun Feb 8 02:41:07 2026 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AA3C257448 for ; Thu, 1 Jan 2026 05:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244916; cv=none; b=Gjf+EhJqGQpTn3+GGSLgH3Mkg2PcAixXURhvqhceEoYGjAd0kiVUO/KrJ3g5DT5dhlSTrarXrIcQfXltl8RUQ1dUjHObFnvPL/LUfpPWGyTajuYwufJ0DBu8I50883NEhj2+P0bdyDdJP90rOBq0wkqY07HF+s/ytwofaGVfMU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244916; c=relaxed/simple; bh=7rhNZKoiKt69rXYOx/nPj8NyhjOaV5my4mHPW2W+MJo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X8V+cj0cjeKOUoNSBu3f9A+KMM+F3pxcIulOEThIr67U9YhflbwDbkBB02SXRwkj/x50j7ejw5dTn8E8o++hw61PedZBn3/rCABSEfrZhhMEwurJWJE+mmemN7aFLCjTD5GyqyvJNgLdALOR7apWLG+69EbNljXACYzYXPt/Fog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lr2pmb9f; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lr2pmb9f" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-37b95f87d64so88017351fa.2 for ; Wed, 31 Dec 2025 21:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244911; x=1767849711; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZnWuhRewCBtlepNlYLvDYAkJsMsIyPpraMiTNGgUITs=; b=lr2pmb9fBA3ugs/QR3Y2DjR/7jhhFex3Bml0m8fWx3JIlEE/Naj4CCVxWlbFOY5qSf 4xsINTZRn4KBLoC6EWlnV/FJdu+6fNEbdvkPPpwPMYWa+LKygDQK2iWWV9FVWg+RQgtx 2bWp5goviPCxIL9+m2T6KC4zxzmvi6kIQGreyl3kD2kDWjHEjZr1+TBU6rjBaCmU4Zrk oFkxvaaooR7/DOjrZmPFHWEmow+5xJLqXjQT9NHsMWdAX34K8fiMfI2AO6n6yoWLVNsD DVMi360hK39YLVb8Oo88j+nlXyvZh3yeOlQtuUsmBFfd7ubmHBvukKn/QdrbVxT7VunQ 5fdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244911; x=1767849711; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ZnWuhRewCBtlepNlYLvDYAkJsMsIyPpraMiTNGgUITs=; b=XPm2dKOEG5BJ5qGnraDeICucgSL6fwavjm9rBhTuP5spj1J4brKlthVdLnzQomfQj6 my3AsyFCI9+cpL/GvR0PV76NrR0RzvP3+nXGXsObGBJ0W1HQ9SjMQhy+YRpGCWxgko3m J/IziP1jwbOeRgIIsjtKX4UboY43dhZVB26b0jI7gCWWNG3DqfjdMLfFd/4HMmT2guyk HOJnHPZr/aUw6Ppz2HizINhMe74knytC4lZW+PEgS8s/h1TN1QQeVtHIDE6Hll5irht+ XjdyNfFnVnqgaoX4CiYosUutSOLEZNw9CHAod0+2JnBMQCBLrurqisXbg31mJW4cihLd ouxw== X-Forwarded-Encrypted: i=1; AJvYcCXW+tZmFMmTtQMuxXL2Y1h1ZHCE8VhoDVkf56zCL4Xxe0Oj3i+hf0u7Itgelo7+kplJcps9oF6L9RHy1Bk=@vger.kernel.org X-Gm-Message-State: AOJu0YxNNVCeG4jNNOkzPNlQ+NHZlfdrbyZq4OM7GNmfAl4m3cK57HX/ OTmRvZVIINu1UaCFlsDMllcHP3cGBSerRAWPrRMZN1EmsbjeLgyxM3Gf X-Gm-Gg: AY/fxX44iOe5QTITCO3nF2Hhd/T724pltIP+8Yk/ewn+kOj8pcn4dqo0jMvY/UCOubd SxUhbAuY2SQJFJz79LPdkKh6zkqFFs6PbVLMMWX990QEZ7+VWlURnXZSmhWITzlkTgehl6lq27K n3wfsQzWwhJjMBqw7vuk0zl7fFm1v9RyC3CnO8MYMgCjZ1fmI3fmPlZEBTKhntDZpXJfRiCIHRF 6ShQTT3EBdWe5dKVee7zSyki/t0Fk25eo5S1Q7Ewh9pv/wvCDPVueTBNemC7w3u9Mt9AWbNCGCp W7YmKsX5R2ItrtxoWFy8AWZXzxzQGHiJhGvZ6H01mKw1aHTnajYAQDT8wxeAjREqi+BRZ/UepqU Nzvu+HrfvkFt9H+TMUMsP7Bfj09/CXjQPkg7jG3OhGCgqPrJ2ElIwc5SUccvGrMjKMkhJ5umYr1 aJXVhmYRSwXkS/YF64Luas5rLBWef/cv0ZZRihmbg7MaAZYRQs5veRvG1Lkzs0URyvN3nJT3+rg W025C/y8qXlyeX1 X-Google-Smtp-Source: AGHT+IGWnxKTzBFDRvVhBJLkPNrg5zCvovKVt3Iq5ajcHW0NwDfpLyHHuTaAQOvw6Ai3P24W4z2g9Q== X-Received: by 2002:a05:651c:1443:b0:382:4d6b:993b with SMTP id 38308e7fff4ca-3824d6b9c18mr83313231fa.35.1767244910574; Wed, 31 Dec 2025 21:21:50 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:48 -0800 (PST) From: Kari Argillander Date: Thu, 01 Jan 2026 07:20:49 +0200 Subject: [PATCH RFC 5/6] rust: debugfs: WIP: Use owner for file_operations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-this_module_fix-v1-5-46ae3e5605a0@gmail.com> References: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> In-Reply-To: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> 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 , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=16426; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=7rhNZKoiKt69rXYOx/nPj8NyhjOaV5my4mHPW2W+MJo=; b=/FHxPndxLye7RpOlj19HW54w3416yImg7K+iPDUzBUCprQvFxJNDtczJD3uQwfT7CmWNxIUe6 6iglF8d4oCDCqSX4wSpusPl5a2PMwxaVFMFe5smUbzFzPC75Rg8FCPo X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= --- rust/kernel/debugfs.rs | 79 ++++++++++++++++++++++---------------= ---- rust/kernel/debugfs/file_ops.rs | 50 +++++++++++++++++++------- samples/rust/rust_debugfs.rs | 6 ++-- 3 files changed, 83 insertions(+), 52 deletions(-) diff --git a/rust/kernel/debugfs.rs b/rust/kernel/debugfs.rs index facad81e8290..03e22b1cfa2b 100644 --- a/rust/kernel/debugfs.rs +++ b/rust/kernel/debugfs.rs @@ -6,7 +6,8 @@ //! C header: [`include/linux/debugfs.h`](srctree/include/linux/debugfs.h) =20 // When DebugFS is disabled, many parameters are dead. Linting for this is= n't helpful. -#![cfg_attr(not(CONFIG_DEBUG_FS), allow(unused_variables))] +// #![cfg_attr(not(CONFIG_DEBUG_FS), allow(unused_variables))] +#![allow(unused_variables)] =20 use crate::fmt; use crate::prelude::*; @@ -46,27 +47,31 @@ // able to refer to us. In this case, we need to silently fail. All future= child directories/files // will silently fail as well. #[derive(Clone)] -pub struct Dir(#[cfg(CONFIG_DEBUG_FS)] Option>>); +pub struct Dir( + #[cfg(CONFIG_DEBUG_FS)] Option>>, + PhantomData, +); =20 -impl Dir { +impl Dir { /// Create a new directory in DebugFS. If `parent` is [`None`], it wil= l be created at the root. - fn create(name: &CStr, parent: Option<&Dir>) -> Self { + fn create(name: &CStr, parent: Option<&Self>) -> Self { #[cfg(CONFIG_DEBUG_FS)] { let parent_entry =3D match parent { // If the parent couldn't be allocated, just early-return - Some(Dir(None)) =3D> return Self(None), - Some(Dir(Some(entry))) =3D> Some(entry.clone()), + Some(Self(None, _)) =3D> return Self(None, PhantomData), + Some(Self(Some(entry), _)) =3D> Some(entry.clone()), None =3D> None, }; Self( // If Arc creation fails, the `Entry` will be dropped, so = the directory will be // cleaned up. Arc::new(Entry::dynamic_dir(name, parent_entry), GFP_KERNE= L).ok(), + PhantomData, ) } #[cfg(not(CONFIG_DEBUG_FS))] - Self() + Self(PhantomData) } =20 /// Creates a DebugFS file which will own the data produced by the ini= tializer provided in @@ -107,7 +112,7 @@ fn create_file<'a, T, E: 'a>( /// let debugfs =3D Dir::new(c_str!("parent")); /// ``` pub fn new(name: &CStr) -> Self { - Dir::create(name, None) + Self::create(name, None) } =20 /// Creates a subdirectory within this directory. @@ -121,7 +126,7 @@ pub fn new(name: &CStr) -> Self { /// let child =3D parent.subdir(c_str!("child")); /// ``` pub fn subdir(&self, name: &CStr) -> Self { - Dir::create(name, Some(self)) + Self::create(name, Some(self)) } =20 /// Creates a read-only file in this directory. @@ -149,7 +154,7 @@ pub fn read_only_file<'a, T, E: 'a>( where T: Writer + Send + Sync + 'static, { - let file_ops =3D &>::FILE_OPS; + let file_ops =3D &>::FILE_OPS; self.create_file(name, data, file_ops) } =20 @@ -176,7 +181,7 @@ pub fn read_binary_file<'a, T, E: 'a>( where T: BinaryWriter + Send + Sync + 'static, { - self.create_file(name, data, &T::FILE_OPS) + self.create_file(name, data, &>::FILE_OP= S) } =20 /// Creates a read-only file in this directory, with contents from a c= allback. @@ -215,7 +220,7 @@ pub fn read_callback_file<'a, T, E: 'a, F>( T: Send + Sync + 'static, F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync, { - let file_ops =3D >::FILE_OPS.adapt(); + let file_ops =3D as ReadFile>>::FILE_OPS.adapt(); self.create_file(name, data, file_ops) } =20 @@ -231,7 +236,7 @@ pub fn read_write_file<'a, T, E: 'a>( where T: Writer + Reader + Send + Sync + 'static, { - let file_ops =3D &>::FILE_OPS; + let file_ops =3D &>::FILE_OPS; self.create_file(name, data, file_ops) } =20 @@ -247,7 +252,7 @@ pub fn read_write_binary_file<'a, T, E: 'a>( where T: BinaryWriter + BinaryReader + Send + Sync + 'static, { - let file_ops =3D &>::FILE_OPS; + let file_ops =3D &>::FILE_OPS; self.create_file(name, data, file_ops) } =20 @@ -270,7 +275,7 @@ pub fn read_write_callback_file<'a, T, E: 'a, F, W>( W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync, { let file_ops =3D - , W> as file_ops::ReadWrit= eFile<_>>::FILE_OPS + , W> as file_ops::ReadWrit= eFile>::FILE_OPS .adapt() .adapt(); self.create_file(name, data, file_ops) @@ -290,7 +295,7 @@ pub fn write_only_file<'a, T, E: 'a>( where T: Reader + Send + Sync + 'static, { - self.create_file(name, data, &T::FILE_OPS) + self.create_file(name, data, &>::FILE_OPS) } =20 /// Creates a write-only binary file in this directory. @@ -307,7 +312,7 @@ pub fn write_binary_file<'a, T, E: 'a>( where T: BinaryReader + Send + Sync + 'static, { - self.create_file(name, data, &T::FILE_OPS) + self.create_file(name, data, &>::FILE_O= PS) } =20 /// Creates a write-only file in this directory, with write logic from= a callback. @@ -324,7 +329,7 @@ pub fn write_callback_file<'a, T, E: 'a, W>( T: Send + Sync + 'static, W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync, { - let file_ops =3D , W> as WriteFile<_>>= ::FILE_OPS + let file_ops =3D , W> as WriteFile>::FILE_OPS .adapt() .adapt(); self.create_file(name, data, file_ops) @@ -527,7 +532,7 @@ fn create_file(&self, name: &CStr, data: &'dat= a T, vtable: &'static Fil /// file is removed when the [`Scope`] that this directory belongs /// to is dropped. pub fn read_only_file(&self, name: = &CStr, data: &'data T) { - self.create_file(name, data, &T::FILE_OPS) + // self.create_file(name, data, &>::FILE_OPS) } =20 /// Creates a read-only binary file in this directory. @@ -541,7 +546,7 @@ pub fn read_binary_file>::FILE_OPS) } =20 /// Creates a read-only file in this directory, with contents from a c= allback. @@ -560,8 +565,8 @@ pub fn read_callback_file(&self, name: &CStr, dat= a: &'data T, _f: &'static T: Send + Sync + 'static, F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync, { - let vtable =3D as ReadFile<_>>::FILE_OPS.adap= t(); - self.create_file(name, data, vtable) + // let vtable =3D as ReadFile>::FILE_OP= S.adapt(); + // self.create_file(name, data, vtable) } =20 /// Creates a read-write file in this directory. @@ -577,8 +582,8 @@ pub fn read_write_file( name: &CStr, data: &'data T, ) { - let vtable =3D &>::FILE_OPS; - self.create_file(name, data, vtable) + // let vtable =3D &>::FILE_OPS; + // self.create_file(name, data, vtable) } =20 /// Creates a read-write binary file in this directory. @@ -593,8 +598,8 @@ pub fn read_write_binary_file>::FILE_OPS; - self.create_file(name, data, vtable) + // let vtable =3D &>::FILE_OPS; + // self.create_file(name, data, vtable) } =20 /// Creates a read-write file in this directory, with logic from callb= acks. @@ -618,10 +623,10 @@ pub fn read_write_callback_file( F: Fn(&T, &mut fmt::Formatter<'_>) -> fmt::Result + Send + Sync, W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync, { - let vtable =3D , W> as ReadWri= teFile<_>>::FILE_OPS - .adapt() - .adapt(); - self.create_file(name, data, vtable) + // let vtable =3D , W> as Read= WriteFile<_>>::FILE_OPS + // .adapt() + // .adapt(); + // self.create_file(name, data, vtable) } =20 /// Creates a write-only file in this directory. @@ -632,8 +637,8 @@ pub fn read_write_callback_file( /// file is removed when the [`Scope`] that this directory belongs /// to is dropped. pub fn write_only_file(&self, name:= &CStr, data: &'data T) { - let vtable =3D &>::FILE_OPS; - self.create_file(name, data, vtable) + // let vtable =3D &>::FILE_OPS; + // self.create_file(name, data, vtable) } =20 /// Creates a write-only binary file in this directory. @@ -647,7 +652,7 @@ pub fn write_binary_file( name: &CStr, data: &'data T, ) { - self.create_file(name, data, &T::FILE_OPS) + // self.create_file(name, data, &>::FILE_OPS) } =20 /// Creates a write-only file in this directory, with write logic from= a callback. @@ -665,10 +670,10 @@ pub fn write_only_callback_file(&self, name: &C= Str, data: &'data T, _w: &' T: Send + Sync + 'static, W: Fn(&T, &mut UserSliceReader) -> Result + Send + Sync, { - let vtable =3D &, W> as WriteFile<_>>:= :FILE_OPS - .adapt() - .adapt(); - self.create_file(name, data, vtable) + // let vtable =3D &, W> as WriteFile<_= >>::FILE_OPS + // .adapt() + // .adapt(); + // self.create_file(name, data, vtable) } =20 fn empty() -> Self { diff --git a/rust/kernel/debugfs/file_ops.rs b/rust/kernel/debugfs/file_ops= .rs index 8a0442d6dd7a..0e5059c044af 100644 --- a/rust/kernel/debugfs/file_ops.rs +++ b/rust/kernel/debugfs/file_ops.rs @@ -115,13 +115,14 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Res= ult { } =20 // Work around lack of generic const items. -pub(crate) trait ReadFile { +pub(crate) trait ReadFile { const FILE_OPS: FileOps; } =20 -impl ReadFile for T { +impl ReadFile for T { const FILE_OPS: FileOps =3D { let operations =3D bindings::file_operations { + owner: M::OWNER.as_ptr(), read: Some(bindings::seq_read), llseek: Some(bindings::seq_lseek), release: Some(bindings::single_release), @@ -167,13 +168,18 @@ fn read(data: &T, buf: *const c_cha= r, count: usize) -> isize { } =20 // A trait to get the file operations for a type. -pub(crate) trait ReadWriteFile { +pub(crate) trait ReadWriteFile { const FILE_OPS: FileOps; } =20 -impl ReadWriteFile for T { +impl ReadWriteFile for T +where + M: ThisModule, + T: Writer + Reader + Sync, +{ const FILE_OPS: FileOps =3D { let operations =3D bindings::file_operations { + owner: M::OWNER.as_ptr(), open: Some(writer_open::), read: Some(bindings::seq_read), write: Some(write::), @@ -225,13 +231,18 @@ impl ReadWriteFile for = T { read(data, buf, count) } =20 -pub(crate) trait WriteFile { +pub(crate) trait WriteFile { const FILE_OPS: FileOps; } =20 -impl WriteFile for T { +impl WriteFile for T +where + M: ThisModule, + T: Reader + Sync, +{ const FILE_OPS: FileOps =3D { let operations =3D bindings::file_operations { + owner: M::OWNER.as_ptr(), open: Some(write_only_open), write: Some(write_only_write::), llseek: Some(bindings::noop_llseek), @@ -278,13 +289,18 @@ extern "C" fn blob_read( } =20 /// Representation of [`FileOps`] for read only binary files. -pub(crate) trait BinaryReadFile { +pub(crate) trait BinaryReadFile { const FILE_OPS: FileOps; } =20 -impl BinaryReadFile for T { +impl BinaryReadFile for T +where + M: ThisModule, + T: BinaryWriter + Sync, +{ const FILE_OPS: FileOps =3D { let operations =3D bindings::file_operations { + owner: M::OWNER.as_ptr(), read: Some(blob_read::), llseek: Some(bindings::default_llseek), open: Some(bindings::simple_open), @@ -333,13 +349,18 @@ extern "C" fn blob_write( } =20 /// Representation of [`FileOps`] for write only binary files. -pub(crate) trait BinaryWriteFile { +pub(crate) trait BinaryWriteFile { const FILE_OPS: FileOps; } =20 -impl BinaryWriteFile for T { +impl BinaryWriteFile for T +where + M: ThisModule, + T: BinaryReader + Sync, +{ const FILE_OPS: FileOps =3D { let operations =3D bindings::file_operations { + owner: M::OWNER.as_ptr(), write: Some(blob_write::), llseek: Some(bindings::default_llseek), open: Some(bindings::simple_open), @@ -358,13 +379,18 @@ impl BinaryWriteFile for T= { } =20 /// Representation of [`FileOps`] for read/write binary files. -pub(crate) trait BinaryReadWriteFile { +pub(crate) trait BinaryReadWriteFile { const FILE_OPS: FileOps; } =20 -impl BinaryReadWriteFile for T { +impl BinaryReadWriteFile for T +where + M: ThisModule, + T: BinaryWriter + BinaryReader + Sync, +{ const FILE_OPS: FileOps =3D { let operations =3D bindings::file_operations { + owner: M::OWNER.as_ptr(), read: Some(blob_read::), write: Some(blob_write::), llseek: Some(bindings::default_llseek), diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs index 025e8f9d12de..85c3f93159fd 100644 --- a/samples/rust/rust_debugfs.rs +++ b/samples/rust/rust_debugfs.rs @@ -54,7 +54,7 @@ struct RustDebugFs { pdev: ARef, // As we only hold these for drop effect (to remove the directory/file= s) we have a leading // underscore to indicate to the compiler that we don't expect to use = this field directly. - _debugfs: Dir, + _debugfs: Dir, #[pin] _compatible: File, #[pin] @@ -124,11 +124,11 @@ fn probe( } =20 impl RustDebugFs { - fn build_counter(dir: &Dir) -> impl PinInit>> + '_ { + fn build_counter(dir: &Dir) -> impl PinInit>> + '_ { dir.read_write_file(c_str!("counter"), Atomic::::new(0)) } =20 - fn build_inner(dir: &Dir) -> impl PinInit>> + '_ { + fn build_inner(dir: &Dir) -> impl PinInit>> + '_ { dir.read_write_file(c_str!("pair"), new_mutex!(Inner { x: 3, y: 10= })) } =20 --=20 2.43.0 From nobody Sun Feb 8 02:41:07 2026 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FADF25B1DA for ; Thu, 1 Jan 2026 05:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244920; cv=none; b=N066i50/0JK07pkBQZcGcrIywn2Z0WJHCRcDoiwkmnlWM4/JqXEFKFjxaKqEysgF3oGg/TBmzjkP2kJ7Pj/m83bRq7fwUYA6PXp5IeY9ovwxzsvhF0cCAT6535UnoyNOYnsQ4kXKMWDoiqvQMMMNkrlkjzMX0hO0dB8LPkqrpmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244920; c=relaxed/simple; bh=KJQ4jpYSGm/3nhZ2nBbnbAiByofjpfGBkERW9T5CzMA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oynhBpqpbeJPQNkK1XaZTEHfJGJuzEpvhM9V7A4F5sbr2UDvjtbQtRjnfW92hty46RlzQ4wnhPl3/nYdFYFmLq7qb/uHNS1nhMszuYT8i3EOig9m5fC1qbTCPVf+uaiaMIyTXkpJcwrqZafhOM9KtpD4CNV/t5CSbJ2BeGqRJO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W8SfiUOG; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W8SfiUOG" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3825ae23d95so37403411fa.0 for ; Wed, 31 Dec 2025 21:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244915; x=1767849715; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MCtaSXGPRcSbvYyqIPMnOeQLbklJUshA1S2PP0SMOWU=; b=W8SfiUOGab+mVjvrfzk/33yX079OgglDKXsquQVI4bjSwr+NAIphOQ0dPWEtcKwQKV r9dTZCKw6pGWEFFXMx94XhpTfWhzQxpRm6XioKypGjKEwBN8iLy5T47VmVhUnJhJkQtO NcKB4R2tZ8xKqChT2UM4L73ojVXqVowPSooi3o38YYfX6iLdZJmouPQtzNyDJKK+z7/U 0iEkcoq3an+DuQJsqdR35jpX/vF+D3kf3lzaBFqm3J1z0hmF/3tjv0fu75O/ZnHIeB86 /nLMvgzM1NjXKUdz3deG9NXgRCVNitauHN0OLSDh5z/r9fP98m+A7+SKpbOnd4gNsOW0 mAtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244915; x=1767849715; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=MCtaSXGPRcSbvYyqIPMnOeQLbklJUshA1S2PP0SMOWU=; b=s4V678y0YIs8ACzu37uruhUFTWpfhMb6HbrZRB6O9tnElBmpecjLQKwGjwUu1jtwSX lUmNxSYRlJ9kdHsGyWqhISa7wtuCaoe3Ermr1ymIPE2pkaXTVEiErQNznlmrnzaZwaAR V/epRghLs2bolms4c/Yg44+X4dA9FuIbyFKuEqAcNEysieu7e5Z6f4JGhubbiYNw+g3F y7Hkyt1zaoFdwaemNSkwXSo8dDBStyLNMuo5DqdJhvM2uPYRB06kiAOB8s75PTAxrRy1 HR0Do5m7rSihOtStqmuzKE/KR3INtJSHF1iw+vhAkCvea9f09IWOYFkPvIiKx3r8ig0w 4zcQ== X-Forwarded-Encrypted: i=1; AJvYcCUYnXZbcaoVtzGKvUEYrEixtYM4R1Qo6/U2EjDVHX+KTYyex9EAYlczBJdsVqt8KH0YJ75mfn4REePx67Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxrTiFq6XnXYtqvB42TacDnmlZYGH7jE6PrUxjnQ34co96XI5B9 lyWgVpnSdsN3gK7iSvyKndBE9oVb4Iqrggi5eLKBgkLt4m+4TpQNqUoo X-Gm-Gg: AY/fxX4mM7xdEKGW5gs+STywk3YASajNBSYBboIORg6qNC3iRwzvg5+MdK2b41GS/DK y/y1pCahNP0mahanIaofLjJHSSNtTuEzdrkqnuEmG/6Z95wH0cfFSanfx3tWuZz7W4prvdhPfqS p6Xafumn4agtZiS+TixPXpB4+gf3tpAy/rKIv1WDEUro7ylhVYjfh/Ogh9sF9VvjfcVR0toXv8H 1oLdUN/14pXrsu/jPd5Q7iujRji0x+5g4oFup5RNg1aelxdiRNwTJzwRyH6JpZl7QzAXhpIkGOf vUVXqmsGnsfdEUvrelVno63pbVDOFAWPtkFXmgG94cvUuVyFxW0QSN7iH+Rf1NcbgWNX/g4TWyQ Z89CGzbViLRFJBdGMT4JM1Q40uahxZd6eOWplA1F8JelDJnsXQzAlXd8jLk6nb57Dgq6DB5gR7P eAXlo3KjLYjjlJFIRxexw8BSAxzPncZ9l5rwp9rw7R+uPaugeHQKVpJgA9tkVaJwucYsmoFmqJg UM9iA== X-Google-Smtp-Source: AGHT+IE44rsnY6ipPrk3/J7X1yUoLY5WMocdogdmnIRKh23tOr7xkmlRQ6aQFRsTEn6UW4FJGOVNiA== X-Received: by 2002:a2e:a993:0:b0:382:b559:8336 with SMTP id 38308e7fff4ca-382b55983b4mr984331fa.22.1767244915067; Wed, 31 Dec 2025 21:21:55 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:53 -0800 (PST) From: Kari Argillander Date: Thu, 01 Jan 2026 07:20:50 +0200 Subject: [PATCH RFC 6/6] rust: WIP: Replace ModuleMetadata with THIS_MODULE Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-this_module_fix-v1-6-46ae3e5605a0@gmail.com> References: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> In-Reply-To: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> 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 , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=13418; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=KJQ4jpYSGm/3nhZ2nBbnbAiByofjpfGBkERW9T5CzMA=; b=gFUZ/58AraibpqH01HqbZhQb+XNzgNCXh3sNTjmMWxdx2lrddwUWZPbsMGPtHuo9cNjvK7Gnk 08Orxt2elZ7CXFWUsZAPrZSWyFOPO4sQv3P7Qixgg1aPs6qOQRb92/+ X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= ModuleMetadata seems redudant after we have prober THIS_MODULE. --- drivers/gpu/nova-core/nova_core.rs | 2 +- rust/kernel/auxiliary.rs | 10 +++++++--- rust/kernel/driver.rs | 10 ++++------ rust/kernel/firmware.rs | 2 +- rust/kernel/i2c.rs | 4 ++-- rust/kernel/lib.rs | 8 ++------ rust/kernel/pci.rs | 6 +++--- rust/kernel/platform.rs | 4 ++-- rust/kernel/usb.rs | 6 +++--- rust/macros/module.rs | 13 +++++++------ samples/rust/rust_driver_auxiliary.rs | 6 +++--- 11 files changed, 35 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nov= a_core.rs index b98a1c03f13d..fbfbcc9446c0 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -19,7 +19,7 @@ mod util; mod vbios; =20 -pub(crate) const MODULE_NAME: &kernel::str::CStr =3D ::NAME; +pub(crate) const MODULE_NAME: &kernel::str::CStr =3D THIS_MODULE::name(); =20 kernel::module_pci_driver! { type: driver::NovaCore, diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs index 323074322505..bd064b677c05 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -27,10 +27,10 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::auxiliary_driver; =20 - unsafe fn register(adrv: &Opaque, name: = &'static CStr) -> Result { + unsafe fn register(adrv: &Opaque) -> Res= ult { // SAFETY: It's safe to set the fields of `struct auxiliary_driver= ` on initialization. unsafe { - (*adrv.get()).name =3D name.as_char_ptr(); + (*adrv.get()).name =3D M::NAME.as_char_ptr(); (*adrv.get()).probe =3D Some(Self::probe_callback); (*adrv.get()).remove =3D Some(Self::remove_callback); (*adrv.get()).id_table =3D T::ID_TABLE.as_ptr(); @@ -38,7 +38,11 @@ unsafe fn register(adrv: &Opaque, name: &'static C =20 // SAFETY: `adrv` is guaranteed to be a valid `RegType`. to_result(unsafe { - bindings::__auxiliary_driver_register(adrv.get(), M::OWNER.as_= ptr(), name.as_char_ptr()) + bindings::__auxiliary_driver_register( + adrv.get(), + M::OWNER.as_ptr(), + M::NAME.as_char_ptr(), + ) }) } =20 diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index 7c4ad24bb48a..5bb029075a57 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -118,7 +118,7 @@ pub unsafe trait RegistrationOps { /// /// On success, `reg` must remain pinned and valid until the matching = call to /// [`RegistrationOps::unregister`]. - unsafe fn register(reg: &Opaque, name: &= 'static CStr) -> Result; + unsafe fn register(reg: &Opaque) -> Resu= lt; =20 /// Unregisters a driver previously registered with [`RegistrationOps:= :register`]. /// @@ -151,7 +151,7 @@ unsafe impl Send for Registration {} =20 impl Registration { /// Creates a new instance of the registration object. - pub fn new(name: &'static CStr) -> impl PinInit { + pub fn new() -> impl PinInit { try_pin_init!(Self { reg <- Opaque::try_ffi_init(|ptr: *mut T::RegType| { // SAFETY: `try_ffi_init` guarantees that `ptr` is valid f= or write. @@ -162,7 +162,7 @@ pub fn new(name: &'static CStr) -> impl = PinInit { let drv =3D unsafe { &*(ptr as *const Opaque) = }; =20 // SAFETY: `drv` is guaranteed to be pinned until `T::unre= gister`. - unsafe { T::register::(drv, name) } + unsafe { T::register::(drv) } }), }) } @@ -195,9 +195,7 @@ struct DriverModule { impl $crate::InPlaceModule for DriverModule { fn init() -> impl ::pin_init::PinInit= { $crate::try_pin_init!(Self { - _driver <- $crate::driver::Registration::new::( - ::NAME, - ), + _driver <- $crate::driver::Registration::new::(), }) } } diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs index 71168d8004e2..254b5c6b64af 100644 --- a/rust/kernel/firmware.rs +++ b/rust/kernel/firmware.rs @@ -206,7 +206,7 @@ macro_rules! module_firmware { const __MODULE_FIRMWARE_PREFIX: &'static $crate::str::CStr =3D= if cfg!(MODULE) { c"" } else { - ::NAME + THIS_MODULE::name() }; =20 #[link_section =3D ".modinfo"] diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index bc154506b16f..31db4d45bab1 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -97,7 +97,7 @@ macro_rules! i2c_device_table { unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::i2c_driver; =20 - unsafe fn register(idrv: &Opaque, name: = &'static CStr) -> Result { + unsafe fn register(idrv: &Opaque) -> Res= ult { build_assert!( T::ACPI_ID_TABLE.is_some() || T::OF_ID_TABLE.is_some() || T::I= 2C_ID_TABLE.is_some(), "At least one of ACPI/OF/Legacy tables must be present when re= gistering an i2c driver" @@ -120,7 +120,7 @@ unsafe fn register(idrv: &Opaque, name: &'static C =20 // SAFETY: It's safe to set the fields of `struct i2c_client` on i= nitialization. unsafe { - (*idrv.get()).driver.name =3D name.as_char_ptr(); + (*idrv.get()).driver.name =3D M::NAME.as_char_ptr(); (*idrv.get()).probe =3D Some(Self::probe_callback); (*idrv.get()).remove =3D Some(Self::remove_callback); (*idrv.get()).shutdown =3D Some(Self::shutdown_callback); diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6d4563662a02..3bae80a949d2 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -199,12 +199,6 @@ fn init() -> impl pin_init::PinInit { } } =20 -/// Metadata attached to a [`Module`] or [`InPlaceModule`]. -pub trait ModuleMetadata { - /// The name of the module as specified in the `module!` macro. - const NAME: &'static crate::str::CStr; -} - pub mod this_module { //! TODO //! @@ -224,6 +218,8 @@ pub mod this_module { pub trait ThisModule { /// TODO Doc const OWNER: ModuleWrapper; + /// TODO Doc + const NAME: &'static kernel::str::CStr; } =20 /// See [`this_module`] diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 792560ca8020..b043d7a388d0 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -54,10 +54,10 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::pci_driver; =20 - unsafe fn register(pdrv: &Opaque, name: = &'static CStr) -> Result { + unsafe fn register(pdrv: &Opaque) -> Res= ult { // SAFETY: It's safe to set the fields of `struct pci_driver` on i= nitialization. unsafe { - (*pdrv.get()).name =3D name.as_char_ptr(); + (*pdrv.get()).name =3D M::NAME.as_char_ptr(); (*pdrv.get()).probe =3D Some(Self::probe_callback); (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).id_table =3D T::ID_TABLE.as_ptr(); @@ -65,7 +65,7 @@ unsafe fn register(pdrv: &Opaque, name: &'static C =20 // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. to_result(unsafe { - bindings::__pci_register_driver(pdrv.get(), M::OWNER.as_ptr(),= name.as_char_ptr()) + bindings::__pci_register_driver(pdrv.get(), M::OWNER.as_ptr(),= M::NAME.as_char_ptr()) }) } =20 diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 67d46231600e..27f196a140e5 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -30,7 +30,7 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::platform_driver; =20 - unsafe fn register(pdrv: &Opaque, name: = &'static CStr) -> Result { + unsafe fn register(pdrv: &Opaque) -> Res= ult { let of_table =3D match T::OF_ID_TABLE { Some(table) =3D> table.as_ptr(), None =3D> core::ptr::null(), @@ -43,7 +43,7 @@ unsafe fn register(pdrv: &Opaque, name: &'static C =20 // SAFETY: It's safe to set the fields of `struct platform_driver`= on initialization. unsafe { - (*pdrv.get()).driver.name =3D name.as_char_ptr(); + (*pdrv.get()).driver.name =3D M::NAME.as_char_ptr(); (*pdrv.get()).probe =3D Some(Self::probe_callback); (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).driver.of_match_table =3D of_table; diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index c6ee98d12875..43259307986f 100644 --- a/rust/kernel/usb.rs +++ b/rust/kernel/usb.rs @@ -31,10 +31,10 @@ unsafe impl driver::RegistrationOps for Adapter { type RegType =3D bindings::usb_driver; =20 - unsafe fn register(udrv: &Opaque, name: = &'static CStr) -> Result { + unsafe fn register(udrv: &Opaque) -> Res= ult { // SAFETY: It's safe to set the fields of `struct usb_driver` on i= nitialization. unsafe { - (*udrv.get()).name =3D name.as_char_ptr(); + (*udrv.get()).name =3D M::NAME.as_char_ptr(); (*udrv.get()).probe =3D Some(Self::probe_callback); (*udrv.get()).disconnect =3D Some(Self::disconnect_callback); (*udrv.get()).id_table =3D T::ID_TABLE.as_ptr(); @@ -42,7 +42,7 @@ unsafe fn register(udrv: &Opaque, name: &'static C =20 // SAFETY: `udrv` is guaranteed to be a valid `RegType`. to_result(unsafe { - bindings::usb_register_driver(udrv.get(), M::OWNER.as_ptr(), n= ame.as_char_ptr()) + bindings::usb_register_driver(udrv.get(), M::OWNER.as_ptr(), M= ::NAME.as_char_ptr()) }) } =20 diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 6b8753d122cc..6a1ce6435e8f 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -375,6 +375,13 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { #[allow(non_camel_case_types)] pub struct THIS_MODULE; =20 + impl THIS_MODULE {{ + /// Returns the name of this module. + pub const fn name() -> &'static ::kernel::str::CStr {{ + c\"{name}\" + }} + }} + impl ::kernel::prelude::ThisModule for THIS_MODULE {{ #[cfg(not(MODULE))]=20 const OWNER: ::kernel::this_module::ModuleWrapper =3D unsa= fe {{ @@ -392,13 +399,7 @@ impl ::kernel::prelude::ThisModule for THIS_MODULE {{ =20 ::kernel::this_module::ModuleWrapper::from_ptr(__this_= module.get()) }}; - }} - - /// The `LocalModule` type is the type of the module created b= y `module!`, - /// `module_pci_driver!`, `module_platform_driver!`, etc. - type LocalModule =3D {type_}; =20 - impl ::kernel::ModuleMetadata for {type_} {{ const NAME: &'static ::kernel::str::CStr =3D c\"{name}\"; }} =20 diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index e996dca19454..2f77b0873e81 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -18,7 +18,7 @@ use core::any::TypeId; use pin_init::PinInit; =20 -const MODULE_NAME: &CStr =3D ::NAME; +const MODULE_NAME: &CStr =3D THIS_MODULE::name(); const AUXILIARY_NAME: &CStr =3D c_str!("auxiliary"); =20 struct AuxiliaryDriver; @@ -113,8 +113,8 @@ struct SampleModule { impl InPlaceModule for SampleModule { fn init() -> impl PinInit { try_pin_init!(Self { - _pci_driver <- driver::Registration::new::(MODULE_NAME), - _aux_driver <- driver::Registration::new::(MODULE_NAME), + _pci_driver <- driver::Registration::new::(), + _aux_driver <- driver::Registration::new::(), }) } } --=20 2.43.0