From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 1047423F42D for ; Tue, 6 Jan 2026 16:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715991; cv=none; b=XMiZBYOx++OsI8vUTyvqDCgJ2TUt08KBsbGIH7iO7bB2mMruG3J1mIPCX2yrFr5oLkVxYlcd3vdbEjqpkJhqxDswkI1CvPe/QAVrevB9nwBmWkbW2fMGXep6gKFsJ8Gmqi+nAAo88eV75h061qVGN5xgJGtlS55Rtx62Pi0oXuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715991; c=relaxed/simple; bh=NbSZJOFudokz6C+njmD0VOJLlYmt/34Y4GRpm6Ry5SM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TnJvjdEbnUFYj+rQZUgS+JyZxI9p8B1KwJEwN46RHTSdOQZtp1YlzAlbIj3GE/3e9iGniknjbOStz4R5QWZpMhrDIDsH/Ggd3Ty2fhJwObgaTAPeaY5x/rMndrH8tR4Qz7OTHjjYzk68qghyDJ+Whn7Iy5UX+NQCVOJb1+cHA0w= 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=TVUmsUD0; arc=none smtp.client-ip=209.85.208.178 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="TVUmsUD0" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-37a3a4d3d53so13716111fa.3 for ; Tue, 06 Jan 2026 08:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715988; x=1768320788; 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=hJEsrOJPO59o/eeH09HtsmYQCeq/k0b3qKzFe+dbMbk=; b=TVUmsUD080N+VrEELv+AkezLiDaQ6Otrk1yY8QOuSjHSZ0ZqqSxIioidlP7yDfI9Vp bgI1E6XOWA7aveE1+I/Pe38MlHLIuZrKmoKrjt2uyrI59zoGjOOzSWvY0QHFnmqvZrjF +8s9p68R0Kfjy3+LxwGR35xMS80s6ciB6TQliS3TIlK1tiY8EtFlmvexq2GVKqIWV0aQ 6VsyntkP3duobEpnjX34tceKtYbUCNhxX3v4uqwsYgWZVe915ZAeQvYePAX6C/arjC8+ yaP6ccsQLK4TXPH9d43rmNtl4xGAkgv8yMcmHRW/iwYc4W4eyjaqZN6MCIxRMzm4dHe+ bNRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715988; x=1768320788; 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=hJEsrOJPO59o/eeH09HtsmYQCeq/k0b3qKzFe+dbMbk=; b=ZzPDghHEj1oVVDf9MuQXPL7MuW22koI0gFjKFUT94EJPqlTtUWksIvtORGHQ3F8tv/ CenWMYcJEOSQtHQmmUef/EihulaxKFq47nK9jtUz4OG4OMXdhE7kHJA2iRnnzbHVdqkY vrFSW+4Jny0YPBfRSimIUS07BB7+pknT7ekCbMHrzqb4jgnYJXPPza++CDKzGEYtegyw /seG+0tqiHl/yvSjNtIM/l0+9C2E7kVCBT3fCf6MECjUq9aNHNQ3rh+qMm31j6zPzNGo Gj4+Ryd8HCthV1I1043fjtE4FEpMvLfHOseHXtzlhtwTbnTgfVWkGaNAiXeo/Qtl4xRf NB7w== X-Forwarded-Encrypted: i=1; AJvYcCUVIMDKzZ7TuRje2pjFj+1OOy6dkBDu71lKL+mB0tdvrxW3KKm3UdHbzvIFjn+WwN0roHqhAE/8ugq8VYA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywfed1ZUq/9eHwYNCStOVVpSmLQGQwWou/GqrceQ1vYcrx/I1VP HnT9a3k+Zy1HfkiEKTXZQN3E/ri+TLmyuWUAtpUaviAE0Y3hMVDDZ5h6 X-Gm-Gg: AY/fxX4yV8/R9Vu1Bub+wzWlOrfewGqwduoHvyvjUOUNgFi2vhFM5hfETVrk7GpliIS ORiDtOBwihRNBuFfHF2qFUV5A0QX9VWAGtnMTRh9ruwMAU0ZvB0hr3/bgkzr2y9K53nMUUc5SVK Q/cGb0sSVUF5qirjTXBlQiktrvuBBrm9jyma4VVWlDlrQbiF+5RJAZDn4aHJwO/GMTHXYlxQw1x tjNVqVu8UORrTGEsEaLT1hn6R0SsPVFml2VT9lRkCQLvkOK318g3CitBHIAEryyhooYeP6TDly1 bfEKfpFwaCzrWFROXqSY8Ys2HEah1E9hxtPDddISkfg9cupTPkvKHnIgMR1lgVml1s1DD251skV Y+IInvmWs20XQBY2nKGQdL5yEdyXMxHhVJXMyZrXU8BJI8iFZ4jFPFCTPzvZ4+OsseXn98PtX7a DZ1fSFvF1yQnltYn397CzL03tPhX5h1/HqGC+vBm2zXDnrhUE9yS4q/CDE0yOT0QW8Uc47DVm0+ bD4Zg== X-Google-Smtp-Source: AGHT+IHKaBOSwm4vp1JX09Pd02uyRduDey+97mZMIBnf1kbFiov8dfuABleYNBj8DwXxWVRLUyVm9w== X-Received: by 2002:a05:651c:1542:b0:37a:2c11:2c5c with SMTP id 38308e7fff4ca-382eaae3114mr10488351fa.37.1767715987833; Tue, 06 Jan 2026 08:13:07 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:07 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:39 +0200 Subject: [PATCH RFC v2 01/11] 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: <20260106-this_module_fix-v2-1-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=837; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=NbSZJOFudokz6C+njmD0VOJLlYmt/34Y4GRpm6Ry5SM=; b=Gfhq34snEkIsncWb/32XzJ7mDnGJI9NzJRtuJ5elT9FOTK96SZFBM57vqx6E+sIWZvobIIJuP PN2M73QNsKNDRKn+ZIbZM0I884SvUA/BxyVpF2M3n+Jph1Hj6VPLvXV 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 6d637e2fed1b..510d4bfc7c2b 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 06:56:37 2026 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 0800E242D6A for ; Tue, 6 Jan 2026 16:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715994; cv=none; b=i8Kje2N+YbtTpo0iy6jbvFWagvGDAMUL8iJNWgnZX3l9A6rp/lH06a2JRs4JonPr2WL0pSderfDW9Lsaz5ArOSA6jN83ix/iruZOxVTqrEhUa/91c38QpRe9qJ7uRwRiRI2wfi5E8BrWo0T1SmkSU2UBNdtK6QC/y4b5+1kcJbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715994; c=relaxed/simple; bh=/Ms0ilmTmhT/+pTanvifPfpMypKbgHczZgI+jrgEiCU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R2wXIi/pY72WK6PnsONXTDZ7nE6IDU8nZSNN7PrOfoHiMzxtKRKcPYDpqXG45ZmzjzAacWqbCHSY0sBNjoMDn7jfEpgKd3C0ApDM+a2GJTXbaKCXef5DB4A4uJqwuJLEgyEBE6eLTPWUV+blEPM90FVdbpFJ8x3+kBu+5S7njUM= 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=lwiw2qGL; arc=none smtp.client-ip=209.85.208.169 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="lwiw2qGL" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-37bac34346dso8975971fa.2 for ; Tue, 06 Jan 2026 08:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715990; x=1768320790; 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=gDBwaX2tbeEhZrSwSpdBrEdEsO8lUCzTxea91t7m1AM=; b=lwiw2qGLxAngZQU7k6WuVQ6LPcoxhICXf6Nser9Y5SGkVXmk0jeEifxgMn6Mn+F9Q/ 4WwtIsDGlwEKTm1TpsYTQC20xTxHveT++jKLJP1OcRXfkwr71ed0dn6UU7cgVrf6GdyM uczK9C9iDU6BWRj/8hpcqBi5OrP/pPmJCN22nDwRlRHQhOCSrpQMh9sb4vMCaidJKXq3 1mJqyEP/rOJ+KL+R3pG4bFdQW8Bx56vwhAxDZLgMqLqpKf9E5YpRKJ4mE9EZc0aTRhcm Az8sF0DEZwTkM61/k7Dzs/Nga2Mni44OCVPVN3WkK1w087BSa8tn4n1oId6EVdwLqKC9 a0HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715990; x=1768320790; 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=gDBwaX2tbeEhZrSwSpdBrEdEsO8lUCzTxea91t7m1AM=; b=eTvXXq/0T0H9j3JyJ2z2wYJqx+NyETY3SfZestf7MLOcIWAR0dLhF9dqhgWMu1ku5W uD1MV3AxmmvIARz+wE4HmNig+YyEAcrvMN0ejm7/hWjgANuPsbcgExvmBHWC0GZY3u+r a0n/ABQxwU/K3VghIlIHnf9uy4TzhsBkIKla6eWMDFWdjWCMMiYEREp5f6bmPm4IRfn4 oZ10YlPp7VFr/qnNUoL8wQka5VY40Mwg2EHmbnTrcgK3rKWOPVfwB2RSSAFudfV0rMyv uwBY9dNOs8jkEixZ9kpNPE/0JzjboMO/PLh2BSnexHEeytjwT77FGEB4qlN43LnizFI6 oPQA== X-Forwarded-Encrypted: i=1; AJvYcCUhSwSfgtrKawytznmsZq3ac8nxXOWbq3Dx6UUOTw7gQUj5hIoH7AfNMyM+ZZnucKglxayGGhRKoWdkN80=@vger.kernel.org X-Gm-Message-State: AOJu0Yyu7BtCj+xNibZLXnc+omJbeX5bhvUXFFaK8nxh35JnwRMiRjUV hmVxlY0bG8ToeqDHaJ97H4CwVHyokhgOC/UVrwqoCWYd+L6jDjOipC/S X-Gm-Gg: AY/fxX4JpH0rfCCntsf9clJm30tJlDqNtUDAV99tAaUvleAoy5tcbyyYvHKYYHMaqN5 FMkCb6NQdxQDATsTJaDxjUaV/Cb18K6CMU/B7cj8Sh9Ud9xVhmRq7G7NVuQx2hv/T7nUQf1PhI5 /svxgYLgT0FBQe3nmQzLzpWb3cfT0XLlp9Sqlb5eImw3/cFivckvpdoEdXhcQjtAJE1ZPfhBASr lXeoIGG/KwOFagDIEZDZYVVKOU9ySoQZEMn/e4SdSw6ZQHgUym0UOXYnrbkQKx5MLdwMoEDRbIM 3hAtsVj+scjun2vYCAxLcTqp/BUW5ZcYVkqhDahQdsMXujqYG1sV9dJSQ5rsdaSkZMmAqG1+7Kp mf8QJ7NQMKxclISwvwTWFP5i87P8n8TsHmpr5ZwzJSIoV5Itawr9Qh1gGuhjMEx84KOjUtgci9+ oyxImIq5+w+AMaTFIxqY00LXFWeoaAqAeJIEqan4u1avv6sJhDqgUmxoSRjvlPkW+HiPyoNkhYy 1PsNw== X-Google-Smtp-Source: AGHT+IGRuC9x0JKm120kgdj5Px6SiSPfgvsaiYELSkLjYGdy8H5Bizj14zDJzMyXimu7DD0V6rf86A== X-Received: by 2002:a05:651c:50c:b0:37b:9615:e43a with SMTP id 38308e7fff4ca-382ea9f2dc6mr8741011fa.1.1767715989652; Tue, 06 Jan 2026 08:13:09 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:09 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:40 +0200 Subject: [PATCH RFC v2 02/11] rust: add new 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: <20260106-this_module_fix-v2-2-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=15432; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=/Ms0ilmTmhT/+pTanvifPfpMypKbgHczZgI+jrgEiCU=; b=VCF39GJJp1wwxCEZh6OVLtm+AKyLVcUz5twsoTod+rQGN3fE6N85Tcj4afu8q8Y/2rGR/8HwV 0VezZT6Bh+wDLrPTUcVyEVHc5BuWrNRBOZXrfGgU63KHQwTWcnHrQgz X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= To make clear separation between module crates and kernel crate we introduce ThisModule trait which is meant to be used by kernel space. THIS_MODULE is meant to be used by modules. So kernel create will be unable to even accidentally use THIS_MODULE. As ThisModule is trait we can pass that around in const context. This is needed so that we can read ownership information in const context when we create example file_operations structs for modules. New ThisModule will also eventually replace kernel::ModuleMetadata trait and for this reason it also have NAME field. To make transition smooth use mod this_module so we can have two ThisModule same time. Also some functionality is added to THIS_MODULE temporarily so that we do not have to change everything at once. Also examples will need THIS_MODULE so also define that in docs. Signed-off-by: Kari Argillander --- drivers/block/rnull/configfs.rs | 2 +- rust/kernel/configfs.rs | 46 ++++++------ rust/kernel/lib.rs | 159 ++++++++++++++++++++++++++++++++++++= ++++ rust/macros/module.rs | 16 +--- scripts/rustdoc_test_gen.rs | 2 + 5 files changed, 188 insertions(+), 37 deletions(-) diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs= .rs index 2f5a7da03af5..7223ee7c3032 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/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 466fb7f40762..908cb98d404f 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -110,16 +110,21 @@ //! [C documentation]: srctree/Documentation/filesystems/configfs.rst //! [`rust_configfs.rs`]: srctree/samples/rust/rust_configfs.rs =20 -use crate::alloc::flags; -use crate::container_of; -use crate::page::PAGE_SIZE; -use crate::prelude::*; -use crate::str::CString; -use crate::sync::Arc; -use crate::sync::ArcBorrow; -use crate::types::Opaque; -use core::cell::UnsafeCell; -use core::marker::PhantomData; +use crate::{ + alloc::flags, + container_of, + page::PAGE_SIZE, + prelude::*, + str::CString, + sync::Arc, + sync::ArcBorrow, + this_module::ThisModule, + types::Opaque, // +}; +use core::{ + cell::UnsafeCell, + marker::PhantomData, // +}; =20 /// A configfs subsystem. /// @@ -744,8 +749,7 @@ 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 @@ -754,7 +758,7 @@ pub const fn new_with_child_ctor( { Self { item_type: Opaque::new(bindings::config_item_type { - ct_owner: owner.as_ptr(), + ct_owner: TM::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 +769,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: TM::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(), @@ -875,8 +878,7 @@ fn as_ptr(&self) -> *const bindings::config_item_type { /// =3D kernel::configfs::ItemType::< /// configfs::Subsystem, /// Configuration -/// >::new_with_child_ctor::( -/// &THIS_MODULE, +/// >::new_with_child_ctor::( /// &CONFIGURATION_ATTRS /// ); /// @@ -1019,8 +1021,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 +1030,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/lib.rs b/rust/kernel/lib.rs index 510d4bfc7c2b..2ccd75f68f03 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -233,6 +233,165 @@ pub const fn as_ptr(&self) -> *mut bindings::module { } } =20 +pub mod this_module { + //! Access to the module identity and ownership information. + //! + //! This module provides the Rust equivalent of the kernel=E2=80=99s `= THIS_MODULE` + //! symbol from the [C API](srctree/include/linux/init.h). + //! + //! # For driver creators + //! + //! If you see ThisModule you need to pass THIS_NODULE for it so it can + //! track module ownership. + //! + //! Each Rust module defines its own `THIS_MODULE` using the + //! [`create_this_module`] macro. The generated `THIS_MODULE` identifi= es the + //! owning kernel module and expose some metadata about it. + //! + //! # For abstraction creators + //! + //! Many times C-apis expect a `struct module *` pointer so they can + //! increase the module reference count. This is because module could = be + //! unloaded while example file operations are in progress. Many times + //! structs which needs owner fields should also be const. For this re= ason + //! ThisModule is usually passes as a type parameter `TM` to abstracti= ons + //! which need to know the module owner. In vtables ThisModule is usua= lly + //! used as name. + //! + //! ## Example + //! + //! ``` + //! # use kernel::{bindings, this_module::ThisModule}; + //! # use core::marker::PhantomData; + //! + //! // Example function signature which needs ThisModule. + //! pub fn create_device() {} + //! + //! // Example of a vtable which uses ThisModule. + //! #[vtable] + //! pub trait MyStruct { + //! type ThisModule: ThisModule; + //! } + //! + //! pub(crate) struct MyStructVTable(PhantomData); + //! + //! impl MyStructVTable { + //! const FOPS: bindings::file_operations =3D bindings::file_opera= tions { + //! owner: T::ThisModule::OWNER.as_ptr(), + //! ..pin_init::zeroed() + //! }; + //! } + //! ``` + + /// See [`this_module`] + pub trait ThisModule { + /// Wrapper around the owning `struct module` pointer. + /// + /// This is null for built-in code and non-null for loadable modul= es. + const OWNER: ModuleWrapper; + /// Name of the module. + const NAME: &'static kernel::str::CStr; + } + + /// Wrapper around a pointer to `struct module`. + /// + /// This type exists as a workaround for the lack of `const fn` method= s in + /// traits. It allows the module pointer to be stored as an associated + /// constant while still providing a `const` accessor. + pub struct ModuleWrapper { + ptr: *mut bindings::module, + } + + 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 be used from [`create_this_module`]. + /// + /// # Safety + /// + /// - Only modules are allowed to create non null `ModuleWrapper`s. + /// - The non null pointer must point to a valid `struct module` + /// provided by the kernel. + #[doc(hidden)] + pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> Self { + ModuleWrapper { ptr } + } + } + + /// Creates the `THIS_MODULE` definition for a Rust module. + /// + /// This macro is an internal building block and is not intended to be= used + /// directly by module authors. It is invoked by [`macros::module::mod= ule`] + /// and by kernel doctests. + /// + /// A macro is required so that `cfg(MODULE)` is evaluated in the cont= ext of + /// the consuming crate, and to prevent accidental use of THIS_MODULE = from + /// within the kernel crate itself. + #[macro_export] + #[doc(hidden)] + macro_rules! create_this_module { + ($name:literal) =3D> { + /// THIS_MODULE for module `{name}`. See [`kernel::this_module= `]. + #[allow(non_camel_case_types)] + pub struct THIS_MODULE; + + impl ::kernel::this_module::ThisModule for THIS_MODULE { + #[cfg(not(MODULE))] + /// SAFETY: TODO + const OWNER: ::kernel::this_module::ModuleWrapper =3D unsa= fe { + ::kernel::this_module::ModuleWrapper::from_ptr(::core:= :ptr::null_mut()) + }; + + #[cfg(MODULE)] + // SAFETY: + // - `__this_module` is constructed by the kernel at modul= e load time. + const OWNER: ::kernel::this_module::ModuleWrapper =3D unsa= fe { + extern "C" { + static __this_module: ::kernel::types::Opaque<::ke= rnel::bindings::module>; + } + + ::kernel::this_module::ModuleWrapper::from_ptr(__this_= module.get()) + }; + + const NAME: &'static ::kernel::str::CStr =3D $crate::c_str= !($name); + } + + impl THIS_MODULE { + /// Returns the name of this module. + pub const fn name() -> &'static ::kernel::str::CStr { + $crate::c_str!($name) + } + + // TODO: Temporary to provide functionality old `THIS_MODU= LE` provided. + // SAFETY: `__this_module` is constructed by the kernel at= load time and + // will not be freed until the module is unloaded. + const ThisModule: ::kernel::ThisModule =3D unsafe {{ + ::kernel::ThisModule::from_ptr( + ::OWNER= .as_ptr() + ) + }}; + =20 + /// Gets a pointer to the underlying `struct module`. + // TODO: Temporary to provide functionality old `THIS_MODU= LE` provided. + pub const fn as_ptr(&self) -> *mut ::kernel::bindings::mod= ule {{ + Self::ThisModule.as_ptr() + }} + + /// Gets a reference to the underlying `ThisModule`. + /// TODO: Temporary to provide functionality old `THIS_MOD= ULE` provided. + pub const fn as_ref(&self) -> &'static ::kernel::ThisModul= e {{ + &Self::ThisModule + }} + } + }; + } +} + #[cfg(not(testlib))] #[panic_handler] fn panic(info: &core::panic::PanicInfo<'_>) -> ! { diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 80cb9b16f5aa..1bcd703735fe 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -371,20 +371,8 @@ 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>; - }} + ::kernel::create_this_module!(\"{name}\"); =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()) - }}; =20 /// The `LocalModule` type is the type of the module created b= y `module!`, /// `module_pci_driver!`, `module_platform_driver!`, etc. @@ -502,7 +490,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(&su= per::super::THIS_MODULE.as_ref()); // 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`. diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs index 6fd9f5c84e2e..089e38b49cdd 100644 --- a/scripts/rustdoc_test_gen.rs +++ b/scripts/rustdoc_test_gen.rs @@ -232,6 +232,8 @@ macro_rules! assert_eq {{ =20 const __LOG_PREFIX: &[u8] =3D b"rust_doctests_kernel\0"; =20 +::kernel::create_this_module!("rust_doctests_kernel"); + {rust_tests} "# ) --=20 2.43.0 From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 8FE54253950 for ; Tue, 6 Jan 2026 16:13:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715995; cv=none; b=HninM9H90FCKsIfgRuJUW6Q383PTVqP18iLbh0a825fa1bGy0e3KqdYnOp8VhAVKUZKzr7Xq5iye5QWLcZo3y+NwMrkK6xnqByfp4suAgBmHeuW1DGk+v3WrM1sgrGqqhBOLGascTUzkKZeJTJTnbhacurxyNKvfu6LWVXxDUnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715995; c=relaxed/simple; bh=891dg5NeMMgINCtxfUx5z2GhTLzUtO+bREujFmK9Vxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KFTo0g97LO8n9YezhD0l7nZO3AMrfSGiObd8+y77HWNaO+Jah/KV8PqT9vvsBxZDTMMwtUWxq92+zifr+JDRQOQcstw/MPByI/J4Wr2YR3ln4Mgg882HSSBj4xzjMog0HtImcwnCFv4Gai5mViTPUF/9K5ds7Y5hW/IarEqhnb0= 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=ldu++Ps4; arc=none smtp.client-ip=209.85.208.176 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="ldu++Ps4" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-37b9d8122fdso8851901fa.3 for ; Tue, 06 Jan 2026 08:13:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715991; x=1768320791; 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=SI0sZ7uVNTRnuO/8Ld3c5O3KKGDZMWG55LzxmtwZszI=; b=ldu++Ps44zc7q53vPwr67A5C/YUHDRRHIknPwGDZFvgN6MCdczym6TRGrzGiV/dPb3 E2Tz2usQgfl431x6YYsDhbotP4eOAItpgWJIMHWym2W1yet15nTDGAChTfd2ysDv1mvG VQ15EZyc0zXZ6KxV4gf9I2Yj0Z1J/OFkjT+Jo2SO+2yGfCFsNhXpwAPDIiqrPJo5uiPk h0NwIi80fU0FcfmO7q5BtVF25MMYkb8LigHM65Uau9ziaO4yT/QJX7Mm7bqTQMpl5a2l rwIXIcYi9C/Wzm2LQpnBR5y5zmDQL7l9/wbb0EuY/4ormYAm5Gxk/CEjfqC8lZWMtEeD dHRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715991; x=1768320791; 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=SI0sZ7uVNTRnuO/8Ld3c5O3KKGDZMWG55LzxmtwZszI=; b=NZnrn0F8XlGYulkBZd8NF8V+T6ybc0TpPEZv8wGfrsXcQPe213spaZMNm2m+MU72Jz HP10K+/gMz4ytseVSY3lA9HBRhdJ99huRCTjXrT2NSeIiQC96Y0rofOeIvMhgWEHBbLf hR/SvrQ7SU3yYdMy46jN+BLzgSFWfnVrXoB4dPrktEoyoHnyZl8aJppbbIa+RxsVEfR2 Mb1Iht9xvqL7Ndh7waDUZ0ukDvbJitixb1VUZTxsG/zGqXMj1OmYf9gaasq6iOE+Hr9E OzaYQt2/Y/m91vDWTRXQlMhtnJva4KvEvMQVHmSyhe3kMe30ZjkR7eM3Z/e/XHbNGibh oStA== X-Forwarded-Encrypted: i=1; AJvYcCUk8swQI4vQneLFF38EQeH4p7spusil3MVjYK5YtALiYNgi2UTFofvuZsKZdPyu95wd/aFlCERWG3bIV9k=@vger.kernel.org X-Gm-Message-State: AOJu0YxAXVorDCiWpmb4ebZpGPyS98pzRuUnKX64W7kbbEWrG/dyWXof Vk2PAQwlnvY/6iNbpb7kh/xQKHa0RyDTZo53YzS7154j66umF5/nWm18V2isjsfL X-Gm-Gg: AY/fxX6tBagVektra4gNsRw8wf9ZXNOxBB+LfMvQlwW7owSFuT/rnM8/Z0BQz0d4qe5 rl6x3FuJKFGcddymqBK8oMww3eUaArhZMG/N1VT2+JYyrDIeSLXCpdSdbsJbShe0rX5DY2z+lSR Xh+6yu8XxdjKK1Ha1s7+6P1mF+2zzEh64bCeqb7Tysy4bqZbHj+MLzS1mS7J4+HZRqeglhqGGPZ Nf2Pu1635G84gPpoU822m/or1lOfsO0B0DK/pc11HgIxGGiPLd/KYGIHJqW3uzmr9GfuVyUZlpJ 50adXE0fdSqB0uqmpTCFpHYC3W+9Z5XHmsMAQ/h16hvY4u6Ja7+ScofnclXSu+bFdBDHaURMLy8 Rlw8AUcXQm5zBCm3Zn3bCR7HXBX3w8GeAgjlHNi3hnFzMVXMV8qci08ICByStPBt0VaOi9B2fcn Jledi3OgAyznSniih7vKrdaeiUKMId8264D+ZZy/5uh9JPuCaG5I5g2aOEeGwJOLQA1Zuo2VLfq 5MvT4c1+6UdRULH X-Google-Smtp-Source: AGHT+IExWVexzUnKcxTwfYgOYf3r4tTgS0aisp7MxRHoeqvXnsdWfpbBK/qR84vqvGxwAzpgZN+KnA== X-Received: by 2002:a2e:a905:0:b0:382:5178:3e96 with SMTP id 38308e7fff4ca-382eaac9c85mr12054861fa.29.1767715991373; Tue, 06 Jan 2026 08:13:11 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:10 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:41 +0200 Subject: [PATCH RFC v2 03/11] rust: miscdevice: fix use after free because missing .owner 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: <20260106-this_module_fix-v2-3-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander , Youseok Yang X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=2370; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=891dg5NeMMgINCtxfUx5z2GhTLzUtO+bREujFmK9Vxo=; b=XTB+sVOL63dP4+VWC+iJBYkzCmbAeMtvvB++kKg5rg1gpSNNQmkqwSCagBJoh3NsSq0qwA4nQ VI5WDjBJtTIDa6b1hFQyngjY104t7ooXovgREEee0nWRpTUeFWWqvFb X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Currently if miscdevice driver is compiled as module it can cause use after free when unloading. To reproduce problem with Rust sample driver we can do: tail -f /dev/rust-misc-device # And same time as device is open sudo rmmod rust_misc_device_module This will crash system. Fix is to have .owner field filled with module information. We pass this owner information through vtable. Reported-by: Youseok Yang Closes: https://github.com/Rust-for-Linux/linux/issues/1182 Fixes: f893691e7426 ("rust: miscdevice: add base miscdevice abstraction") Signed-off-by: Kari Argillander --- rust/kernel/miscdevice.rs | 5 +++++ samples/rust/rust_misc_device.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index ba64c8a858f0..d4b0c35c4b60 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -18,6 +18,7 @@ mm::virt::VmaNew, prelude::*, seq_file::SeqFile, + this_module::ThisModule, types::{ForeignOwnable, Opaque}, }; use core::{marker::PhantomData, pin::Pin}; @@ -112,6 +113,9 @@ fn drop(self: Pin<&mut Self>) { /// Trait implemented by the private data of an open misc device. #[vtable] pub trait MiscDevice: Sized { + /// Module ownership for this device, provided via `THIS_MODULE`. + type ThisModule: ThisModule; + /// What kind of pointer should `Self` be wrapped in. type Ptr: ForeignOwnable + Send + Sync; =20 @@ -388,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 49dd5814e1ab..464e3026e6e3 100644 --- a/samples/rust/rust_misc_device.rs +++ b/samples/rust/rust_misc_device.rs @@ -155,6 +155,7 @@ struct RustMiscDevice { =20 #[vtable] impl MiscDevice for RustMiscDevice { + type ThisModule =3D THIS_MODULE; type Ptr =3D Pin>; =20 fn open(_file: &File, misc: &MiscDeviceRegistration) -> Result>> { --=20 2.43.0 From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 8D1D1314A7C for ; Tue, 6 Jan 2026 16:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715998; cv=none; b=TN8b4hNN5foViGlFmFKTSFoHRuPza8syWL09WGnfdQIakTOKYP7XKmnbVa256qJL8UwSNoFRTrQfApKWEtF2+J4uXsz/43Qxlxrzr1JSb45wuVQUrRrZNylxZSXeBzmuUCKIA1ApI0TR0kefH1Aj3Gnzyg3y2V5nmAj8CmpP7ME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767715998; c=relaxed/simple; bh=PsulVulBYOKVhtxVFsqQzoL1KhSmhEASbJ2jTpxpE5M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DObUR2hK2GiZvPZ0jb8MgdHmRka4JxeaSQFqNiSnZUHj1b48yXy55whWxqg8fHoFFaFwmBjveNOhToBr8gAACvtqndh9t1feTBaBBa+pOehIKPu62EX0XgzmgE6YUK+XQKxzZxJ+ZRFNzDhzjLWcZ2expaVsGqriWs5eWH1navA= 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=Vx/Dd30h; arc=none smtp.client-ip=209.85.167.45 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="Vx/Dd30h" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5959105629bso1143167e87.2 for ; Tue, 06 Jan 2026 08:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715994; x=1768320794; 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=6p/TE1++7w8lcKdQTf98fxRYGObQ9N/7Fpqo/Gx8pUA=; b=Vx/Dd30hnwaEdbq6aIK9ps8AGmAxf/UPpSwLSUTf0lp9HK4KuqDiWITdNOGhsAxy5t DRtY8UTwWoESQ8IRS0LbzgJ5vR5qFN1vfu80XtDbCjCvKCq45qDe5tW0wiFjNvlCfjpG BTGMN9BQsBgeDWStL5Pmjo6jvXUw7vKzFqc+dU95t/HsMgkLqEEcyZqG5EOrDnI/WHBH I3gH0UjlruQaZqdOIX+XeF2eZr4LewNsPcm4Y7qsoFnUS7SC0mcRa26d7aL4NDL6FUEi EXmDRy9IONAz2bWD6NTqqGRDBtkGGnFdBisO8LA7wswSVhwzGuSHCDHz0UqjKn01YQiW fXAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715994; x=1768320794; 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=6p/TE1++7w8lcKdQTf98fxRYGObQ9N/7Fpqo/Gx8pUA=; b=rtbi9VqQaQ1UtBWAQw4YK48tz+rYrLZ3NNr82R6yPWGC/GCFjKjIv0SSec6BwR3Bfa 9dRyU70oqczJQf0IWaa36DdjzX/BAxp8JWYVzbzPZjGSY3CneNQWht8ExoKnexuPmEw4 IJN64MwmeYwKcCtRh1wMjvvWkNxBWQpcYYsozLMLvPSCMkLJcadlt0PTIVpHPDjx+iub THa3NFIaQ1YxwrP+iigVaFRKMSuZ4lEBEnQDuqhXI42MUReypMF3gT1hdRxGycYl4WDC Ilvmo9uPMM/b+ZotC4DBWWrQtTNmtTdfde4010xE4agBJUYMrVD25vNTZTpEVVBkmw5p G1wg== X-Forwarded-Encrypted: i=1; AJvYcCXjmMeqqB72XB/8xCqwLfHBx6RODhIkHZDs7oJMZTVo7zaIurXZ+QYn37iA+JAbBe6bq6+r6NoTgViGoBM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywa+bSe9QVsnYB8CjBTUE1+wLkDBOcysNE3UaASlnlVdDipzIHB gitfttRaP3/X9ShM3eDVQu5VC0Y+vv+0dqGgISCxrY/yzPMLQE19KKc6 X-Gm-Gg: AY/fxX5y91a47SvJ7ZnWwLxNMs34aak7Kx10XEHCwzBg/NNcPJRqsJVeeG2NYXDyajP vjCSUSMSSM1u05IwJlgHTHm4AjPh+r0tQryQnfT+1F1Vms7i32XKDpSWSBn0jjepyCvbczjn3xd +2evMqGtxdBW1C+5aB7+OjqbLBg/8LOI5aYAYkp8tOtmLHbtpua95LuV7v4z/9ne0oRgHSLKgyV db4VWuW2NjRR2l4GXDGmgKnQRG7e52hXz75bs/By1U2+FrCG0DEBZO2JT7XwyX0UbodXqFY7dL9 8cWlT06yY/IJ0slaZdJXKhUzLOnCUf7FwyuD1JL8jn25yAgaE96yW81B0hzNwGe3C21x+8pIba2 BGFwzXYZ7HXXLDpd2M4XUbq2wKn9ow4Bax/e+YoQ5WksKpUfsC2NEUTAiKDGfQqBZ6FDclT6uZ1 NQEp+mo9GPduO1PuFe68LxeM9GgfDulJhF/sOSsRHshj5MHsMnvwwceUB0YIf20ooZPoIJd+6y4 oqLBLgmo+seZM+y X-Google-Smtp-Source: AGHT+IGlXyOOqsVxrzerdqZLWzRZbo1sVTEEFXJL0FcS8CHueTTVetp3Ab+FGNQAORlulzN0p9Q48g== X-Received: by 2002:a05:6512:124a:b0:596:9c01:aeb4 with SMTP id 2adb3069b0e04-59b6528578bmr1179647e87.18.1767715993393; Tue, 06 Jan 2026 08:13:13 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:12 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:42 +0200 Subject: [PATCH RFC v2 04/11] rust: block: fix missing owner field in block_device_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: <20260106-this_module_fix-v2-4-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=5351; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=PsulVulBYOKVhtxVFsqQzoL1KhSmhEASbJ2jTpxpE5M=; b=Sim91oPpd8l6p0q1O5Xp6fchcI+KFs0dqtVx/nb6eTqylSjcfpMwGbx1MCNvuwMzNycLZHSXT 6GC7B7fd+dUDmk1/IvWKXSPc9zWnTh8NkP6D1PwidvIhL6AfTpdTZRi X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Kernel has now enabled "const_refs_to_static" feature. We can fix TODO item now. Fix this by defining owner in vtable so we can read it from there. As this table needs to be const we need to define it in operations so we do not need pass THIS_MODULE alongside with GenDiskBuilder::build(). This will probably fix some use after free. Fixes: 3253aba3408a ("rust: block: introduce `kernel::block::mq` module") Signed-off-by: Kari Argillander --- drivers/block/rnull/rnull.rs | 1 + rust/kernel/block/mq.rs | 1 + rust/kernel/block/mq/gen_disk.rs | 30 ++++-------------------------- rust/kernel/block/mq/operations.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/drivers/block/rnull/rnull.rs b/drivers/block/rnull/rnull.rs index a9d5e575a2c4..862369ab9b5c 100644 --- a/drivers/block/rnull/rnull.rs +++ b/drivers/block/rnull/rnull.rs @@ -74,6 +74,7 @@ struct QueueData { =20 #[vtable] impl Operations for NullBlkDevice { + type ThisModule =3D THIS_MODULE; type QueueData =3D KBox; =20 #[inline(always)] diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs index 1fd0d54dd549..0c8e9e316952 100644 --- a/rust/kernel/block/mq.rs +++ b/rust/kernel/block/mq.rs @@ -68,6 +68,7 @@ //! //! #[vtable] //! impl Operations for MyBlkDevice { +//! type ThisModule =3D THIS_MODULE; //! type QueueData =3D (); //! //! fn queue_rq(_queue_data: (), rq: ARef>, _is_last: bo= ol) -> Result { diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_di= sk.rs index 1ce815c8cdab..4d5d378577ec 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,10 @@ 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..0f8f616590fb 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -10,6 +10,7 @@ error::{from_result, Result}, prelude::*, sync::{aref::ARef, Refcount}, + this_module::ThisModule, types::ForeignOwnable, }; use core::marker::PhantomData; @@ -28,6 +29,9 @@ /// [module level documentation]: kernel::block::mq #[macros::vtable] pub trait Operations: Sized { + /// Module ownership for this device, provided via `THIS_MODULE`. + type ThisModule: ThisModule; + /// Data associated with the `struct request_queue` that is allocated = for /// the `GenDisk` associated with this `Operations` implementation. type QueueData: ForeignOwnable; @@ -280,7 +284,33 @@ impl OperationsVTable { show_rq: None, }; =20 + const BLOCK_OPS: 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, + owner: T::ThisModule::OWNER.as_ptr(), + pr_ops: core::ptr::null_mut(), + free_disk: None, + poll_bio: None, + }; + pub(crate) const fn build() -> &'static bindings::blk_mq_ops { &Self::VTABLE } + + pub(crate) const fn build_block_device_operations() -> &'static bindin= gs::block_device_operations + { + &Self::BLOCK_OPS + } } --=20 2.43.0 From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 672E4335544 for ; Tue, 6 Jan 2026 16:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716001; cv=none; b=cfKyFw2+TytY7mK+2/h62cSG9G034RBSRDxCowMmuLMuer33+0v90hEjIgGUTwBQHcfHu1ljoYqjRetBkh104Ve7LAVp6B3McMKIZN5gXvh510SMxQJgFR4x+A3rWQeL0ZfPIlSpeNcew+Gtx1jdmfgNPlszaPahmyA1gRxM2/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716001; c=relaxed/simple; bh=Iq8dwvKf4qpl9g//ZJHlBlX2MQk95xnztRt44GtTqZg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DpFOsifErdboia/lYKj24MgLO9JPoIn1nq+fXw7aXkjbv+R0LjS0cfQXyjSTVDeeozyk2k0lU36CVNQMmJXEXriFOWnP73EX/BN0TuBrqQNVcXI5QJkMUwhOPPDAmRFdB3vFCgJwQLuaNCQjSugkqS9xt5tY9bnioe4xVYoAKJ8= 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=W06Xvs/s; arc=none smtp.client-ip=209.85.208.174 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="W06Xvs/s" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-37b9d8122fdso8852961fa.3 for ; Tue, 06 Jan 2026 08:13:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715997; x=1768320797; 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=HWUZeCU4mb7jx94MzKj81ED9AcODZrS6l0/OTITjt+k=; b=W06Xvs/sf/v+MZNPC+Y34MesjNreiOnIZCuM0rBRzxZIehHqfUNE0pfFsPF/dMAtUx M6JDSa01em3odFwnyE45Wl0blFhAY8eljTlhjpTqr/PcLV9EJD3X4LZyAR1qKIFK75/v hdgLdu2T9+6aCku+uvqmPu9tarNc6Wv2u6/cRxsdWEwFOsvcgT4RKPb2NX581EVhm9pl LDb4lGOtHQEb26qUbfdctfyhZq/jkvTXAKLXVn2t7f3vKiJX7tgT3cLCB8a1OxFqS2Nh phPfF+mWUgyWdRVw6mZ4bOlNFO3maMwLOJahu5HMT740RLciGj8N+Uw9q7REJiWfFtE5 If0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715997; x=1768320797; 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=HWUZeCU4mb7jx94MzKj81ED9AcODZrS6l0/OTITjt+k=; b=tF8DzgtL2h+Ku2y/rYPOtTJcivcXhKFFrhQuHkMfW6d8TR16N/XOTY765cBZw62jbi bRqxZOb3fjZhRUmaNlzb25ZPMI4T50LvcQEj6+5Ku/v2/PpnyCFCNfEF9k+RViiTeS2o /oa0D0XA+HYn9ozWh9TQzagjmQMBsQ7lGkK1+4nXZ9rjP6AySeinKIXXnG+IwSs+gIUz oEoopmvp1o+6vWfh+2BGY33wbk6wDj4gYSwXwOtaz2VmUJB/364AztzrazHcggxxXbEI UjC9lTdAYqTpmg5mfu833r5GvErKn82XY6cwRr5BvTFBUrgZYM1ICog+wvCVRt5L88m/ 7XVQ== X-Forwarded-Encrypted: i=1; AJvYcCXZeFWiKHZgfMXfYcuoaHHkzaQm501zhFgDnanl8VmuVdbbItxFalPcqsvOlB+lAuVhsFVUjqj+Z9+Elvs=@vger.kernel.org X-Gm-Message-State: AOJu0YwIclMX+DwUPZpqh3b5f2NKgCgR+46JC8n8rZVNIaImNbdcPKc8 AqrsNRUTTYniKnijVo+AJKePfwe93L8SzzO9spdWBGrtzK72ZfDqK0zk X-Gm-Gg: AY/fxX5uO6YpM/mjFc8gGzmmX/rm1MAV+8LaCPSNdUL2ukCUQ0n/lzeTIsrln2XzJF/ Ex0zGLDRoQheT4FyRpwC0YsFOp8eVHFj71UqjUSMLcx/rzJi6pXVBc6ppFY0uQhadP6M21XhTVc GH9kB9rdOHVmzltnsAZOpVE1RPDw8MvaanM5MEdgZCedv39zlw8jvvui4aADO8390Ok5cMZXdWQ JV6lMnkbMdBjY9ZMd9PqxhRZLiXQBFmuuDroDLbyf0O8AYJ8dGXeZPejYO0hvK7O9FW/d2AcCUf JDEE+jiGE1L+H4YUIL7mgI1F8UpZkzDvEUeEvAxDjHh2ZXhUXPx/rLxgd19n9Fr0YIL8a41P5fM 99iw/yPa5ggE5ffjyPJoUaMASu8TuRyLldj/RZEKDd2h3w9FmDMdYiNgy5C3HZfssMg/arRGStP Ylsp1P5vTQXJngx8csUMJ6SgxsogUqO1+tpHkZp/9FYIk4TOTMvV4EHH0K9KK0ILv7WQjnAJGje FH5UuJt0mcwlGtb X-Google-Smtp-Source: AGHT+IFU5y7W4r3vtwvNrwDt2AEQu7aHNHiFMmS0kmAFCGGtvAOwYmDUlbx4za8//rQD3V+f7QSnfQ== X-Received: by 2002:a2e:a88a:0:b0:37a:47a4:d5cb with SMTP id 38308e7fff4ca-382eaa05509mr11025441fa.11.1767715996847; Tue, 06 Jan 2026 08:13:16 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:15 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:43 +0200 Subject: [PATCH RFC v2 05/11] rust: drm: fix missing owner in 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: <20260106-this_module_fix-v2-5-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=4164; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=Iq8dwvKf4qpl9g//ZJHlBlX2MQk95xnztRt44GtTqZg=; b=4PHWmJPXGk2AFwwIRcqeacJX2YPoIRKK6cosxTWftT0EnsRQWaboWc7UTcbG/a5B+Htm208HV CyfU+LVXIKuDZ6vKwGOJZZNDvgiPCkSjNODmdz0MFTOv3nPt31QejWD X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Fix missing .owner field in file_operations. This has been previosly left out because Rust feature `const_refs_to_static` has not been enabled. Now that it is we can make define owner even in const context. This should probably fix use-after-free problems in situations where file is opened and module driver is unloaded during that. Signed-off-by: Kari Argillander --- drivers/gpu/drm/nova/driver.rs | 2 ++ drivers/gpu/drm/tyr/driver.rs | 2 ++ rust/kernel/drm/device.rs | 2 +- rust/kernel/drm/driver.rs | 4 ++++ rust/kernel/drm/gem/mod.rs | 5 +++-- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs index b1af0a099551..7ce505802716 100644 --- a/drivers/gpu/drm/nova/driver.rs +++ b/drivers/gpu/drm/nova/driver.rs @@ -14,6 +14,7 @@ =20 use crate::file::File; use crate::gem::NovaObject; +use crate::THIS_MODULE; =20 pub(crate) struct NovaDriver { #[expect(unused)] @@ -65,6 +66,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 f0da58932702..11932d3f03ff 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -25,6 +25,7 @@ use crate::gpu; use crate::gpu::GpuInfo; use crate::regs; +use crate::THIS_MODULE; =20 pub(crate) type IoMem =3D kernel::io::mem::IoMem; =20 @@ -179,6 +180,7 @@ fn drop(self: Pin<&mut Self>) { =20 #[vtable] impl drm::Driver for TyrDriver { + type ThisModule =3D THIS_MODULE; type Data =3D TyrData; type File =3D File; type Object =3D drm::gem::Object; 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..a157db2ea02b 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -9,6 +9,7 @@ error::{to_result, Result}, prelude::*, sync::aref::ARef, + this_module::ThisModule, }; use macros::vtable; =20 @@ -99,6 +100,9 @@ pub trait AllocImpl: super::private::Sealed + drm::gem::= IntoGEMObject { /// drm_driver` to be registered in the DRM subsystem. #[vtable] pub trait Driver { + /// Module ownership for this device, provided via `THIS_MODULE`. + type ThisModule: ThisModule; + /// Context data associated with the DRM driver type Data: Sync + Send; =20 diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index bdaac839dacc..9980cebec96b 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -11,6 +11,7 @@ error::{to_result, Result}, prelude::*, sync::aref::{ARef, AlwaysRefCounted}, + this_module::ThisModule, types::Opaque, }; use core::{ops::Deref, ptr::NonNull}; @@ -292,10 +293,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); --=20 2.43.0 From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 ADB21248F47 for ; Tue, 6 Jan 2026 16:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716005; cv=none; b=FX2RTFtNqfIgymRCzOwegI5zc8ZcLCot8iYMjlzafp4DYV0HSPKwAU82HbNqMrDaoR0XnQpKCOpo+mOULr+jVwAXjVjB041wSaz++GLTWI3r7quovKGDJQtrMTSTVYUggfDrvDqh2u5Nt1iQiVnKU1WTPPCfuFkDMZsLWviRoPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716005; c=relaxed/simple; bh=UTNOeFwTGihFmlxHJgeXPwIlyRNHZuCVFbumdp1zOoM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q+nqd0qAlR6r9tXrzJw5oo3n2QfiEUnD2mBlDON36Ak8yvULFC+YtylQpyTQfUR3WY++39hQ83H+HOkwgvsmcBgHkENBA6jBve+7i/rNVExV9ParnJJUHSzBoO6Rd0K451lvf7wkA8YAz2OaMampGfhexHVC7OasVHWKsigLBl4= 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=Sps4K1JO; arc=none smtp.client-ip=209.85.167.52 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="Sps4K1JO" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-59b6d5bd575so94135e87.1 for ; Tue, 06 Jan 2026 08:13:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767715999; x=1768320799; 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=cO44XyCgtGl8WrKQeDHWNuLpTRXz0AQwF9LfwT0N9ro=; b=Sps4K1JOXzurYrdGsz9xKP7qdhBTfLSFRUQfmBKgdAg/LV+IWHa34XRXKLKZaGAJWL BM6DDhAgOkwLiLV2yx90OFTeV/p4vHfITfwecDySaBT/m+e1TxlKrqTTJqSweR0tSu8/ vrmwh22/PvdyaHN9wwR/LKNID4CZpvrVT/t7eJ6sea9Y+wgYU2bJBTYQs7g5nbkPcNeR Cpf+ziz+t1r59wbYLpnqDO62hyqWhkqgFdE41yDiAOozzVUGT8GCvbgLltAZ7okyN81A ILdUofKKVgTGA2q5iMmXgVVJmxKts9SNEPEDkg4d7t7/ZuDdoCS7HgCsQaIsMbIu04Dg XKkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767715999; x=1768320799; 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=cO44XyCgtGl8WrKQeDHWNuLpTRXz0AQwF9LfwT0N9ro=; b=W+JqEQHo5AjWCrQwS8nEy0pyl8ZdnDabEGgfYrtXz9QB8kHF1bXgV8Hn1Alj5yKJ/U MfPdFHWjfhvaK1eN56jzKZBpFoeqM4aWH709KOxJNGoin7+yR2WJOOF6TkOhpF7dRiD+ fmgTHrKBpQUKm6FFXj9qjTIS0QdD0bu3WWxrLzt8PRVMFKVzzVJ/KJ0kw6hrZJJY7PLb 322e0OEPDtHjIzpcA8dLuiyQhRygp877YO4QNEYcAQTi3VpiNU7lUfGmdVJesHhgXP6N +WFmWfWit7J6+N2R+ygHVQeANuCRbOZiEPyYzKfP+YNJ0N82pl0z9dzFBmPbkYY2ica3 5+Xw== X-Forwarded-Encrypted: i=1; AJvYcCXR3OQiVZ73J1sey5t6a1w8srDDe9CUoO4TQL+TVohcR5uxvMh/hISzxC4YAS4zSCHGSoaKckSuXLQ10W8=@vger.kernel.org X-Gm-Message-State: AOJu0YyUvKmP5OxdkG+eVsUU+zyABCNVNldkP/N35Vv2K+P2ukYCVS1r zlcEpPFEgYtJMzwoJI1f15npjllMLi5es36O1d3/v82FA4Eyyutdgfo9 X-Gm-Gg: AY/fxX7gP8ZTsfBwRvJKemcJQ5ibJom+FUKl9cyZyL7lXIWdr9OBRvb0KLAMw2QhXaM 1f8gRGKNTuz1iDs2SODSihnPOKMCnUUK6/p9iVBDKA0jxbCcv6Ls1/Yyjs6qHnQ1oWfL9mI8+ec TJJzFemPFZdyJuWwhjGJNEoZBqowMgh2JT+4c/gxs/YwX4rcco50aHNLnO3WluEisF2Soxg0j/K eC21HCwHcofLM9uWelHRQvS9siAox02IjPpPhLGSCPXISwc1B6wIZL068hGtN2ohTqovnWSizsY DwYLY+Zcuf0hu2TYMT0cIz7+TADLnB7EFQxzNQrPlVqMMTleJ3wtLV4zQjGX1V3h7ome8XuvxEL 60dJozSOvzyQu+SxWZhS+IaUOaVo1HM1Ju7DwDUbdftBBQR+HieXWnYuH0FplB9iKJsdwhIke6b Kgmp/nyfzTPDbwZv03R3J5KbNjxVYvyWcI5Dzj+zuD6HHFnQZQp51OgeG8mdCrUIIaMaGvlyaMT pVOpuxAAJhFujw5 X-Google-Smtp-Source: AGHT+IHZLlib1FdNp6Mz3hTD00GnfYsdeklIwQwb155sldQfNtXmxDGwSdPNh/AFDq9/FqP+wutAPw== X-Received: by 2002:a05:6512:4016:b0:59a:108a:3215 with SMTP id 2adb3069b0e04-59b65292ccdmr1193890e87.23.1767715998955; Tue, 06 Jan 2026 08:13:18 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:18 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:44 +0200 Subject: [PATCH RFC v2 06/11] rust: driver: make RegistrationOps::register() to use new ThisModule 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: <20260106-this_module_fix-v2-6-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=12781; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=UTNOeFwTGihFmlxHJgeXPwIlyRNHZuCVFbumdp1zOoM=; b=DGUQmoqLCaQuejFYSYafK1smRUP3ShGq814VX89TAFuGO/2cknLNDFFelQnPhYq88scSSs2rx oNXoB+ngwz9Cdpu5utUuDtc8cd23TTWpFyJxHKbLJA/LfIe4C221/rk X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= New version of ThisModule is trait which can be passed in const context. To have unified way to pass THIS_MODULE to abstactions have const parameter which can be used to get owner and name. Signed-off-by: Kari Argillander --- rust/kernel/auxiliary.rs | 16 ++++++++-------- rust/kernel/driver.rs | 29 +++++++++++++---------------- rust/kernel/i2c.rs | 11 ++++------- rust/kernel/pci.rs | 15 +++++---------- rust/kernel/platform.rs | 12 ++++-------- rust/kernel/usb.rs | 13 ++++--------- samples/rust/rust_driver_auxiliary.rs | 6 +++--- 7 files changed, 41 insertions(+), 61 deletions(-) diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs index 56f3c180e8f6..102b0349af16 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -11,8 +11,8 @@ driver, error::{from_result, to_result, Result}, prelude::*, + this_module::ThisModule, types::Opaque, - ThisModule, }; use core::{ marker::PhantomData, @@ -28,14 +28,10 @@ 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) -> Re= sult { // 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 TM::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(); @@ -43,7 +39,11 @@ 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(), + TM::OWNER.as_ptr(), + TM::NAME.as_char_ptr(), + ) }) } =20 diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index 649d06468f41..dc7522c4ebda 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -94,10 +94,14 @@ //! [`device_id`]: kernel::device_id //! [`module_driver`]: kernel::module_driver =20 -use crate::error::{Error, Result}; -use crate::{acpi, device, of, str::CStr, try_pin_init, types::Opaque, This= Module}; -use core::pin::Pin; -use pin_init::{pin_data, pinned_drop, PinInit}; +use crate::{ + acpi, + device, + of, + prelude::*, + this_module::ThisModule, + types::Opaque, // +}; =20 /// The [`RegistrationOps`] trait serves as generic interface for subsyste= ms (e.g., PCI, Platform, /// Amba, etc.) to provide the corresponding subsystem specific implementa= tion to register / @@ -122,11 +126,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) -> Res= ult; =20 /// Unregisters a driver previously registered with [`RegistrationOps:= :register`]. /// @@ -159,7 +159,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() -> 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. @@ -170,7 +170,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) } }), }) } @@ -202,13 +202,10 @@ struct DriverModule { =20 impl $crate::InPlaceModule for DriverModule { fn init( - module: &'static $crate::ThisModule + _module: &'static $crate::ThisModule ) -> impl ::pin_init::PinInit { $crate::try_pin_init!(Self { - _driver <- $crate::driver::Registration::new( - ::NAME, - module, - ), + _driver <- $crate::driver::Registration::new::(), }) } } diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index 491e6cc25cf4..b23a26a445cd 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -16,6 +16,7 @@ error::*, of, prelude::*, + this_module::ThisModule, types::{ AlwaysRefCounted, Opaque, // @@ -97,11 +98,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) -> Re= sult { 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" @@ -124,7 +121,7 @@ unsafe fn register( =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 TM::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); @@ -134,7 +131,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(TM::OWNER.as_ptr(= ), idrv.get()) }) } =20 unsafe fn unregister(idrv: &Opaque) { diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 82e128431f08..88a5416fb44b 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -18,9 +18,8 @@ to_result, // }, prelude::*, - str::CStr, - types::Opaque, - ThisModule, // + this_module::ThisModule, + types::Opaque, // }; use core::{ marker::PhantomData, @@ -55,14 +54,10 @@ 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) -> Re= sult { // 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 TM::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(); @@ -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(), TM::OWNER.as_ptr()= , TM::NAME.as_char_ptr()) }) } =20 diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index bddb593cee7b..a4678af3b891 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -13,8 +13,8 @@ irq::{self, IrqRequest}, of, prelude::*, + this_module::ThisModule, types::Opaque, - ThisModule, }; =20 use core::{ @@ -31,11 +31,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) -> Re= sult { let of_table =3D match T::OF_ID_TABLE { Some(table) =3D> table.as_ptr(), None =3D> core::ptr::null(), @@ -48,7 +44,7 @@ unsafe fn register( =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 TM::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; @@ -56,7 +52,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()= , TM::OWNER.as_ptr()) }) } =20 unsafe fn unregister(pdrv: &Opaque) { diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index d10b65e9fb6a..e7e07360f953 100644 --- a/rust/kernel/usb.rs +++ b/rust/kernel/usb.rs @@ -11,9 +11,8 @@ driver, error::{from_result, to_result, Result}, prelude::*, - str::CStr, + this_module::ThisModule, types::{AlwaysRefCounted, Opaque}, - ThisModule, }; use core::{ marker::PhantomData, @@ -32,14 +31,10 @@ 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) -> Re= sult { // 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 TM::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(); @@ -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(), TM::OWNER.as_ptr(), = TM::NAME.as_char_ptr()) }) } =20 diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index 1e4fb23cfcb0..28a25e540298 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(_module: &'static kernel::ThisModule) -> 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::(), + _aux_driver <- driver::Registration::new::(), }) } } --=20 2.43.0 From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 247EF2405FD for ; Tue, 6 Jan 2026 16:13:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716005; cv=none; b=f4Asyp7EgZ6e12lbPGLPbgICPuG3F3Ladp9XlwZxpYnSj81LloRfP08JQwVhXdu01LN1u+dOk2U7yuIeWpGGU6il823J9WO5QHMpgNb27pgbk/mAROmMcWwhvhFHJAb+mmFzFjpw2dTkwX7xZhV8pePCbKdG2gYncdJpHJBEsGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716005; c=relaxed/simple; bh=cmxaklbkQRdcmvAPv3nZU1XmyGWj+C91dTrjBACqY00=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E5eLNGuTM10gCZZwyqLzYeZCw3sF3eeXbxBiTjePmJtWntFxaTqC/Ux1+DFYMCDcsgGQ3JpZd8uuzMIjZVsQfhOKH/9hPcr59Q/Cb5jqj6jjbw3NOVlBnxKQ/HJPC0nRCIS4MOTnAtdFGdvV3kRXCW1hUoDSS8RR34vFBGVncNg= 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=L3Hya9hy; arc=none smtp.client-ip=209.85.167.48 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="L3Hya9hy" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-59b30275e69so818510e87.1 for ; Tue, 06 Jan 2026 08:13:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767716001; x=1768320801; 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=h5aCMn3FrqRU+TQVZ+VUcKX0ZHYXGPf5P30sbMEeP8s=; b=L3Hya9hy2X7Jd7Bx0vmN88cIUXra8moux1VmKDWbu5I4c1EeAxwiMKfN1vfF77ygQR hR6zlVo2NjnON5Aj/YJWuBi5vWao/A3eHbsoYLVQf8dCySlqrZMzLn9aZhg1+1PNRzqN U88i1fHimyQrmWwoRsTWSCwbMN+C1gmtSDg7TDjKN4r3e9nVfjwNxsZlhjr92Mp6vu4M KPZiZXnJYK/z6q3eo//4uw/peqC3cA+V+deoAWwGwKf7YQg4BGYmA733+aPBCUIqKBeZ TFA1g2PSkFS4yYRKZcpUlxtk57iPordlIHBDklvGKx66E+JYxQ1EHkQ9fzktKg+u9VQM zp3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767716001; x=1768320801; 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=h5aCMn3FrqRU+TQVZ+VUcKX0ZHYXGPf5P30sbMEeP8s=; b=SIa0g2KWxrApOGD39/P9vGggLbpM2fVFuDiWOPUQ7pzSO6SNFbrAQjhhndb9tmtA0d UFfdS7BRP5Etwx3tqWtnpzDeCGUr0xIcH5ldTOj0mvDeTgkz1A/j3sLA3kAR+G02luyO E3wAIUsita41Lx7FK7Y7XBbtFnoAGy1PiGMrXW1ZIGQ1CtMnatUClZh4p5MstWBPaMTZ UDdUaXY0qX79ZZpgUDAL6WMCUTxFJ4CFnxcdW2aRm0zxKiIU2ajmFlkLfbn6mc0Bu6mF RwpHgXrjV8ZXvANepU5UNZSHaNJ0aJfhWVMcljJ2WDfs7c+fsyHf8Yh6caUEs6HOH+aR glEg== X-Forwarded-Encrypted: i=1; AJvYcCX7bCx+qyPwbUy1JajPlZ7Wve8ye/84CQ4oYl/eJpXNWL7ORdJd4qKaBpwCluZ/8/YBJx+/sN7DlnPqV7Q=@vger.kernel.org X-Gm-Message-State: AOJu0Ywinu45JFzUNWigQk75UVaZrSMSn8Gyx5K9Ohdmhkpv+jRcFxLB +wdY3ULOqwZ4FHI2Z9wEZVdyUk6pOxSfQnCiYdA2cMGJcRna4IWjhH2+ X-Gm-Gg: AY/fxX78W49D5vhL2SKSdRqJIXldOJMdqz+HBRsJgFx73F4vH5W5iIPkYc2gnVWUiPm iE7wBIQig7z1uVy4r1m9OWantVpab5iSWQeGCMTnEFDXuWKkhFB3FHx+sJtcSC9bPnC7FCDZ2nN /aR6ZulTDCzKrl99MOkPeR0bAA4tgNGRNp6uirYfJyMr8z/RdiT2tobffdPoXozwSNCQ6S1XGWV XYfFBCJMzX4TKwMMrUDYhr1t4fxDs/S8xYHWxfh9X4fCWurTYRmT2v8xQCO59ww8P2XG6yhfJir SyyIfWRtbh8eZNQlb3/AOsuPbrbZym/r646W1aaTKalFb6lxeiaNAi0DNO5HHW0wCxS9o+G6PG1 OINWt9zMP/sGmPqhr6KQ0wW+9p5lhwKWV/HHFP0BKjypf4xapgCKt0qucE36SIpUmhr0fFQ22gV G/eN7JYg8ebpwgp1e4sBgxeEEokUtPInxfHpR2vlsAnJmbqFHx03FOyokExSjej94YjvhErG0YD TjPcg== X-Google-Smtp-Source: AGHT+IEtAEGIdsEnrjEv9hp9aYk8dlDx9Z9M7RXZ2NsQs+GlYYPz2YQjUEUNJFTWzDj+8iPFr+ObPg== X-Received: by 2002:a2e:a98d:0:b0:37f:cc09:3197 with SMTP id 38308e7fff4ca-382eaabb987mr9562311fa.23.1767716000748; Tue, 06 Jan 2026 08:13:20 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:20 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:45 +0200 Subject: [PATCH RFC v2 07/11] rust: phy: make Registration::register() use new ThisModule 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: <20260106-this_module_fix-v2-7-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=3371; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=cmxaklbkQRdcmvAPv3nZU1XmyGWj+C91dTrjBACqY00=; b=klGzWdOZ5EgPSjks2EtqIzlsEOOg95lAi5QZmehg+4hxXdUW6mLP37/BYLKSPS3LauFIz4LDk dWJXi9qxenlAQp+keh9h30GqcEXUmEVc0MNNhASsQEK7vOIDyJbD+pz X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= Switch `Registration::register()` to take the owning module via the `ThisModule` abstraction instead of an explicit module parameter. The function is now generic over `TM: ThisModule`, allowing the module owner to be resolved at compile time through `TM::OWNER`. This unifies the way `THIS_MODULE` is passed to Rust abstractions and avoids threading module pointers manually through the API. This also removes redundant parameters and prevents accidental mismatches between the registered drivers and their owning module. Signed-off-by: Kari Argillander --- rust/kernel/net/phy.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index bf6272d87a7b..b6c99bf7e97b 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -6,8 +6,17 @@ //! //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h). =20 -use crate::{device_id::RawDeviceId, error::*, prelude::*, types::Opaque}; -use core::{marker::PhantomData, ptr::addr_of_mut}; +use crate::{ + device_id::RawDeviceId, + error::*, + prelude::*, + this_module::ThisModule, + types::Opaque, // +}; +use core::{ + marker::PhantomData, + ptr::addr_of_mut, // +}; =20 pub mod reg; =20 @@ -648,10 +657,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 [DriverVTabl= e]>) -> Result { if drivers.is_empty() { return Err(code::EINVAL); } @@ -659,7 +665,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()?, + TM::OWNER.as_ptr(), + ) })?; // INVARIANT: The `drivers` slice is successfully registered to th= e kernel via `phy_drivers_register`. Ok(Registration { drivers }) @@ -891,12 +901,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(_module: &'static $crate::ThisModule) -> 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 }) --=20 2.43.0 From nobody Sun Feb 8 06:56:37 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 EC0183385A8 for ; Tue, 6 Jan 2026 16:13:24 +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=1767716006; cv=none; b=SB7MTkfEi2/+qWzOEFna5bT3BN8WhCXEBYvJ7yLD0jQBbFoFb5y0kpCGlbHvZgX3WtUSuvqNoIMaDxCYx2brc+fqRVdEj6c7WCcBjhxJ0H8Cw8YZgZ3XGfwsywUKsf3TcPbvGuSE++3EWTwyEEyNaPlamT5dh0zqiY0yGNm6jUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716006; c=relaxed/simple; bh=HXsmrNNEr+H1R93npODROo6Md8lvxfZavxKoxrx9XrE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UnuekmiXx4JG52Qf29h3/xpqXiPxsuu48yeY/SlzkAsBHQdENQXNis+BSy3gc1KrHn9C/yI7A19jOOyDMdxBgysUa3H88hPmjoEwAEbvEC/s/4GZ9OYXfhuBVtYp9JxUFPyMbeDqitr/1Zeyudt7R2dxtYy6a8CixwFWXhTiV/E= 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=mOMfVa29; 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="mOMfVa29" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5957db5bdedso1294575e87.2 for ; Tue, 06 Jan 2026 08:13:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767716003; x=1768320803; 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=jA4SPNhuMX5XCZ5OBbakMPi2P9GAq2DqeqD/xi+6gT8=; b=mOMfVa295tY7LkIeYZsnWS1Rdske3pgJY8ADTuX0xsp6a0wfNtA/RgpbASh6gwkbie LtoGdyKnfi7sN9JFObruv9dlj0yc4NqvSaxn1nqg0KZxrg5ivQ38cc6WQuNz4rB17T9J TfSfxiaKcs3MW2trseyAhouSny0xDvoH4jQNvJbijvt3WFWcIN5ipxa1Jn0AXAmM4zEx odgUwfes6qD9m88Edduo7I4HSxWKDqovjndroELwdcgdnuqpK/nRxBlu8p8Ny2Bcctv9 P45MdXltu/tAr5HhUtyE27wAKpjC/zI2UtqJxwLkbGOOwFE9RjHDSCr334ohfDyJuYdG YmyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767716003; x=1768320803; 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=jA4SPNhuMX5XCZ5OBbakMPi2P9GAq2DqeqD/xi+6gT8=; b=vetpgocs1K7DnSLyDxGUcKnZOMhtmKybAy58pc/ZoS61e+5XQyfviygJ4XTSmb14ZH ufkF2tTqFAoQfykb8N75BZ2z5BJOwxOF9zdRPGd1sbvKHk1M4ZBVmHyVZCFP8iZhjlb+ Epj6Sd+5AYwFdkMvg9qSWGOIyd5s95YQiygI0Y3UIWQWlZECs17zv8gukdntlHFE263x 0SHl4aumbBcYG8YHzo2JcYuEycXIBHlQiMCzpkiKWoMZxjhWKYVKSMzfsNhQWkPgSmEM Ve+HCotGpYNtwUfma24SlqR0fd3VD91EMACS5EiEwtnKka474tbqxNX0sILQD6mJQGga nc4A== X-Forwarded-Encrypted: i=1; AJvYcCWeSt34yG8ylN/LD4pTTUrk9WQCTYOmi/o/LQJNUAFlmzmh7uR3/uGEO9WpW6yU40XpjVHSJy9EPGkbhIA=@vger.kernel.org X-Gm-Message-State: AOJu0YytTPG4+dRerFT6vyAIo13az948bqpT4TW3HZL8U9pXpridczgM Bf3YHkHWoDXuOnMU6pdnitguqx/ANYtbNtFM4QOrliSaz8aVMR0jUcAV X-Gm-Gg: AY/fxX5zlxrm9lde3V64qEqzFAn45EufhRDM8ZMjCocFEN9t/Mb9IGRGQvne8vtfOZx AVXLXHzim96+vO/QMzziOMUokuCRU6d0kc4BYGQu3tTHY2Xky/c87gfysRWTABCzi9ZK7vZ2zam u+glmItkpIyHXv7ogkxwXy+kVrcZOMICTNm17bH+OuSMOl4lXUqFLj98VtxJnEm6pIK5TP3h6t9 2WzFDrBND4GFg1f+Qe2i6Pe2ux0f26WVDPpHPC3FwNT/Uu9ymJ0gSrWiNki/NPqFU712z1aHaqN mpV44gcfEPPkEbSkIl4mLNWolImtgzIzHBzAYIxlo+zBM0zm6gqubZFY/8hRqVpN9mQDRruehBY YDw5/a9MO/jIvFfQixXu/MFIFsvMKAp7E8AZs/mX13k4vHN4zwJBV2Wv8JYd36gvKlipjJTbpm3 oCk6Q+VhwTBzTmlr1BE6ql9ZXjY1bXy4g/LeZXXS19w4TlmG16hTkvqnaD7b9ZSG+lH5IlrlmMi Ha88g== X-Google-Smtp-Source: AGHT+IEDfjAP/q6tl8l2j/q30jjjWobjSIo8yqpbOiByLc5uyBuPPT+WRrg2weBXCsixvQrl0a6H9Q== X-Received: by 2002:a2e:a58f:0:b0:37a:4714:ff39 with SMTP id 38308e7fff4ca-382eaaa2f8bmr10163611fa.23.1767716002686; Tue, 06 Jan 2026 08:13:22 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:22 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:46 +0200 Subject: [PATCH RFC v2 08/11] rust: binder: use new 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: <20260106-this_module_fix-v2-8-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=1238; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=HXsmrNNEr+H1R93npODROo6Md8lvxfZavxKoxrx9XrE=; b=5lBBJ8pNkqE/cUVzYPL+ifrN07scK3BAy/Q4cFAaJhkvnZyARbkT2dcTAmw41Pf0yprOIFojh u81hnoO3A+YArUkD6BUvZYrXJkWXcEAIj6EBEDw7QQDufIRI4FH8z/+ X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= We have new THIS_MODULE. ThisModule is now crate. This is ugly for reason that drivers should not use as_ptr() directly. Currently binder still needs it so ugly cast is totally ok. Signed-off-by: Kari Argillander --- drivers/android/binder/rust_binder_main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index d84c3c360be0..fc921c0e1116 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -21,6 +21,7 @@ sync::poll::PollTable, sync::Arc, task::Pid, + this_module::ThisModule, transmute::AsBytes, types::ForeignOwnable, uaccess::UserSliceWriter, @@ -319,7 +320,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), #[cfg(CONFIG_COMPAT)] --=20 2.43.0 From nobody Sun Feb 8 06:56:37 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 C9EE8339859 for ; Tue, 6 Jan 2026 16:13:26 +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=1767716009; cv=none; b=dbL81HS0YpPdTeBxztODdDzU9iaqdTVnE9+/dLexXHw8wIRsoDUG8BJteYId+fYxhHk2DW7Vt0pLHHNYU3nb794sj3I8iNmodBVLUoGjajh55BTxGLgdvMDL2v2n75hQlWqwzdlEi9tcJb7Z+DbS12XQtFbD2SSHz671pPoAs2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716009; c=relaxed/simple; bh=ux96t37i0o+XQz9rwL1Xsqa9o9j/lFq1tZiPHrrgcfg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TJc95pOO78BjaSPafBBEzPMxyf0VfKyFyvYlibcKImEGL0l8h0xm66OxB8Tms8kJQCxaVScCwUxwA4WwHxsQ466Uk0bn/sDskhbdXmxEd/qRpIUHQV55ioMhP75mv3rXwTTBuaCkfvefoM146k4Cjjn3yE4y+U2iUCQNpXnu7UI= 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=eh/guTD+; 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="eh/guTD+" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-37b9d8122fdso8854031fa.3 for ; Tue, 06 Jan 2026 08:13:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767716005; x=1768320805; 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=w/r3EYPU9S+RKnAFCMdSg0qTpeqQzdmOVqZdf6MJWDc=; b=eh/guTD+R/aW9TmdqdN+G0xMr3EUdjtMAMnFOUQAH7peyukSZ9mh4WdV5bTMytjsWy IiT9jafeNhcRsajEdIG/igU7fugiIzm23MwAg/RRiG/rpf6lYFiIc1xFon8fM+GevNR1 FvyH88Zy31lmVIW/tl3Fjo8vfjI7RSJxhC2c33dJ88R3FugEmUfpbn2PxdsD8w/E8ciP 09D1sL3mXlDoP2kuh1R7eEuIsuYny+vugRCJJWoQy81WSG5Er3loWOCSlTlU/LNTFiSt CHQAnAW5cpGCXrLrpI+xhWU1UmN4DOIlbIhCVFh8hncwwYNbVT9PPCHp41j7SOyVbrsE ZAuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767716005; x=1768320805; 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=w/r3EYPU9S+RKnAFCMdSg0qTpeqQzdmOVqZdf6MJWDc=; b=i3o4WW5EHjI7Q9/Gmez9408NmPOpdul0DJROETb54fij+ji8JZSSqXQt8KwmtUUXIx TAOKrenP690prnq7EXvDFuCWCkPLAh8ItWTO+ipfhNwdpNuOaLOjgjxLECx0XOElocLF wfOPD4IXGw4vXs75ssIzk5TtLVhuFiMuMBpjS4bGoDl4OiGXirnb4nWlT3MVg5zeJh7q GUn5OpE4n7mhEzhpCbvDdjQ+YyE92y192QyzmgFG00z5gOH9O6qmbAAxf6I6iNJQpRTJ jm3WjJ+ew5EGBVFp+Jd6P322P4dPG0DQIv6QKG0M8HlR4Q8CRMimDucVBPy5ys0DXhBK fR0w== X-Forwarded-Encrypted: i=1; AJvYcCVRU/7gUz4OApvn8gEijSuC5qvhsTbVoVmVgAfRHys5GqcPemg/vwXvhSeRIuE0HbM2C136v7P0pIg+ops=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4VVwxdGncoNZNkIPuEm6+BngVM0kkUbr4s16jsd8LKvzQ4/CC 8IY0GKaVPI6vDfyXDcJLtaxIoQBmvNV9HQZaOebseFhGOeFOlgoGoatz X-Gm-Gg: AY/fxX4w0QIM4KtH2LrE4v5hInt7qdkPeRbHx6rDPocWzlzLCrJc+c9SrEIzxdG4qsw s/nhhwBYs/PYi7LBUPAOPgFwVMXUEPr5p6wrA4pIK7INkz6HvoxoMPRN3+iVZJVkZlHkC6BMu1r tsqAHdfWU0ZjcCl9ldO9edLCHDtlE4wX+sGz0Jm11UJhw0kKR3PftLSocOYi4Sqil+xht3AqTof mQrWCHcv6GnOjRb5nsz6rIlqYxiOFYYNPqkT5TqLFbP3o9WcdOb/695FZl+QbPjm4kD5x6RYCSW xnqdDIJM0rKjYlWzeN/2Fq1rGw7iAzODl4/QXI4fmLLHLtYkMwXd8cNyX5MN4mx9iAlJHaX/I+t VZUR6rzzYy9KipC3N/fyT5/3RGwPJwX9Zxo43QxZS1+ihfFTTi7YUtQ2DJJvLX9OEbgfIZqglyM 6bcponIwX9SihPCCzBLmu3Z/uPhX6NxFExDy959RWZSUk06KbbiSHzQlOvNP7hRzSQKyc6GISEr tp+AUtUqfWvXcyD X-Google-Smtp-Source: AGHT+IGYZWam7DBChjxOUl3CONwCvShE1fvapEpMsDYCfGaWU3TWsq5laWGyI8gsXTyWYvUHcv79Mg== X-Received: by 2002:a05:651c:221a:b0:37a:30c5:af1f with SMTP id 38308e7fff4ca-382eaadb376mr11103641fa.40.1767716004648; Tue, 06 Jan 2026 08:13:24 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:24 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:47 +0200 Subject: [PATCH RFC v2 09/11] rust: remove module argument from InPlaceModule::init() 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: <20260106-this_module_fix-v2-9-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander , Yuheng Su X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=13585; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=ux96t37i0o+XQz9rwL1Xsqa9o9j/lFq1tZiPHrrgcfg=; b=rRmm6X7wAsFkyggSVE85WlCCByCGyW2Uik6XNWiq6PaAnJGJIKLtaD+udyDf5v2FSjJoAgZ2i VBkL++c3BLZBdhAJJP5v/pWpv3oxK1lhXckuofLLPSz1HXQM5ZA9M3q X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= InPlaceModule::init() has ThisModule argument. However modules always have THIS_MODULE made by module! macro. So it is unnecessary to pass same information through this function. End goal is to make idea of THIS_MODULE simpler. Driver getting this THIS_MODULE from multiple places is confusing. So let's just stick with THIS_MODULE as that also works in const context very easily. Reported-by: Yuheng Su Closes: https://github.com/Rust-for-Linux/linux/issues/720 Signed-off-by: Kari Argillander --- drivers/android/binder/rust_binder_main.rs | 2 +- drivers/block/rnull/rnull.rs | 2 +- lib/find_bit_benchmark_rust.rs | 3 +-- rust/kernel/configfs.rs | 3 +-- rust/kernel/driver.rs | 4 +--- rust/kernel/firmware.rs | 2 +- rust/kernel/lib.rs | 8 ++++---- rust/kernel/net/phy.rs | 2 +- rust/kernel/sync/lock/global.rs | 4 ++-- rust/macros/lib.rs | 4 ++-- rust/macros/module.rs | 2 +- samples/rust/rust_configfs.rs | 2 +- samples/rust/rust_debugfs_scoped.rs | 2 +- samples/rust/rust_driver_auxiliary.rs | 2 +- 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 +- 18 files changed, 23 insertions(+), 27 deletions(-) diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index fc921c0e1116..8b865112e60c 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -291,7 +291,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/rnull.rs b/drivers/block/rnull/rnull.rs index 862369ab9b5c..a9be1b2187f4 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/lib/find_bit_benchmark_rust.rs b/lib/find_bit_benchmark_rust.rs index 6bdc51de2f30..5c231569d887 100644 --- a/lib/find_bit_benchmark_rust.rs +++ b/lib/find_bit_benchmark_rust.rs @@ -7,7 +7,6 @@ use kernel::error::{code, Result}; use kernel::prelude::module; use kernel::time::{Instant, Monotonic}; -use kernel::ThisModule; use kernel::{pr_cont, pr_err}; =20 const BITMAP_LEN: usize =3D 4096 * 8 * 10; @@ -88,7 +87,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/configfs.rs b/rust/kernel/configfs.rs index 908cb98d404f..2af63f7daef2 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -27,7 +27,6 @@ //! use kernel::new_mutex; //! use kernel::page::PAGE_SIZE; //! use kernel::sync::Mutex; -//! use kernel::ThisModule; //! //! #[pin_data] //! struct RustConfigfs { @@ -36,7 +35,7 @@ //! } //! //! impl kernel::InPlaceModule for RustConfigfs { -//! fn init(_module: &'static ThisModule) -> impl PinInit= { +//! fn init() -> impl PinInit { //! pr_info!("Rust configfs sample (init)\n"); //! //! let item_type =3D configfs_attrs! { diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index dc7522c4ebda..de77f95d7fe0 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -201,9 +201,7 @@ 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::(), }) diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs index 71168d8004e2..11372a8f7be4 100644 --- a/rust/kernel/firmware.rs +++ b/rust/kernel/firmware.rs @@ -157,7 +157,7 @@ unsafe impl Sync for Firmware {} /// # struct MyModule; /// # /// # impl kernel::Module for MyModule { -/// # fn init(_module: &'static ThisModule) -> Result { +/// # fn init() -> Result { /// # Ok(Self) /// # } /// # } diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 2ccd75f68f03..e7bc52a6ad42 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -175,7 +175,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. @@ -183,13 +183,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 b6c99bf7e97b..7d467d42e951 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -901,7 +901,7 @@ 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 }; diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global= .rs index eab48108a4ae..7fde464462d1 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -203,7 +203,7 @@ pub fn get_mut(&mut self) -> &mut T { /// } /// /// impl kernel::Module for MyModule { -/// fn init(_module: &'static ThisModule) -> Result { +/// fn init() -> Result { /// // SAFETY: Called exactly once. /// unsafe { MY_COUNTER.init() }; /// @@ -243,7 +243,7 @@ pub fn get_mut(&mut self) -> &mut T { /// } /// /// impl kernel::Module for MyModule { -/// fn init(_module: &'static ThisModule) -> Result { +/// fn init() -> Result { /// // SAFETY: Called exactly once. /// unsafe { MY_MUTEX.init() }; /// diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index b38002151871..d22a93696209 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -80,7 +80,7 @@ /// struct MyModule(i32); /// /// impl kernel::Module for MyModule { -/// fn init(_module: &'static ThisModule) -> Result { +/// fn init() -> Result { /// let foo: i32 =3D 42; /// pr_info!("I contain: {}\n", foo); /// pr_info!("i32 param is: {}\n", module_parameters::my_paramete= r.read()); @@ -114,7 +114,7 @@ /// struct MyDeviceDriverModule; /// /// impl kernel::Module for MyDeviceDriverModule { -/// fn init(_module: &'static ThisModule) -> Result { +/// fn init() -> Result { /// Ok(Self) /// } /// } diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 1bcd703735fe..7473a377a3bd 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -490,7 +490,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.as_ref()); + <{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`. diff --git a/samples/rust/rust_configfs.rs b/samples/rust/rust_configfs.rs index 0ccc7553ef39..f34260793677 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_debugfs_scoped.rs b/samples/rust/rust_debugf= s_scoped.rs index 6a575a15a2c2..75897e02766b 100644 --- a/samples/rust/rust_debugfs_scoped.rs +++ b/samples/rust/rust_debugfs_scoped.rs @@ -134,7 +134,7 @@ fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl = PinInit } =20 impl kernel::Module for RustScopedDebugFs { - fn init(_module: &'static kernel::ThisModule) -> Result { + fn init() -> Result { let base_dir =3D Dir::new(c"rust_scoped_debugfs"); let dyn_dirs =3D base_dir.subdir(c"dynamic"); Ok(Self { diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index 28a25e540298..7b729687811d 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -111,7 +111,7 @@ 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::(), _aux_driver <- driver::Registration::new::(), diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_fa= ux.rs index 5330b77ea986..2653b2ec3338 100644 --- a/samples/rust/rust_driver_faux.rs +++ b/samples/rust/rust_driver_faux.rs @@ -21,7 +21,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"rust-faux-sample-device", No= ne)?; diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 8eb9583571d7..c024f8083499 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 464e3026e6e3..709adf4a6026 100644 --- a/samples/rust/rust_misc_device.rs +++ b/samples/rust/rust_misc_device.rs @@ -128,7 +128,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..de1bf7b80153 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 06:56:37 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 F0B6633A71A for ; Tue, 6 Jan 2026 16:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716011; cv=none; b=Eilb4RIInpUvF6XZo8LycqVc2Hi6KRao/UrAH6GfdAnWvPkOmFLstZ5WH1aJbIl8DaaUSh/4j4japP0jdWrzQHdbFwBtvgW7L47BCBNVIErPYClSe8HucTrX6CDEEt2OI90oV3fkiINfOLRxfpxxUq9SxjUVqi+45kuvC9ieAps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716011; c=relaxed/simple; bh=31K3z/TeTL27blPoZfDSHOqEMPWwg63C71FzL1KNDBY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=htXQSg876POiTGIO1ov6u1acP2nPMAcDHS2MOe9RnwxJVK7zccwHCEkMiYJAeTPo1xYJpYhqUBW8WnzUzw9SnDWQ0+y75ykDhIKIdEldwRVM63PbnOawJVkRGYaEPdTK72C7JxHn74yiNrevw2DLt082/dcEY3WoLUEhDIn2jKM= 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=js9H5iCD; arc=none smtp.client-ip=209.85.167.52 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="js9H5iCD" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-59b685d2b79so719119e87.3 for ; Tue, 06 Jan 2026 08:13:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767716007; x=1768320807; 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=Rzq6sT7GcMk+zrj1ACCJmSl03CZtKzXScBbEctCNtgE=; b=js9H5iCDT1xuYoBwfMQoX8HBM4fQF7ARMJuPtWMXdN/SRJqmJ8Am75E2rITcGr4lev UQvHdP7wDWL1e9hb/I05KwrWlQyoWRxVFEyQN24shW2lOTNJgavuFdAi+b9jxd7KoHwI drlhKUUVeWtBLXnvuJnuWGIFbMCCvYmzYhVIROeyAhClVX8diUQdEZC6iIqU06gvNCwA V/5xHrhFbEig4JJK9SZLTo3bv8Tqr5rHjSoTZKKDfPNAhx7AJs0qdRwGLOm4/JuQaSQi Fu+CQN/+YayRAjQKJxIW9RjPVf1bXvmUr0S7IrJJKqIfaE6mpbg0uUy3OTtCbvPp9Fub 16sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767716007; x=1768320807; 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=Rzq6sT7GcMk+zrj1ACCJmSl03CZtKzXScBbEctCNtgE=; b=oCqu0/GSKe2eV6M9CEs9qsiYGRIwb3BQC/8vZK413SyqovRnk2QbB1CoIDoyDAh4Ur 2RokRgct9DwREQGnlcyC3Jkl88ztVtiTUfPXpaDyzOHFntG2EDR7wXyfox9jNytYz1Po Zkc48XzCO/UAteQF2MM7fHBWts9KEw35R85Ovl6t9A11O832g6dATmosxvuWaMtlcvAM tfMdFZAhGXa1LESnIhbXVMrZnQOCTkqugY0amHEzhmiD//qhxcUzOTmRusvU3RtMDpAd JFuBiyfpPjOud/xY89ON97ANdF5xnpDkZOkMcmPbXld4Z5ydif+cvWnqawBKeM80rnaG YLlg== X-Forwarded-Encrypted: i=1; AJvYcCWoUEpol64h0Ro3uLocRMCBBu0NudGb0Uk9ilbgn6LOmh9gj9WFcHRGtJfHiZdcHGiwgqW9PiWijNpCle4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyl/7TJKPHd9+tCqbM6gZpEthqa2uOz6kF/p4J4kHHB70SSw4rh ujNQKpzN1hT1L1x7MaA5s9kdydhJF72U40crvSvuPX9jA0UfTJJg0e2J X-Gm-Gg: AY/fxX7+sCJWbAhqCm8YHerWbPJYuVKhHjPbhMCzKB1NBvHuP3gTZHrXPK76ypYAZvY 92EUcM1MZUei2jol7TYiOjlVKzOx9Rtmfv/oVxFtnaTSKuMdFCNcCjlQiY7ee+iPW411BlFwJFV oCf7DcwBlWYur95Z70l4gsIUw8tUcD87eFBq5aye3baIiyQi9iAD/4mv6rBkL+1H0HobAEXEffv bfqOviirRk5C5Cp4d6TfH6O/KHPcTCbkLr7mTUMdKKAHW2VoKfjZsBl8UKdpfdKUTeVofYnC3hp +CITs4wOpChXf94kvJgiFe1JZfr7NE42WJPVfXkECDe9nBPT3UwlsBPwvruHzR4xepxKmuVpjsV uYUCeEYh2bgX5g014Q0p2KILYlZO1vQhPEpr9oqF+2hnz4Ju63PDULamH7+S6eTzAnHBbRTjWBa A2EnKK5p817VEwNRpCm9bK0BOzfpAqJyVqcwgv4WjDsokH/Z/9RbW5fYQ9iVn/8uP/FrMOk5k7r NYkQQ== X-Google-Smtp-Source: AGHT+IEP/ySDqe0fUbCPgt5iLWx19W1TWyDR8oFVojZghcOpc//7QvyUeu7CEG1drmNLRunieI+/Uw== X-Received: by 2002:a05:6512:10c5:b0:594:2f1a:6ff0 with SMTP id 2adb3069b0e04-59b6520ebe3mr1228667e87.9.1767716006851; Tue, 06 Jan 2026 08:13:26 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:26 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:48 +0200 Subject: [PATCH RFC v2 10/11] rust: remove kernel::ModuleMetadata 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: <20260106-this_module_fix-v2-10-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=3446; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=31K3z/TeTL27blPoZfDSHOqEMPWwg63C71FzL1KNDBY=; b=aYpSyfVvVzRtx2jZBA0uzYh2qT6PaE4SsBkyhK757T6LX63SFZ5UAGbmaYOT6qU//VGxRLdbb ZCWh1rldZrwA3wKCYGu9+ZCmt5Du50a7ox3x1R5Wt+7hiG44za8CUbs X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= We have all information available also in THIS_MODULE. Use that instead. This way we do not need to do ugly casts from driver struct. Signed-off-by: Kari Argillander --- drivers/gpu/nova-core/nova_core.rs | 2 +- rust/kernel/firmware.rs | 2 +- rust/kernel/lib.rs | 6 ------ rust/macros/module.rs | 8 -------- samples/rust/rust_driver_auxiliary.rs | 2 +- 5 files changed, 3 insertions(+), 17 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/firmware.rs b/rust/kernel/firmware.rs index 11372a8f7be4..42bae71f6af1 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 + crate::THIS_MODULE::name() }; =20 #[link_section =3D ".modinfo"] diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index e7bc52a6ad42..dec1d05ebe7b 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -201,12 +201,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; -} - /// Equivalent to `THIS_MODULE` in the C API. /// /// C header: [`include/linux/init.h`](srctree/include/linux/init.h) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 7473a377a3bd..97635aed1598 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -374,14 +374,6 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { ::kernel::create_this_module!(\"{name}\"); =20 =20 - /// The `LocalModule` type is the type of the module created b= y `module!`, - /// `module_pci_driver!`, `module_platform_driver!`, etc. - type LocalModule =3D {type_}; - - impl ::kernel::ModuleMetadata for {type_} {{ - const NAME: &'static ::kernel::str::CStr =3D c\"{name}\"; - }} - // Double nested modules, since then nobody can access the pub= lic items inside. mod __module_init {{ mod __module_init {{ diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index 7b729687811d..528866b953aa 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"auxiliary"; =20 struct AuxiliaryDriver; --=20 2.43.0 From nobody Sun Feb 8 06:56:37 2026 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 7FCC833B6EF for ; Tue, 6 Jan 2026 16:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716013; cv=none; b=In0GF88NipFYCaJX4/D+7DNbu1hXEOvie5MDQwtBjgqQLLOJ/IEXB8JQy472hWbAnHTNrp/2VqfXTaRiYDm/SKSpqlXGGfyMj4gEZQ9kfK+0whwzrcLij2JnLKYhQ+HPclX967G2HYLmhy2eQeO/3UspDOO9Ixix9yennwWLqQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767716013; c=relaxed/simple; bh=DmmtaDAQNblc8YsS6wVHtlUqz9NIYJ5OZn7ml6apuUc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ILpQFkfK7k+NGc7nIE00OisHv0R3HN4kzcr28JHZfRbT1UJoYn7EARM+yirxfJGZYvQYyOG1oTFHhQ99iAAm80LyJssHhFCrSQcRNEKlNhqQAo9Sc/B3zyzJHfwxAbnsy9QGyv9r9X8DIlZQ8IiDlkml9dH4NM7mtp8ofvePUkg= 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=USf8ptYU; arc=none smtp.client-ip=209.85.208.177 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="USf8ptYU" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-382fe06aa94so22371fa.0 for ; Tue, 06 Jan 2026 08:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767716009; x=1768320809; 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=yD1KNN5/TWj3t1cQe+Jpa13onMvM2XzOEo1ubv8aag4=; b=USf8ptYUDxHpzCm9+DVHO4RWuMzUZTZawfX40J9OI6HOS90AATEmtGxwaSy3YcnXbM 5hHFZU+I57W8wLiA9LrkBhL3R2ENebO0tyv4ncFJ22QgNMDN4kCNM1iwb5bAPaWgmcHk qclIkVvBi9wlUE027PBeaEvKzP5yjQhjP3wdgZ/pcJXIaJP+66emkYmLHPoIyRocp16H VK1s/MC31CYC50vULt1/yjivjBWDNeGATarBS8VTMcW9vL640XNngSKzmyn5KImxjiRV EC6szmQXC3scWBye4f2Vt4/T3a83jq6Kg3Weg3lDmx19hu5OkKFPiyvVe7/7+6+Ru8Kc rWRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767716009; x=1768320809; 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=yD1KNN5/TWj3t1cQe+Jpa13onMvM2XzOEo1ubv8aag4=; b=XCRB3U5HTgJ9iPTpRhIWuHkwat8OhgBDzzBq4nTOh8icPV8ECVrQghOc7PB68e9DU8 X0dYe74f9cVapbeuyJm/7Yjg05kxsXD3LTEOH2i83mVUGwtxeSNnZaF/U1DezVinrftL ILcILBtEcyhRTTWgBkSQznnGZsMV/JD56EN89cKhTCXjKnSNdKxas2Ypnx2k0t+JCWyW FHko0QNLFafbK/FWxhE9ixYHH2fjw62OkWnntCXV5RHFloL3qIhQeJZEmTOCpJcCP4qy 7jQjjggi2hoabnQz9HRxhDuufeJ53A/YE6RYY+nrWhsZkN7GzHCwOzEMQlSw8uim6Okn XMrw== X-Forwarded-Encrypted: i=1; AJvYcCX/vKuo9Qztsa159xZX8N+fQRor/1r0oJMK7E8Q2j0CCMV+g8c6KxYT/oYoc3v9PXgzg7lMr28BA8dhhQQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywdi71nZEiBiT1/++Lu1PjC5SlrvMa/JFUtzSWtoHcLL6qjmtzv K4PpO1jADg2FlNd0UaR2kVBJrE392RAtIb/6D2GScY0c9uT0yubgDs40 X-Gm-Gg: AY/fxX6qLYwn3uRdRhwYmOX32V0OZ7wECDTKqwO1a8jBBYrf1VAQBs+RM4NMLio6chr jD4WjyI2pUSQmKuAJOURsDrAld4BVNER/dFUJh4THbqSAV3b9BQS4BBMFETCqkNv1yLiIORiUUU nCylpXl0cudDin6dyhSGL7tGMYsm2qsZlYPewX3tO3j6Ub16rqAslVqcTnofH0Sa7BflFHJ1IHS G4NJl9j3EyAR/soezWPjE/nBH21V8T3OhY28duG+bk54s2/I0GVjqqj45Z4SsCqLcUj0oF5lA00 XNXyNqYBTRNhzRQdYQXyGC60E5oY1iNf0eGxG3xC2RkFy6t14Ufkqcs3XdGfLtHni1GFhzR0oZa E6iOipeMDW4FeBGNH8NX6nEpuONar58GhhB1HFp9xD5sIt61VvAtm7HtgMmafBXxiS+rAjyjf85 k1O4UOFfgSAbSVI3o+zj6gefiqD/6Q/MomMBmUaYRohcXfizxm+mGtXIGzrUeJ/P9GkU5OcXT8r 8csIg== X-Google-Smtp-Source: AGHT+IGJWfLGBy47BJ7PbhNF+N9zhPP31NLcPDf0py/c4ZK/NKQFnYsEpUrBObyH1jqbw52Z4Ikz8A== X-Received: by 2002:a2e:a988:0:b0:381:ca5:e893 with SMTP id 38308e7fff4ca-382eaace214mr11548671fa.29.1767716009250; Tue, 06 Jan 2026 08:13:29 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-180-149.bb.dnainternet.fi. [37.33.180.149]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382eb91dfbdsm5256091fa.44.2026.01.06.08.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 08:13:28 -0800 (PST) From: Kari Argillander Date: Tue, 06 Jan 2026 18:11:49 +0200 Subject: [PATCH RFC v2 11/11] rust: remove old version of ThisModule 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: <20260106-this_module_fix-v2-11-842ac026f00b@gmail.com> References: <20260106-this_module_fix-v2-0-842ac026f00b@gmail.com> In-Reply-To: <20260106-this_module_fix-v2-0-842ac026f00b@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 , Kari Argillander X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767715983; l=3442; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=DmmtaDAQNblc8YsS6wVHtlUqz9NIYJ5OZn7ml6apuUc=; b=uYBIMLvMg9r/ZOwGJHxD6HePpybjrDmSrwNbtIJYvgRSrcfWVRaic3h5c24eIiIqJmaUBSlPW 8XKbEuvtZb8A9rti2Mh6Q5HGTetYgo061eGl7iK6Gpzab9/0YztStRN X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= There are now users anymore which use old ThisModule. Also new ThisModule did have couple quirks which where there only to probide fucntionality what old ThisModule provided. Those also are not needed anymore. Closes: https://github.com/Rust-for-Linux/linux/issues/212 Closes: https://github.com/Rust-for-Linux/linux/issues/1176 Signed-off-by: Kari Argillander --- rust/kernel/lib.rs | 47 ----------------------------------------------- rust/kernel/prelude.rs | 2 +- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index dec1d05ebe7b..e709f85ec4b5 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -201,32 +201,6 @@ fn init() -> impl pin_init::PinInit { } } =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); - -// SAFETY: `THIS_MODULE` may be used from all threads within a module. -unsafe impl Sync for ThisModule {} - -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) - } - - /// 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 - } -} - pub mod this_module { //! Access to the module identity and ownership information. //! @@ -360,27 +334,6 @@ impl THIS_MODULE { pub const fn name() -> &'static ::kernel::str::CStr { $crate::c_str!($name) } - - // TODO: Temporary to provide functionality old `THIS_MODU= LE` provided. - // SAFETY: `__this_module` is constructed by the kernel at= load time and - // will not be freed until the module is unloaded. - const ThisModule: ::kernel::ThisModule =3D unsafe {{ - ::kernel::ThisModule::from_ptr( - ::OWNER= .as_ptr() - ) - }}; - =20 - /// Gets a pointer to the underlying `struct module`. - // TODO: Temporary to provide functionality old `THIS_MODU= LE` provided. - pub const fn as_ptr(&self) -> *mut ::kernel::bindings::mod= ule {{ - Self::ThisModule.as_ptr() - }} - - /// Gets a reference to the underlying `ThisModule`. - /// TODO: Temporary to provide functionality old `THIS_MOD= ULE` provided. - pub const fn as_ref(&self) -> &'static ::kernel::ThisModul= e {{ - &Self::ThisModule - }} } }; } diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index 2877e3f7b6d3..66974ec20ef4 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -43,7 +43,7 @@ =20 pub use super::error::{code::*, Error, Result}; =20 -pub use super::{str::CStrExt as _, ThisModule}; +pub use super::str::CStrExt as _; =20 pub use super::init::InPlaceInit; =20 --=20 2.43.0