From nobody Sun Feb 8 04:34:40 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 8576E346AF9 for ; Sat, 10 Jan 2026 15:09:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057752; cv=none; b=ujkVz4hrEQgJRl+kY0k9kBiv1QirkgjszDrlfOPIRsCY8LD/KbQCriwkke7dKdmUokG9cGI59+nsBdN4H31biDtbNUPmlavXjGRPaYmEwmQno/acPBC1NEVKZ27oSHgKATlb8Kv9QCffgqjkzYvYIYGq8E2onbQcqQZ+XDU5Yl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057752; c=relaxed/simple; bh=NbSZJOFudokz6C+njmD0VOJLlYmt/34Y4GRpm6Ry5SM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ddb5f5QjnjFO0uDyAvqaIZL4x0iM7imGKaUmIITv+1ZyhKwh3Ssub0mE0NjWuk/IBs7S/yDjdIIWEhsqI1pmKhtL44njYve5u3DMRsq5aigoxhJDsqu5STnyaUJ0zvxFD0Fj+kSQrugsWnT92JCeKfIzXBfPxBQyVIeRfqTQz7g= 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=eH3Ah2zA; arc=none smtp.client-ip=209.85.167.44 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="eH3Ah2zA" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-59b6df3d6b4so4852969e87.0 for ; Sat, 10 Jan 2026 07:09:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057749; x=1768662549; 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=eH3Ah2zAX0rbaB8aQB3tVqyqJjqMHW9ms7t1kkkXK3xU8tudfeMNA49JMRJb44UkM0 Ir6rFnR/LUWxkQF5Nf0KGruohsVTwO47LOFgwQsjvS2UU6NiFFiDGOytMzqse7kkeRV/ q8YcF28hmBiFBLUKhn4QmEw5LnQrVILTT3ClJ8O8CMIbXZUFVQxr9tzwc7SuUw4Iz2Dq DmAYz7DtCN8W6BDyyNSMlRTlecpe+CKfBHWeD5eQFVlISALtN4JbEI1sb1HiGGEPSb+k 1cQHHZC/wULg0VVTnOxvg3r1JPBONO3ePvFJVkDEdIm0cDSz4iIzmdEihdkIQdqbw5PF Fe8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057749; x=1768662549; 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=YWJ4nUqalRd1cC0Ow2Z37iAtGrA66YAFILR7BIa2g5fTFcE4RtstnY89HnWiOb+LQC V/33D7RLvo6355/OGkTsuUmD0J4QlCl/O3d+16dfHekGHUeWkc5eylG2lHCIZqUmXo2h RUbgt+NV30WYbwoDXorF/dt1I5podcA4KmRBnSblutYLMYeRfDiN0MeelCTnyCy3Vtdp 1dgdjLPYVdrLJhDlDMeolAXhy3/kkJXJH8eoUqA//8oB78tRVpul4lwsRGf89uQJfWIv OMg/qTZcrAzM4QIvaSEuSclRA8MkRVAbRThITNaWjOiSX6+ie4MET+W09Fxxm+D5d1FA hejg== X-Forwarded-Encrypted: i=1; AJvYcCUrHx+D80SjN5hVt6WLj7PRSIrTanBcqe9cHy8n53HHegL38F7oIoATAUro/dLcK9A1ZgwyELTRCXKrWa8=@vger.kernel.org X-Gm-Message-State: AOJu0YwaGl5AKogE08eTXqR2MQXIF5/vh28W4E+IuJK3wTef5oYOtOqh YmB5wCZsVaXQdSrPVnc7o5EA970AapJqPOGbbCjAEUYmQikXhgDsReI1 X-Gm-Gg: AY/fxX5Z+dMackSLX0BD3w2/Y/kcENdMfGOQ+OkuMSFxmrmVhwXGZf3NQoEdU5jYBbO TsupDSr4voMeejuOpk5EgovDPHQc+RcW8YYVZt8SHzA8EXxhh27Lq7LgIwyveWGTVIEiM301Ktq 0WYY3gywMNsLJW0QFk2WUgJ9kyD1oLU7anK/jk6uVJwG98atIZFXqXc8m25B4+Dtv8dERP+kZg+ jUTTdCl+Xv2LwCjLMqCnsAmu78EwZonJhLJi56AhtzlAqAuZE/aZRmu+H8/bDhnsSe8OkkVTewO yo7bxJWB23aW98zHVq4+KLdbNsiPn4IAA9m0Zlg50UH/UWb8NmD6a1Tlo4Ce5iDgnf8t65l2UGj kexgWKs/U4mm5UR3tW0GDiE1EODSYuB/ShlGPPsQnLtiiD4jkOPbDwblA7ftI75qvmFkekE374O 3zwPCOOT3Mj1C4fp1QMSOxzFdia11MBqdwEhZYq+d0p77sTi6SpKmGJ9GQkqvGJAICSUTmtcJP X-Google-Smtp-Source: AGHT+IHBhceUlOKxssp/V2ATdBwshPYNs4sQJe/+zeKAqqJ46EkHQ/gZgH8aiQ2/64zYDmL4eWntMw== X-Received: by 2002:a05:6512:3985:b0:59b:73cf:2f17 with SMTP id 2adb3069b0e04-59b73cf3399mr3933492e87.50.1768057748448; Sat, 10 Jan 2026 07:09:08 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:07 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:07:59 +0200 Subject: [PATCH RFC v3 01/15] 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: <20260110-this_module_fix-v3-1-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=837; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=NbSZJOFudokz6C+njmD0VOJLlYmt/34Y4GRpm6Ry5SM=; b=4vkJvuu2jFVi+J3bLxy06QVBvfjoWAjPvuHGbbprllQZav7Q9xO/ZRqlxXGFrxCXa3bazL5zy va5jcyoAN3cAG28OQlcqT85GHBUcPBR4z1/do6sC61LQ6JNh/kU4qNP 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 04:34:40 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 8B6E0347BA1 for ; Sat, 10 Jan 2026 15:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057755; cv=none; b=gF8tlqm2n3T/qE24klM90R7Vqfe/EHIfmRl7NPuekhhHHquBbw9P2LV95RO/fP3FilNrCH5zQcuIpe+DniVAtHSznwrjtj/j3q1ik97Eu45uNLHgFO96dJCkmIvK4bQQn0REQZmYqLrWB/5XSwe0oyDa8YQP5ipvUnjBKzaDpeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057755; c=relaxed/simple; bh=qllvw0idDXOnIB0CGwSIi/5rAB72aSN88B6VHNRb1ac=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ActlfiRsKhb1C1IE5hCVi2iHATTXEneUgl1Bq+rhsj+wtykyq/svqmV0umoMhtfmEfWzYfJNf6PomJcTnfkV+GykNePD5XsVNTsTb5sxgs4m5dWcDrnf6PYUG8U53L+u2HvdA67tRtQbZ911L8xK0tt2HWOmzMoxiFKKz+oBu0U= 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=nL/Z8wuP; arc=none smtp.client-ip=209.85.167.51 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="nL/Z8wuP" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-59b672f8e40so5491080e87.2 for ; Sat, 10 Jan 2026 07:09:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057752; x=1768662552; 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=fykazAZF3HAYQpCFJz/nzZleds7CiXZwx2GOEkEsWOA=; b=nL/Z8wuP5dV9cd2rzWHMj8Vl+Jw2Oq1KWSIFAnCNG4QGPxyd4bCy46qxgkJHfy1hXS iu8Zww88lerMDmAjbmJAhSgqJ6eyANiF5/Nie9lDIzZ76TqvvRfNOh022hlidJ8FSbwp bjHW1IG5ikP4rGUuKFFfsTQovqaYWrD5A2SLIRm7QNtUN4PAq1LXX3D+lfdgZVRbo2ui WwRvN015LkB6cn0iUQm9RJV+tLuGqU2vnX5xdhUQfbW7blKA1uMLeq01HSabjN0PNwh/ BykeTBuSbeEvr6jBFcP8aOCzkX2FObXYatT3javxbpkyApbZ6lyJg0kYKjOhveimSea1 gMCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057752; x=1768662552; 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=fykazAZF3HAYQpCFJz/nzZleds7CiXZwx2GOEkEsWOA=; b=H5rmn91hA8ur2xkvhfUfD8Ur+Clqvki8+YNUDyKwYWtn95Gv181ELil3hDW6sad3Ra aUGTJ9C7kkCuLWO3+qrWYUZcutcL4j6El/ogsWLsLUEHC8IaO66/YEAygMOyIkOxlxW7 DS92lvzQnxrF0QyInH06qi61bJ9SbIQjSmFFIX42epdbJUYtmtq8WWHOXfFddq9qzIYV 1CZW6JSQihybC4/a+zO+RctSCHRic636D1arerMIojGJvSrkXQGU3Rj597bqNpXGAYTB wQhc20VGJNdXi9rbhgt14CffZudgH0hvWKHwXUDa9+BirLPIsdTAr8iq4dGACI6YnhQu n/7g== X-Forwarded-Encrypted: i=1; AJvYcCXPGIsGFdiZDq0WIXZ5QiMZtnPrqMywOQqWnuZAjEj3DDoEuW6q6xim83mKl4Mx739iXEHxx0XlBTteIT0=@vger.kernel.org X-Gm-Message-State: AOJu0YyrbpVmgdPZAV+CL01CI1CjnFrFm92cOggQsx09EyUcVmJEUloh nRDIBJDN9/z6KRSZVam5JzJB+9oIL1/UZiTJp9Zuqs7ZZZVQ2XJ599zd X-Gm-Gg: AY/fxX5nxy1vbvhF9MG7Vibk1T7DHz7Vyw6oy1OUnZHD6ZGi0Kis8iDR+51aF9C1Tey 4yD/Eg8Qf8ZD1sTqKkhW0UqDYeCrZh0j5rgniz9AJ5Ee3N8qfqUm7MJTuKOh6+UskWsbL+kRham TeX5+XAfdPHdHjID7U4kixbXtpVjCYeGUvfARy18D3YxDeC7QGZkYmlWkSouU9b+ekUqHoX7YDD WeEFwwU36eD1PI94viGVmlbzRKy/r5MZTtzcaHSFbQFo4FhRYs0hU/8BhjSuX7+HznqhEh2shml ZKLuzOSMaljv1MIn9uGO6dkvjBeWFZdX4bYMC+vIe74xWXUbeSoZOLvdVMKvq/KSQjsvAsY5NRz 8r/3S7qxSYM7rHfiQS/7tc6/MxV3H8mFRqgqErQBi8PcqM5y//XYtA4atZrQC+vMtOwUkHsVnrO XZVN7K/uzGjYO3O327DmAnqpJsEH2IvPMf4ZUl/hGsxgBwLWOJI7agWlyakt3IZXbOuxyyVNIt X-Google-Smtp-Source: AGHT+IEa9C+0IkOnrnHmgn3qNoR/RdYiVg8QdC2LkRqOYQv6fDShjbGBuOp8BKFt8hTS3edZ7zPsIA== X-Received: by 2002:a05:6512:1109:b0:597:ddd8:cce9 with SMTP id 2adb3069b0e04-59b6f02b24amr4151383e87.25.1768057751330; Sat, 10 Jan 2026 07:09:11 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:10 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:00 +0200 Subject: [PATCH RFC v3 02/15] 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: <20260110-this_module_fix-v3-2-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=11964; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=qllvw0idDXOnIB0CGwSIi/5rAB72aSN88B6VHNRb1ac=; b=3cDQVG93FqvGZl8dIN85pb9TVrWhh87GXa5i5JbwoqpeZ+oywsG1SWiCNte6DIiDqSNB+eFmU Fj3hdrardI0AL1Bfn0oUlBY+78DlYj094tzdD/gZ88mnWXomTrAZ/UI 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 docs examples will need THIS_MODULE so also define that in docs. Signed-off-by: Kari Argillander --- rust/kernel/configfs.rs | 6 +- rust/kernel/lib.rs | 159 ++++++++++++++++++++++++++++++++++++++++= ++++ rust/macros/module.rs | 16 +---- scripts/rustdoc_test_gen.rs | 2 + 4 files changed, 166 insertions(+), 17 deletions(-) diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 466fb7f40762..fe80439ab21f 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -876,7 +876,7 @@ fn as_ptr(&self) -> *const bindings::config_item_type { /// configfs::Subsystem, /// Configuration /// >::new_with_child_ctor::( -/// &THIS_MODULE, +/// THIS_MODULE.as_ref(), /// &CONFIGURATION_ATTRS /// ); /// @@ -1020,7 +1020,7 @@ macro_rules! configfs_attrs { =20 static [< $data:upper _TPE >] : $crate::configfs::Item= Type<$container, $data> =3D $crate::configfs::ItemType::<$container, $data>::n= ew::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] + THIS_MODULE.as_ref(), &[<$ data:upper _ATTRS >] ); )? =20 @@ -1029,7 +1029,7 @@ macro_rules! configfs_attrs { $crate::configfs::ItemType<$container, $data> =3D $crate::configfs::ItemType::<$container, $data= >:: new_with_child_ctor::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] + THIS_MODULE.as_ref(), &[<$ data:upper _ATT= RS >] ); )? =20 diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 510d4bfc7c2b..4b899f75e56d 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() + ) + }}; + + /// 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 04:34:40 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 B704E346FDF for ; Sat, 10 Jan 2026 15:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057757; cv=none; b=UAxWqUmFdBvAcoeSNqKKtaC/p0mspGRjKmlQVA8E44kaOiEgZpWUO7DwWmpLl1L1sSrxIMPh1URgRKEaC5Oqtlt34xCUBCvepTjg+cA3YZ/pxmLjsAhFfb0MjDJ5FhXnVZNBmNKjGw2TW6bnsnuL6NbX5YXJ5WoaTE2I0nV2yzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057757; c=relaxed/simple; bh=891dg5NeMMgINCtxfUx5z2GhTLzUtO+bREujFmK9Vxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WtboTbnVQXVaeYmuHB9QrnOWDzHcLdwVGblDzTnSubGOlYHZrVcYP2dJNu4yY5wyo+Fs0T6MWx3dApJTziwPae0p3PtgVdBv/7NfCDE/nvr4QCgJULnypMytDRUwogtn+2Ti2bDvKNopN+CjT/+vrcTG83+NZdWYPDH1mILNWO4= 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=Ns6wyTsC; arc=none smtp.client-ip=209.85.167.51 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="Ns6wyTsC" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-59b6c13b68dso3378827e87.0 for ; Sat, 10 Jan 2026 07:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057754; x=1768662554; 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=Ns6wyTsCKAFNVbWzJ1CxIRn0XdsOkvf17b5zSed5MgBzEiMnkcrXMA6BDndyqA6AEK rIdJdkVRWlrr+uTu1cSGgeKkHGLCIj7qEjch6uhDNx6c7TE/M2JwqEBUWVMEk6HNelyf +De+i8BprT9w7faeWuqv2MVPlgr10CskI3Ysb0jJSiBPA129fdDgpKRhKWysOc1NJ9YR s6nFrN96bXeWIMmZyUy7b+Zlj3wcKZ/ERZMHNkhnPRSWCeAV5Jyybq8xyRl13tL7g1aV dXzr/+W48k3r8QETM+e2v6OV5WgfXG0BC9v8GUfVIbgCDtGQ5xa9+/B6I0/6ofX9duB4 HloQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057754; x=1768662554; 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=Nh7YmBH1Fvpnstg4LNbr3iPAqeN0aNUvAyMa0jF0BPdO183IKrIhBLjb0KnvtodtEJ epFDtvM7e9REWfw6SLUOmsveSAsQl0AYaQKBoPoVu/y/q2NEjE94u3dgrbFqF7jB9dVM 3goJm2/XbvvYtX4YS1cVrXudWmt9VzL9cSCVqHYsFGU/86x87KRROV5+To2Da0h3jJg/ cJnShjSaYASPMpL/3hivSvRs6BU/WTMPkNI5VaWZUSwKMCIOQeV9L531+1zkQdgqd3eo c0PICwMKlze1GZyXlBPGPRwlTsMVZT6YUf+zGYGdcYqmjHtkecKIGujA2IBrhx7GTWY7 K02Q== X-Forwarded-Encrypted: i=1; AJvYcCX/5p+6E9maKUzFwIc0Tc1UdImq/ZFHja9qAANkHGahRlC5MwU+VoouVsEGIwJpPmvZAYmpri4/N9JKYlc=@vger.kernel.org X-Gm-Message-State: AOJu0YwkhXQXEqd3f4GKDqNCt0hEGccn+GvBgoThY6FSx5w+OeRs0k6c nUK0l0UD5QYxT7/beUR8DmLaHYejGokP5vNm0sRjGxPwfCs4fuoraBIA X-Gm-Gg: AY/fxX5SBQiSazh7/O9k929unMyQSd+DlOBZFbYtjO/RVqXwbKf2VVYraPtzKFgJa0P Caf1FZpkaq2ErCXnHI+mXDB2P9r3rQMIkjiwk8XqqmubxTcQ7CuGK3zqfd7As7fgHX+bLtXJiWU UuwdJhhxPQOpiwORGud4x0VJgzvcWolpnF5RggHcga0thnBbQ3w+XmE+3Qpf6QDHv6Zz8ebjqP8 T1XbxP5JCreWw8LJDvNWzAlH83yxA8anotGJvpOTy1yzSQPYN7dS5FUrrbndJnOOu41g8UxiBf1 HHZ4UUU/rHYZcEGT0IxpmPHwisgdHAxGx8aBBqsWlT9xUW/8KWUiobArKBHtPi4xH67W9C4E4bD Itce0wDBKQfmmzuMDlDCaAsC3G2wY5u6eejmDBs0fJoLGYat0ymw5MJE47gKsYl7yJU7iGxT9zl dVKKgSF+fj1pQZkfHR1cAGGC+BrYSECG6y2q8mAVuhwqafAxBQIcp3PyQmanJCNtHN6y+szb8X X-Google-Smtp-Source: AGHT+IF15/eRGuTu7+wp+QYULK4KR7oRPF4/q3DNB7vZeYJShFYAC050bMH9rb7Ur2PCPfBPy+O9hw== X-Received: by 2002:a05:6512:33cb:b0:59b:73b9:1f49 with SMTP id 2adb3069b0e04-59b73b921e7mr3815567e87.26.1768057753607; Sat, 10 Jan 2026 07:09:13 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:13 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:01 +0200 Subject: [PATCH RFC v3 03/15] 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: <20260110-this_module_fix-v3-3-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=2370; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=891dg5NeMMgINCtxfUx5z2GhTLzUtO+bREujFmK9Vxo=; b=YGFU2Mudpv6wmls6LVSS+C3zLULqJaxqGgs9hMIwnNZn79Pd9ugTIDLVe52c0ThqhL7w/+wS0 cBq/kCyOWf4B6laeNZScBjMawlstvNU/8l4e7/MRGSL/nd1oFpEZQDf 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 04:34:40 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 137E3346FAE for ; Sat, 10 Jan 2026 15:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057759; cv=none; b=cDsiCin6A9eqsUDWsBvbNvioDdQSKNuzuCfpoKlG+qcDpOBuIFiYaKV0NGvH0l+QUBiwolHVWUxfgVqDAgQ4F4ZfbV1e3yEzPL0YGpgnfEV+WgHgeWKQOCd/GlzLgZbtNy5ap9y2p0VL2PZMav1KApQkg1mwAGgGOObV+TsvUvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057759; c=relaxed/simple; bh=PsulVulBYOKVhtxVFsqQzoL1KhSmhEASbJ2jTpxpE5M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jC66458bzfuqnG9cp0SmgD3ZKDDjTiPAIUGzSIEGsrb64l9nVVxkdJ9/+pM69gGMBvEf2RT724tl4mzki5vgp2qYnyJZavfX5/ETtd6DmLjbeERAc/wG2PoE3Lx1vkKCOTsx/dXXuYRVzpEFKNpAcMT25mRgvstAyC9wPV7tnwU= 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=fNB/2O5V; arc=none smtp.client-ip=209.85.167.43 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="fNB/2O5V" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-59b7be7496dso3001444e87.0 for ; Sat, 10 Jan 2026 07:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057756; x=1768662556; 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=fNB/2O5VPaQcMjJhRn9ooDDxdhrbWQ2tJueaNuRkADCw0wUBB32pLXyEQqVjC2OmBy gzD7nMLV3fR+6bNWtPDHocO07nop4UPL1OcOuAaI5F/Pt9ELjrqIOiLkk13KG9OpkQgM ffkCuCnpwLItPzPMwJVkjhEKhDcKRmrd5CZ2E0cIxcdJzhV9pAAsN7p7Ub/VIOmCYAVz Z9975GGB87swDXv4A3Jf/7Iw7ouO8zz/8Hk8NtTQuyqtIpW9Fct4VQOm1eaDklBLD4Ti mnlLWzJF3mj8yBFfximGdQjt/s/MD2wWnHiHO4GIUyE4krgcIkp/MLSUqRR5lL9AfNkk GQ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057756; x=1768662556; 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=PEpAfG7AqpL70ajhVS3a+AwEvZI+i0zXbn7aX4whRCMA26LG6PaWC9d0xyoP36GNmL VmrCMjsly3Q1T1xjgDGgG3fzN9PI9HAS5sxW2XzFQB8Mvsk0gMk0IKIpgm8mvC0Xdk05 AGXm8Khp4u01sCGaK2KYfGGAcp3/Inr2utCqrSBeGb9SxyT0wl7arIALDA7B+lQ9+c95 qq043xqYkiT5qFA7O0BRU4H2N2R7vfrZ1wWp1u+4vjlk4OmdHGEMQuuOK2AquXUFizO0 PSmEkAIMaxITw0UJtJsam83i2demoRRZ8xUBcW06vwOs+77fYhXIKN5Nu/EWH02Mauy0 S5/Q== X-Forwarded-Encrypted: i=1; AJvYcCVZVQHZfIOt1osvVukTmuW7fVUWcSGkiZmT3qK4DS8vAE/wwci0bDnWoTWYWGrviCqR3OylUoGOBuzwo3o=@vger.kernel.org X-Gm-Message-State: AOJu0YyCDyFv6A89E5w8r9TT1imjLElu9AqRjGVIduX5pceqOqulXLqo ns7JSZ2UpYOqVrSWF8TqoFsQ99T3jiK+Ak66JWn6uvnf+XBxkoWIdCyU X-Gm-Gg: AY/fxX6kVNC1D1PVnOEURUHjJ1PAi/Q/HZIzw5ajC7yQWP9MzNp74t6jhYo564Oe+hg l274YqswI1Mq1lZnvMfBf8wo/W1ujScJeD+cH/9vI0U0J/24AkUeCIkQSpEd8tZGlIaz9rpeaTF Hb3WkBQlUzfEXjmYBjkHWGcFH+OwfgFNmKAE4XDSXChHK7JVAYDXJ90I8FT4MAKZBMXjvJ18ZYt PTX1rdHkxK8gFygy6B3M2Ge5MzcbMyhkLR98BFzl9vkTIgAWwznI4Wi8eBbJlwEP9Mm8i2Sye0K E+Qb8/Rm86bR8IptSMvtFNrZytelqXvdgM1yoAzJLtrycx2hQBB+auLarzeh5cyM/vCGC0YxgVU LTHcizEzvDtWvEjqOZJFB5IkLWmfj1GfgEKw8zOWBmtq8wQTlzvG9vKjQGNVZ9colgDlF6Vl++g AWUg/E59VVxjc9jvkLUVnZRI1h5ZEyoAqocWm0w8SpVEsN7ygJs82N9zW3u8TPBswL/zBOL3IK X-Google-Smtp-Source: AGHT+IGlt9Yv8sDeB4e3Q5NwnV4p5lgaXKn9ea9qedHkfBs0ps8vJj79GZDi9RawkBZhq22ruSs+oA== X-Received: by 2002:ac2:4e0c:0:b0:59b:7b86:44d2 with SMTP id 2adb3069b0e04-59b7b864515mr2191519e87.18.1768057755950; Sat, 10 Jan 2026 07:09:15 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:15 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:02 +0200 Subject: [PATCH RFC v3 04/15] 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: <20260110-this_module_fix-v3-4-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=5351; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=PsulVulBYOKVhtxVFsqQzoL1KhSmhEASbJ2jTpxpE5M=; b=185gZsCt1xGiCyXyEzSPP0pAcZ1ipKyoiLBT3qAgSvAHQ5mewac9KEA/SJgWHYzP0ShVf4l15 sTw9hTUbbf/Bpj28SG+0E0IafHVZBRm1xGY6ElfQmn7afXlsCIbrPqv 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 04:34:40 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 2BB21346FBD for ; Sat, 10 Jan 2026 15:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057761; cv=none; b=ccmfgSS1wJM0iJyqk9zlrrmYjlq9ZrIxzZfiBas9HozIhDVBpIHDch2lN0zPHRRhacQG3Bxzp9FUcNf3lARE7YJbSa63a95e1hSLBpAvb/5ICp35ZOEaMGNuDKOuU2RWcJrekJKKmHC90ur6vCTO6kAjWVKGd0hOKP7Lw3/b7iM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057761; c=relaxed/simple; bh=pObMsqQ3xkzVkZ3cfdHVrZzRa8fls1Dett+yl59GTWk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i7XN7oIoW1BX3BGqc16x4r7bDY0Y8ZHzIAWqBkR+F2l3+myVtlMJTRvDqrwzY/EsyF2/acL5VwGrzDfjlriOjTlBR0XTPp8zAYyAGHPuqxEWpsjJrtxNpFfsgvjINGOPuuzcNB9koAv224OV80bNLCeDmfCBxJ9WM2EIu8eDmCw= 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=NNkkbRo6; arc=none smtp.client-ip=209.85.167.43 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="NNkkbRo6" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-59b7bb3b913so2876923e87.1 for ; Sat, 10 Jan 2026 07:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057758; x=1768662558; 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=POe8fbaXk5saKFPceg6wmKUDp4vPexwP90O+JTHpGXU=; b=NNkkbRo6aZbyc06RlLk1lH6ZXqkmowM+l54L2ZcMX1EWCqGBDSx/t1ut8jyp4lLRYe ZzCPCSWbF/6nHNtqketNdBc2Rs4p7n2NxODS9mhEDRzCdo1MGhtrdqPwD8DbgL6uNHEp +JzoXSp0L3AE/dwcjuAhG1QNca7EFz+yoKTogTRFxzd/Z0EO6xaKOdwtlWqLfGlbCMpW UUCObZsH7+dk9tGaTqseR95BAjGbUHC91fGzO9zB+oZDtqWirktvirSpXpWfjTmF2INb 9xrWxT/xIyI+hdRoz5Bj4Ty9XT5xytQNk0sMK2V87pfWGaAh6ZSnaZLe9NdgOtsBNEUc YHuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057758; x=1768662558; 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=POe8fbaXk5saKFPceg6wmKUDp4vPexwP90O+JTHpGXU=; b=vkXh2HU1XKW7RtJtSqbIlYMu9F8JVJOC5F0cUJnSf2khwnG3j6kVm1c+zoKfjjdDlb 9rgEfkU5ui4YSYK7xGHkAh13PDH4zoWAwHNAYIX9ssKm+v/Z91Lsut5kIv9B91zisz+c uVmJRPUJ9p11G6xonJHrvgK22F9qgeUW+qRQNSdeYRPJuaI7arQ2YK//ut1J/A0csu74 3X99tGT7UWqbRbU20Oa9nGNvDgoQB6T7p8DOoNJtow048qkhj7J/KeCR4KqqXWdQiY06 AyDc8/n29YtIEYTso/l7rxaxiFdRK87XrPPwxolObsQzkIlDGMei9gxID7dVBOSS7KYI bkhg== X-Forwarded-Encrypted: i=1; AJvYcCUk3SEgdNxbXQenDqSJQAIDnGrHuzL7Ggxeg1qJqbqmD0eGM+qmqt9RXcESX0fUJEkeeZdD1wJmdPwqJfM=@vger.kernel.org X-Gm-Message-State: AOJu0YwXEavWEZCKzJIOw03+J2NkWjw63GQbRLSyqQTk9O6OOWbZjpjB 1f+gpC2UWlullm97wKrGcmbUmRcQTBWD763OJyaV8RJaOeQRcau7ALtl X-Gm-Gg: AY/fxX7rdoQqdn13EnSn+LqsXljyskNKZRBzlc/gadsTlp8dnyeK65MfNudqhywX7WK xXHeJIvqR5EsKxyu76Y3WmK0QF0coHccrV6I7J6tCRio3VuuUEEaEpKuK9NrT210kIctvJ5EM91 4X1XObr9TBQntzE5nnuYbY6iuvn61kitsfAU9NT1boEDIw8D1XQp1i3oBbm0CmTYirg18gRTExG uLJ1FRSczAKEbBoKhK6uLsvoJ6A0Sey1Ttj6dIPtg6ECRXayGt1IDr51qVYrmdN0OTcGf1h53aw rJtbfJtmcHXIC3HP10czz6f16haoqeqM/hXeiwMWOnFNc/U5Kp9GoJvan9F5XB3YMAoGaPJ0H78 K7e7t8zuFPDWCbuNFvNsZxbhc8FSNUQFHTBnLksMgixrHSYV4agkMbKH+c4sZalTZsBANNhQgNJ Cr8Vpy0i+W6BF3qlb9A0NDJstGxUwAKLKvD/57JfR0vZWoO50zGUthlSBcASuRDBAv/HF4EhGt X-Google-Smtp-Source: AGHT+IFNLBJQ01WunUBd430d8tTEifFvMoI0XyeN6DoOTINO7+ijuLgcerNFWqW0B99vr+losLUPpw== X-Received: by 2002:a05:6512:2117:b0:59b:7319:1178 with SMTP id 2adb3069b0e04-59b7319121bmr2477799e87.18.1768057758332; Sat, 10 Jan 2026 07:09:18 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:17 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:03 +0200 Subject: [PATCH RFC v3 05/15] 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: <20260110-this_module_fix-v3-5-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=4166; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=pObMsqQ3xkzVkZ3cfdHVrZzRa8fls1Dett+yl59GTWk=; b=7zLe5lryXy/9T6T96fAXZ7YJeKt8qHxw069TB58wLHh6FQK1Lc+lOPi4kQLZ71zfyr/Y1nIP9 SPGhEma2/P/CfpNojS+bq8ykYv3iAGUyS47NiSESO5YlCZu6vHqAVfF 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 d49a9ba02635..705afea65ff6 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_operat= ions { let mut fops: bindings::file_operations =3D pin_init::zeroed(); =20 - fops.owner =3D core::ptr::null_mut(); + fops.owner =3D TM::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 04:34:40 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 D68FE3491C9 for ; Sat, 10 Jan 2026 15:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057772; cv=none; b=fb0cFl1+Uhb/6G0QLQEKcdO2S2yyp7Y1XE+zbNZdoXLjAY8jXG5ES8PEkf3/mpHHQyu0ljOkwHuam13bkWNqorHW5SosvuYmYqImzFr/XnIl2QFUbmenoTZA948KYZaMisdxhhvRPjRrQHhP3k4ffVKI2HhJk5jKtCfLb4uqEoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057772; c=relaxed/simple; bh=1FB+uT1pALfUGFef4CiqxjN0XjuunSUgAxAx5cQ/hwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bdVJD+dUbwltbJ0FKMJg8vudQd5j9eLeIcU6/aaPvDqMJUIAqtrp+x01FruGg9OOsCKgAPl1u1iCuS/A4roGPMEijxzMrWxoZ68BSWjqSwe5Nf1imeQL9Xk+ee2d4kIENBhJqdE7zw+Ckd+ycMzt79Jffx5qEwyxJwAqXJ7wVbs= 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=CKMMlPNv; arc=none smtp.client-ip=209.85.167.44 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="CKMMlPNv" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-59b79451206so2365450e87.1 for ; Sat, 10 Jan 2026 07:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057762; x=1768662562; 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=Vqf7LCg+sg6Hx5J5qs/p3xtmlckbxwDqMrE5j+qRjSY=; b=CKMMlPNvXpMm1GvHDNAatxWV55AUHOZ/PGrn124XPDPrWuSgUdhRqbmUHGlZ82BJht nDTSTcpsiNo844EQgZ3vRE3LIbgC2L/2tCwAtw57a3RBAnCAc2tBunEZLSzTXwO5hQkt Z6vfxBO1KrdwOGWMk6hMWGHp8ITA2UxQYbDFMEIXcT7HorZ26Y+U1wUNBI6rCV+MhRN7 6Qm5OtL+PKlAL5O0Rg5NGEdDiGmuEuq1/VCWt+EHHMOm/h44SEkzvDM36OYNJFCPt0e8 6umbr6gRTqplzwwdwSbSJP1AGItO/gbdTOcIr0y3MJztwvAHEDHcJhdPsODc4nqFxxog 6WVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057762; x=1768662562; 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=Vqf7LCg+sg6Hx5J5qs/p3xtmlckbxwDqMrE5j+qRjSY=; b=REf81kByeAIhn5RJiUQCVa3J4xmov3QiD+eSaHvuykDF1VK+3ktWTg5gcFv3Yrjd3L A25r9ejKDCsYX957ZP0/tAO7IGkKYemCX9YrsOj5RvYFpoA0u4uapx/VXWLfvhT9p8k1 qC+pkC6K3X1xDCsGelP7lsKNExULjkSo76OonCe5Fi7EpQofnF+dsdwSsAAr+AkoMBvX CSBvnFqgzSBhA9RuFQmqpzYtM/9NNYV3T4wdyLsEcN5RmxxyOD12b826H34kKBoFRyoq MiPfXzzFCxHryGP0MHe/JB8MbzsozwbI+rZKoC3PGZ1hZ+sRwCELHPlQEmzY5Mtl5bhS g+SA== X-Forwarded-Encrypted: i=1; AJvYcCVe15Rm4v5vx83rQ0/QTHlKkExZXUTves8KRR+I575fckaYtgWvaZovz8wMUDCrpQF2qRPINjpxtk2BHWc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3pI6tYxpqS/wPMQQqJXT7CqTD1r6Y7JNNEjkPARTlCPCB9yp5 DoAZ2HG6h9vqE0ZRgcZSszFRNCVAj1FUDA7fmkx/g6DZcHDxMCCXadSX X-Gm-Gg: AY/fxX6/zBSByiK6TOZ/WQhkQo8B3j/m570ImYJi66RtqVcDlI5LvWJPWPFNmrhc86/ yt2UagJrkro24+hJ2W4IMU79Kgq/XfyyH78lZ0at5EoE8qdD/WnhRUQo5ALvE2w0DQmHoi0oYuG J203nBv1mQzsWWK/e2o8ooWU3/4Reb8O0nVsQw2+yKAJXvtpa3drOTPxmYgeHbn7lpKsoiuuK9K 6mnxqu244iqeV0CPoeVkt+bsdNFB/BEMD+xSYqO6UnXEGAAMvdK/Or5dxfXPbX1QhnofxqDwluS zIlWOCJWnOpXu0e4E9f03EMarfUWYcitphjrilkguE5htm6/m+lALViInx19mawSvX7m6L8h7Wr eVg4xHk0fDdIkg9rQJfXNPlbbr6x7rOyBLKYPiqcsmz/5EoCZND5IufAdPKbDgTW98iQiF8zW/4 75eX1gIE3F04hd49a1rJUNMq5e1PNXb444WQi1gWrqTdTbhaf2++uQrmKT1aHqtvQ7eYDynYOK X-Google-Smtp-Source: AGHT+IHEE1TGipeoD2/6eyBBIsojGiNqm7JwcbPiYjVFBwHDR5nwSai8es4nGi6I/fgjxe+bGdX/zQ== X-Received: by 2002:a05:6512:b01:b0:59b:8483:8d97 with SMTP id 2adb3069b0e04-59b84838e5amr1204577e87.13.1768057761899; Sat, 10 Jan 2026 07:09:21 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:21 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:04 +0200 Subject: [PATCH RFC v3 06/15] rust: configfs: 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: <20260110-this_module_fix-v3-6-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=5277; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=1FB+uT1pALfUGFef4CiqxjN0XjuunSUgAxAx5cQ/hwo=; b=KTu6JmsvpKxaB1JzW8EXhr264WUGMX9sqMRbv98Urte4QvFUB+KimYWM6CyVbNCSLfejIngg3 769ilDyNnBwDbNGyi+QKw7almLRAojJtFeFDvsqYuTex4HO29lmm4rN X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= We have new THIS_MODULE and ThisModule is now trait. Pass THIS_MODULE as generic type parameter which is current convention. Signed-off-by: Kari Argillander --- drivers/block/rnull/configfs.rs | 2 +- rust/kernel/configfs.rs | 46 +++++++++++++++++++++----------------= ---- 2 files changed, 25 insertions(+), 23 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 fe80439ab21f..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.as_ref(), +/// >::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.as_ref(), &[<$ 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.as_ref(), &[<$ data:upper _ATT= RS >] + new_with_child_ctor::( + &[<$ data:upper _ATTRS >] ); )? =20 --=20 2.43.0 From nobody Sun Feb 8 04:34:40 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 8A39D347BBB for ; Sat, 10 Jan 2026 15:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057781; cv=none; b=rGp0rFv8TakMuU9vkiQsmoizU+Xrt8pVqQ2AR48NAblGU6StpHv2QJfoQEcy3pKIZ8f8gVjXlUO3xA1jLzM+zSIBjYZoeJHQpzFS/JsvytJcV8LCA0PETKauFRoDVHALX5ucEGQ9wp4YxlzWvgEh4QKqQCLQ6CMlIL9J8qqkfjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057781; c=relaxed/simple; bh=HXsmrNNEr+H1R93npODROo6Md8lvxfZavxKoxrx9XrE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WgyQpRM5Sat6PqN8JqhSpZxBMzaO2vmJm52tmTx2v/BVwE6nYGyyYgH1crFaHAHraDRCiWY37kni49e6jVTQ8RkKWk8Oj95W0KodvXy24LnVCq2V93Lo/fzEOxewZrnjnf6yjJv54WWXWKMakM1lluIPRJQc1chFrC/OHEsF6lw= 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=LtrT728O; arc=none smtp.client-ip=209.85.167.54 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="LtrT728O" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-59a10df8027so5908192e87.0 for ; Sat, 10 Jan 2026 07:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057766; x=1768662566; 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=LtrT728O3amQSkF69AUmkAC7v5yMmQ1cauMk5K8evmhDhZBiizof39/SelMtMizRde sn4JS5sENOCa3XDLCe5bwrpe7aX/r6cRKm8Qe7K/ZaPfuajn6AcKa44VE+UvHNHcdjIo 1PDLMasQtZa7hMUD1sHrphJHnSuvBVohEzeb03piE6Wp5JcrdZ5KgwYAFYTpspvyI5wR /oq9yNUKVUxCgxQwfy7QVv409/9bmX2xDJhMvKXJ0vNsUnHXp6p6IMN1IQBsaF7Hm/yo g5n3bQF0xCjHkdQ4TtBSejYFFF3anz27BK5YxqDE5EgBRvVq2LaDYDzIr+s7El9QzAcL Deig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057766; x=1768662566; 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=jE4bq30i3SDb3Ju1aZIwQMrtcBdmVghFqjsXZJLhJsp4nEykacCytOnJpFqaENzebj pFgAuvdxsl0sssbZVmof7qjy7ktIYgN5FkYxXf5A0Wxz+LJ6Gat4K3R1v+VueSpxFCJR xHVookiiYqjDXtHlS+Eb9Adki8TfMlRvLaTY2/faVyoJDh0Tbp2W3vc6NrhBwJJmJ+fi BBKJ/tFH/THlWlucQUyAh5QGl97RPEfSshxM4pQ3KTeeCCLQaVTx3K11R1liIImkTcxy xTWp6NAf9/BrDfhqLI+dHapsA4vdeVm+M2T2czcx1GcJ0l56/T7bT6whN2i36GijHeDP 7nHQ== X-Forwarded-Encrypted: i=1; AJvYcCWwt0FDxQzwqW4tQy82p3hFNkbUar1CRdYZzvSylr6tQEHn0FgFAtJmdzt5ROqyqwSLCdTofaiYW5RkRdA=@vger.kernel.org X-Gm-Message-State: AOJu0YwFfAr385V6PE+0BaT3RPaOEZJsNMWxYXdxsc3pLxisEEx6TjqW lrxDCBqzUjqgky1J05eXlYmo1CWzTqH2Aed0ptUOe49djdGfBT9FZAuC X-Gm-Gg: AY/fxX5qsDujCnj/WA0WJGWTg30oFdWok20XXyepiN+9gLNiZekfAN1pBOfuhRRMtIB SBzcwrU2qyQAoMCSNPOGomusBjwLmo+T4ysi5/Mhj7KLAfVwZNtfKaVZHRPX7BPZEFhdvycx0pP Gulb33qxIFTBi+Z46vh7wNpzx/y4Wh1AxELghFQ8AZwqf3J8edDk4sJ7qKZDYE8HUfgSE/xR+aQ 7ZP89JblSbC8zAMndLZNP3d5pux7WmHUNYnZg2/KHDn+73VzYDLyL69UcYtdZ3um156BKvgu0Un i6LQqTk2f6qQFW7uRhaGvqTSm1ihcSHO27jsaUCTUhnEpe0NorQp8mQVeEadzbOpLspNpjQyZDn kLkcf1rfqTHHZZdwgpfMD9FKOITLLg227YRe13JNVIgsnFuWM+mgPaAtPX3+89hShmdu79i90nu SeWt6R0UfAE/TtuVbOa2HSWBqkGPrCvnKLUSjwr06gMPkNzSt88dgZ6ilT7VjvY9KxODnu6iCv X-Google-Smtp-Source: AGHT+IF5pkNobwqDdpJnVvMJj9HNo5dFu/TJZ8O4ycgXj/UHfAc8hmVO6+l9QbYPw5ZRrk2F06noMQ== X-Received: by 2002:a05:6512:3d04:b0:59b:7fe7:eed1 with SMTP id 2adb3069b0e04-59b7fe7ef14mr1809283e87.28.1768057765447; Sat, 10 Jan 2026 07:09:25 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:24 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:05 +0200 Subject: [PATCH RFC v3 07/15] 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: <20260110-this_module_fix-v3-7-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=1238; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=HXsmrNNEr+H1R93npODROo6Md8lvxfZavxKoxrx9XrE=; b=R0q/X1ltJqeYVBP9SobLKfHgM075ElagNogpcGU3GkRvQ1n9qSEzsNfW83i0UdVRRa/JUGwAU bxs1cBNamQBD2YNOSaU1QhJ7S2BuCHBpPzzaT5E05h1XEXN8E9VD7v+ 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 04:34:40 2026 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 CDF3C346E74 for ; Sat, 10 Jan 2026 15:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057772; cv=none; b=UDJTDGExL19CGjfoHb1F7OkLRhL5I7Td4oLXGM1GDnDt+zD82d+6222hYjmorhGpHC50d+WoaE5W8VGqyiVJt6M6iT/l1t1kYWAvSYWkaAGKrppvH+LAirrZ3OhbOkfBCS8BHs3awb7oaSugAUci62jVS9yiejW7Ans5MnkCzSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057772; c=relaxed/simple; bh=W71manYc49CiWAv2i0/k3IAXEeJXVcWy8Fdli+uPecw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CJ1IFTzTBewxnUpwhSYi7BdeS6q/WTnwNlH3waR94STpSji1xXz9vL4YerNpc6VVMTathFVPyoH21jQcM2uqf6zrYvy0wxq5qEwlu6hADuTMX+2OA4ERex/Rvs1Nou8JhKggCTVID1s11ayiptKPTsTgYh8WAGCT86PH4RMGAAw= 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=OYKGo33d; arc=none smtp.client-ip=209.85.167.50 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="OYKGo33d" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-59b7be7496dso3001602e87.0 for ; Sat, 10 Jan 2026 07:09:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057768; x=1768662568; 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=c7uhurcFR9DbDTq+yEkMv+ps4y/ZlCrnBHcpx9/LZbw=; b=OYKGo33dtgLdkgKac80pkbkYmnbrFzqEO1eS/KWpZ4yFjK32T2d2xTreoU50aGtuzW WU+wcNxprqAvr15C2z04ol6rrhdEVOwOCWUwQSmud/iG4OQ9lSPZKgvGA6ngiprcp9Xz 8l5B5loCR9LAykT2P06D50TacVt79ajwTvZGjVXi+PmzEj8Cop77Oz5zSvh1C44IJuWg QNWbOB334llV5Qxc0ir2AeDRZcV6t/gap1mjkbTJn1VNDGOpBLq49kgf3NoPEi6WCcXM OObSJNYt83hW4JShSY13ywOzNotM34DF5/dVGS6jRYxpCxY++CkMys3moz9fr+R9HikS +71Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057768; x=1768662568; 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=c7uhurcFR9DbDTq+yEkMv+ps4y/ZlCrnBHcpx9/LZbw=; b=TXBiz8MlQggYv3aTyK3ZqCnnII5AzIp6GtF3ckH7vJB2BwkFd53QUbZ+B27lc8sYMs 3UJzlbtjrTH8L9Yqm1QZ9DCRHtZOCprj/wFZKAoAKqsUWkdujHf7W/Lz8cXQ6TWdYmke w6t0SkH2Aa+3lAf9R0PY6RHSDPtw8DVY9aCmkdWKfZEYmguTpHnKaABiDBQnfcuctP6M DlRYQg8GXtguiPD+9+TqgTIrLt/lTby+J9wKyt7mRTc1CQO4Zm0ZcnfUW37+PdVSKr5z Hw9BGTu4pxIQCu8hQoH0RP2l6QXncMO6GYpwdn+a5JD3QIvbyNT89UBws6ORhA9vv6Mt zRuQ== X-Forwarded-Encrypted: i=1; AJvYcCV8ug1xctFQcWlEb/Mqgz3KtMFxHjw3R60jUTTcu0Hiun0Kdv/XYyNLkOYLzr9PHgmrsVh6Xs09DWk8lHY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz51LGO8oPX8P9n/0R5TwwiPhoq+vhkBE8ddEDB81UvyPE635XW eOie+5Rt47s+uDxq2MxzE5WYBaxa41//RtruZ5H+DZwizJH288yWrT83 X-Gm-Gg: AY/fxX5PesE0xVXALyhpnnq2koGN0Y0FhyzXZZJbMPFg6IIOa26TjK18z0sl0Ig2i+4 au3W7DCGXabjZgBvoYS7naaKA48U7cIy+XDS8+R9AmJCkClmaN5ajS/8CTRDlasqLUhuim2QUDt ++7RKtNI2bMMeoCdjZsFT4/ldp2vrRw7Mf6Tw0H80qrKIzcSfG2RPX3bLWk5bHQ1b1hyfhSssfp DRySeVfpJkMHK+0oYIU+Ofn7P3gLvpWWiOfJpg47KWWaSWc/kMJKnL7tfTBNE+JEz2E0akINViX 052ydtz920V4BjXTHk455ElfNUOu4/A/ETml9tFyPoB1LgEokCyyiXN33usX4MiFL5zUYUNlQRW jJiaOZkGvPijE5Mq1FxXvXgf9CvyOnk3+uOjf89QSZGf6uQrLKSNvTmmzyR2j3p/jWQKAgvyqBu aBoo6hGfFCRXAJTyNP+w7N9oqVUhUxcyw0NeYsxo7FiJJREeZxOsw/8HGl2EIRORN97NZs/XeG X-Google-Smtp-Source: AGHT+IEb5d+vaUkZpyBGq+p43WuUE9Ufr+umE708zZAN3Ro/I3sh2nhVyXVGVrxWTqDPfClDb90idA== X-Received: by 2002:ac2:443b:0:b0:59b:70e7:4128 with SMTP id 2adb3069b0e04-59b70e74285mr2359072e87.53.1768057767898; Sat, 10 Jan 2026 07:09:27 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:26 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:06 +0200 Subject: [PATCH RFC v3 08/15] rust: firmware: use THIS_MODULE over LocalModule for name 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: <20260110-this_module_fix-v3-8-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=820; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=W71manYc49CiWAv2i0/k3IAXEeJXVcWy8Fdli+uPecw=; b=TI2FZYAl41BCzRj1MSNDkzQDfQwog9xX66xfNZZ1pkWkh8jNuIQdCerLykM46eYcWqAczB9aJ vKnPExldgPFCeNcqUBG3nc2rFIsDDwEfn0QDI1LdCeaw7ubXjJM3bIL X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= THIS_MODULE now contains also name so there is no need to use LocalModule anymore. LocalModule will be removed in future. Signed-off-by: Kari Argillander --- rust/kernel/firmware.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs index 71168d8004e2..2702f01c0403 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"] --=20 2.43.0 From nobody Sun Feb 8 04:34:40 2026 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 8FC77346FA9 for ; Sat, 10 Jan 2026 15:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057774; cv=none; b=doLqag2Qv1g91o7zfNRaCtKiZr5itO9sMAiIujNAqFgll1iQ4g5s1G9qdAjUI6Cfhg12TqXn/drxcZo5WYwK2gg2Wba3PbNTIOoMaoT8Gv7yq2yqS7r6ienE4T5f/xOEDPV7xIjuq5dQwpurykZdQAsM177S1m6bzGHsDamt0FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057774; c=relaxed/simple; bh=16z+/p9/lej3nOQDzP3jcxjHTQfVy2r7xALqKBRkYmc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fvO5vSEUy0nNTLG/2rmYNjAj+rocsltUGhmE8a5IcnuEp/BzCGbvFqHd/3uruvkaxWIQZ1qhS8v2VQeNlLcebQ9ooLC5MQzQG4G/jIOFC+D+G1p3m0ZCR//Vp73iUwg2Q7fQwUznoKDllJhNA0Gc4abE6nvWe0xmX95lstuLRe0= 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=VDYtQ7bY; arc=none smtp.client-ip=209.85.167.54 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="VDYtQ7bY" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-59b73193dc8so4002662e87.0 for ; Sat, 10 Jan 2026 07:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057771; x=1768662571; 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=JlDCOqcpxSYZNQqRknLGjEy40YAMcG3nssNg0J3FjxY=; b=VDYtQ7bYrzbIpfZr3TKveqV+L0Vt92aohVqmBQpLJOuvNZrmYy9iRhj+hntu6mX6F/ I3eullZ1g3ehZQoJ5MpgNASAedkVjsK7IgSlbadGEj1yGbgB/PyKaamTQE9vURL6CroJ RaWFnna4K1TkF1HG37OwWC/BLmSH8hqwSPnsu43LGI3+wsPK9JrX7IdPWYmHOD7BFLnr Ll2bkZ0TKiXrfdjti0gNp2lammdoNfSzLkTyvdOWN7HBB+7FClyNNT0SSs7QrG0V11mS 87eZw1u8tEadA7h7uoJO2yEOXKwZz/yFUFku8vXOxhE9w48U0v2xF3SyngfrIN5v+1WA Rdqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057771; x=1768662571; 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=JlDCOqcpxSYZNQqRknLGjEy40YAMcG3nssNg0J3FjxY=; b=o2H7/Hq6qbBQoJ78A2y120jvp3f3QgD8QjQNVktczIfdNFZyhgp1eB+y0qFQQJuYP/ i2mC43O+3u5ZS7Wgkv8sLhlU8BHoVgAyC+SUsSaeIPY71jcVfi7P9IBYXK9dWtxZJFj1 9b7uIzNB5xOLHE3AUc/ndc2xna1kXwYBi1NQO4TAUw5qRkguxLMc3QmcURHKeTp1xAO3 7T5bDuxq2CHZnPbI/rQxn4WeltkK4nwLZPUqNMp00JZlM1cAPlM5iLTHP8Pk8rkokewq 2vwCrki49x7mT2TrMUNo+2CzRizwSuDUIz6t6DT1OJ1hioXMoRqtbAszPtWZQKZoigTK Dbug== X-Forwarded-Encrypted: i=1; AJvYcCXEA8js86HJYbS5IhurfgFDjIm5mjwL716k4gXGtsMW712oa5SOkJ4q/IpmB0b3de7QNx0Cm9qBEIpAqh0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc2gxdLWuSWHzz39e8xNIxdyRHKML01Lx8IVu5Ef/1kPhvHQep rhi6ZiHQNB54VsPNJm4FCZUFvIz05fKedQ70JfERk0Ho9Wq1ty7k9FUM X-Gm-Gg: AY/fxX6irdrP3m2lbvy45v/JxHA7gF48h4DldA3Er3C+VF33XmBq/ckbV41M5DUPYlF aOiSAbO5tAEmLdhBN5ihrtQk/jTRk9J1HBD3/5rfB5yDQTH+zFRxkswHJg6FmGJxjhc8vtDWyQC Zakmlp6x2BgztOiUp6d3I/COHMtktIePUy5hhNZoHAJcdJzirc0riGjhIVcXDpX3tS7JGWUfpMy pJtEkjRZgCbZobWyQhZwKbCJorjtIzmS01V7wUqSb3hJhHOg2S9Zh1TzIUj6xHP6qwb8XeP5sBy ASObkBxkXwSyTxHOE87RHVsvroHXY0fOWlNjEhwQlGQ+c/Q/xS2hpCNasnIXQQZK6DmGdX9MFVx NMpU2GQyMF0j97q7izYorpwdIY1zY+dDat58nM91jSe3+yM1Zf8vi54sWgsfJCfUzZcyttgXQTR dZ3vSjphh11tlv256pChNFW/N3FPsP4qqgbSe+JNF+zLhcvOIPjTCABoKNWlAABNIaHqwYlrpe+ IS7sbrFpNc= X-Google-Smtp-Source: AGHT+IGPacMYwDU7ZheyDzxzZJyrY1/QIDRayqvxVVTESHnbCTj5MKU+UYyTZd3q0INr8ESQRaxDqw== X-Received: by 2002:ac2:47f2:0:b0:59b:715b:4fd8 with SMTP id 2adb3069b0e04-59b715b529amr2926411e87.13.1768057770686; Sat, 10 Jan 2026 07:09:30 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:29 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:07 +0200 Subject: [PATCH RFC v3 09/15] gpu: nova-core: use THIS_MODULE over LocalModule for name 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: <20260110-this_module_fix-v3-9-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=801; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=16z+/p9/lej3nOQDzP3jcxjHTQfVy2r7xALqKBRkYmc=; b=2ckocfo0Z4z6nSjUTwSYROhT79u6Ea3s3woTynS15mrnKNn85RGMQtrTTrNA6LV8iIWiR/ceh WrveCD3jfC5Creqw6HHlcTQlrQlgwbm8kUGr3jdvp5DOGyCvHfXtMrg X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= THIS_MODULE now contains also name so there is no need to use LocalModule anymore. LocalModule will be removed in future. Signed-off-by: Kari Argillander --- drivers/gpu/nova-core/nova_core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nov= a_core.rs index c1121e7c64c5..c8d6f9e3be1c 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -18,7 +18,7 @@ mod sbuffer; 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, --=20 2.43.0 From nobody Sun Feb 8 04:34:40 2026 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 30435349AF6 for ; Sat, 10 Jan 2026 15:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057780; cv=none; b=GshA9XiSKna38s+EVYd3yZRadfbj3//uayr9GgVNM7Z93eqmjo3nwij/50G04160sop3+LM0uROoYeOBBz3LfvKN7IhzMioeG7FeEvps7weEA1+sZ3bBXVdPxr+/FTcrzF9e7UD/IoreheCy8CoiGgcFf7GYQ2b0GiOkdRtXhGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057780; c=relaxed/simple; bh=tU2A7XGU5tMg3thsacRJ8bxh8G/tJCbsQXcLwZ+tI3w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q1W+398bflc2oAmQSVokKTZ8Jy561DB590W47AGv5Susv2NhSp1YaHQ3DvKouc6V/UzSVaSWOrkIFynonm+IQJy//krB9oHVoIm4sAz2zFfiVUj8Ebe1eCxr/e+4fECZFhZO+jJAgT//sHsd4K385FnigPdKaHaOt1XHXwLt2AI= 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=enWCGSU8; arc=none smtp.client-ip=209.85.167.49 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="enWCGSU8" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-59b79f700a1so2331197e87.0 for ; Sat, 10 Jan 2026 07:09:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057773; x=1768662573; 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=07W52aMxFLKScpD3hgugCwUW4vLdsok57EM7soocvuA=; b=enWCGSU88UwstH5doadgYHTOI2MIMtPqqNVzvyMlAFmZmXbTHJM0r0go1coFkEo2o7 TZC+hfcX1bsvWkuGUJ4S+qFFe4q8NBcRFJZ1TQIY9pKTwZTMMD0X6SYJchhm16MPBXtY X80WYB83frWircTnlHSxtCwkGOZG39uaRnUUn704N1Xw+0GSC88bw0q8Fplqa16VGdBB XHcFPS32QDm/B3r5AjLmT0QFUQeoJX3c6Mo7QRzNQNMLHdYyCi7WG+nXl0AtPiFCGwJ/ g2/m0X9IjHHsJJlAninGMI+IqP2WfdrDKVPdgjqk9+WDyLOQ6ldbTgOMCHe5DsWpYTub f9Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057773; x=1768662573; 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=07W52aMxFLKScpD3hgugCwUW4vLdsok57EM7soocvuA=; b=JqnrlWdcHuJR+8+8aq9ErujTBVWDddbvzu11v6zq7UKtzNsI6l0pFMKFUh10pdJyUu 9PmAKzxs1tjfg6BFR5m5QAnFhhnrFwiZffEzb1O66NmKdraC44G7mKNBgh7ILKXS2S4Y 5fYcAET0nJ6Nu4jfHNMHX+ykOZarj3po7Vde9TR5YiRP/Jr/vAGONm9wNlARKXz3cILq ym27LplrdmEJBeb2py6hKDlrZCtF5P9ANJQeG6wjwP6QI2oiMQKIA089GMtnpoTJyxXx f9SfpbeBsK6fKeTBXyIRz2r3uH3qfGOlgFf4HXW6PRD3tqghryGdCJlIgj+E/01uBex2 2YgQ== X-Forwarded-Encrypted: i=1; AJvYcCUSBBWT7C0SmSaVDnonzzPhq/HU6Tbvkc5XhU1mrQyXOQ79MnnyB/KRfExjD3ESLi6HgJ2+tre4oLOH7DM=@vger.kernel.org X-Gm-Message-State: AOJu0YxHxfG3DYESW8yIZTg3zXjCeYmVhR3oN8AmejKObeSPk8P8Pkaw r/H9GmEgGFzSq3B7oR+FC58eXVYZJl8JBi6GngfzJ5hCFoAr+M4X2+ge X-Gm-Gg: AY/fxX7akdMXmG+zsJtuRbP+IUv5W1qS0njiEB2vMsrrMZyf8wAUoRWVLp3lfqBL3g0 MY8p/adH8ITZIIv82JbRMU7ttJtU1M2N/nWhrlDwWxzvpMHz9tfDtNHAdIQOF2P7pocgbmXKhij cLjtTRt+ZavT/KHrt1fRvN9mIqpbOy86ICoMmY9lpYKt11svkayQuaj56JnbQm48y0y7bD0/FlV SqvSLwbaiTPI4EY6gI/tcgVRE4WYFW0IRJSXhYeT4gDaiUA8qzjsA7Mz0Yfs7P35cnOelKoJwRA aSl2pPPlAMMXNaIspuXLBNaOHlZcuwW6x+rUteIniMF0zo6sbDfsBJG3Y26fVBZPueDGfhtQ7jV CaO3VsqmrYGylM2ofv4X6V7vvF9cgMU6AHFaOeg/hzEeAcf8BzXsBUPF0UzNJ7kGVTlS5pteBPD VghGM9t38Of/NkG9tdY6DEPyIrfu+XYeGXO4z8p3XYQdHkATnAFqg9SF6kgPAFgEKhY33y59lxS 4UU0lC99wE= X-Google-Smtp-Source: AGHT+IHZXip1FuDd41exkQ9+vHKMbxvmuRagUKcC4E8lHg1S1o+cppz7fFdiHyoeUx8UQxAGL2bEjg== X-Received: by 2002:ac2:5dca:0:b0:59b:7346:261a with SMTP id 2adb3069b0e04-59b7346289emr2376804e87.13.1768057773222; Sat, 10 Jan 2026 07:09:33 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:32 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:08 +0200 Subject: [PATCH RFC v3 10/15] samples: rust: auxiliary: use THIS_MODULE over LocalModule for name 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: <20260110-this_module_fix-v3-10-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=801; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=tU2A7XGU5tMg3thsacRJ8bxh8G/tJCbsQXcLwZ+tI3w=; b=QSsWUb0DnKp1VKyD+MbfnB/CFvwKQF3LVY1R8TG1xLAWCKovA2tX7wOgbxzvdwKQgbDYH9Ocg vh9HCi7TippDwUAEn8szZiHPY1G6F0uHGXS6Ehm5ZbX0qYfUyfMqauv X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= THIS_MODULE now contains also name so there is no need to use LocalModule anymore. LocalModule will be removed in future. Signed-off-by: Kari Argillander --- samples/rust/rust_driver_auxiliary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index 1e4fb23cfcb0..84d67c5c87c8 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 04:34:40 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 5C42F34845F for ; Sat, 10 Jan 2026 15:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057785; cv=none; b=jCRx9FvUNGnd2H51T7POwZBAcb6BiDbLhLb/T38Ck0zuV9d2oywBdHtmpWo+cqlT9BW7YNCgTB/5nn9Wm9B087PW4+5zPR75VHlMCfNczYd65qyDcvqqGhBWwaLJGDuuSh2Msh/reNgJ3931Z3vByxcpF6EQMI1gd0IgqVfucGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057785; c=relaxed/simple; bh=vEu6o7mqu+RFkiHGwwnRAU9DOgppBhVS6nTew5ATpME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a8LUpyZMlGJE6yF7QTSh2pVSRDazRO+RxuqbCERYSPDzQhHQ9w44hwjBkz2czaIHBLaf1+cRYHiCxiUkNqYudWTRCjgqxuPl4q6dnnVRLOy1MltPE1cv3LNREiMpl27PG6Y1RIyfIdDWc2Ctsvh/PZJCabfBpYUbQ/oPnZH2dl4= 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=cz3r1Urq; arc=none smtp.client-ip=209.85.167.51 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="cz3r1Urq" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-59b76c092acso2538261e87.2 for ; Sat, 10 Jan 2026 07:09:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057778; x=1768662578; 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=DzuWLdvnTvIXevxxHHGLaFpbvsHbVmOruxmKPq87W9o=; b=cz3r1UrqUJIOHGLYHbp1ATioMrsLVFjx6TPwHdxvlYpsDgbeLdNFdQhPhwzHwVFfKP Dimm9aQLhl2ECI+F5QvqhwlQt9vjkvDNXDWUTgDGlYmh2mUcjQ+aq37RoLY7nf87ry1K +j8fj04U7ee5DWbF8awr6BdvEgdmbqstUM/UQnvZdJJvW3p+KJwEaEEYzW6luax7INJG C1ovv0Gbse6bv8BYyYdCsERsNq5voVnElF6M0MQVrqmAyEDpyANwhIqeEiuNyzS/iorY F1R8TRBRktMeGbtjtTqcU05qt+WyXyxjaY3UWNMIqrXz6G/L/uG8xbMQlI7SEvkV1wbN ocFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057778; x=1768662578; 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=DzuWLdvnTvIXevxxHHGLaFpbvsHbVmOruxmKPq87W9o=; b=aAmKP/7EO0g1fZ3SW2LvsukWI5RzgHsNHtmUl2EqRbptQ95aBEeLLOI9qmFt3sprRQ fuoP6dBcxYvEReJH5+nxjngOTjJjREN1dKf3teVIOZL+zXyIzYBCgwLmroKHsojrgpmP a5Pz7DAC7wMkDVGXBRKiVOIH4LlgxjXhJEABHFECKv4GWScUMcLaHHmjQrb26ENJRt3o 6VKXLxkQHJpffT+xQQCW+1LAn0Yu+NQBffsG87rAdGEVNi6Zxuwqr/FvnOmmVlMg84RB hWXWiwR2ryy/xnoKpvN0nhW4BqI/vluvfz0zjAj6pAO7/Byqrh4+KmNzIm3SRAK6JhX9 sbog== X-Forwarded-Encrypted: i=1; AJvYcCVGJKmQhpZfHJMTfidEns1hLn//G1o9W4kv/t5x48cxkCs7QZAuhfEqaqKFDqcpPDlv53ePJFOACepCSSo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx16tZds1rRuqEW3VTCRVbAsifHftxFjR3QwvsGuxcEpJ7w4gs2 BSv0D5WQB+lG/3uu/5zE8POG/FBNoB4HvJzDDUoSIbrE6y/AxMNWlEIk X-Gm-Gg: AY/fxX7KmPGjE2IHg5pUe2ELR8NC5rTlljqtklL0wnOVGZiXWJrOVjhgjsTytr10bhM AcfXMWx8w194sBvfFIbdg9urfOBZc6unP0O+xyo1L8A412tSMHKiEcciSedTAWnXBtCCp5Zl0h4 YnczcoaEsOQGpuX+T97KNRbVLlgn4dLA6Y3AAr+DdPPVgiI3iUadONcgRHbvLnG4wSwXi0cpwIQ XqIK9N6KeRAlt9VVnSQ1P/Qld84KWsOq8FQfHPgyQ+t+tJuwdBsbKm7Fg+tfK2YOHTK7TEWAuQg 5rzolozJjAccowJ0OXq3ZDsFu22TLoeSU6iv3wzXMYl8IodDzRtguVoYrFkcICP4b1QCuWRjZ2G fzkothYjKzc5BlHslbWclxnqT8JaHMTrR8UvI/iP9mMw+3HbpcgYsRNYcsSSGks9tm07lkhVzaO 4t2QXDBDP27EK/g93/VcRVCinhbIvK0SfvFGGrIv5+MuiL1YMFZnZCGzxJxjWUEzdEpuYmjBzR X-Google-Smtp-Source: AGHT+IFLDMt7DbdqdOgRShF10afiSlkPty68R8xdwB3Kov08d6DRT+5yzAdy80yfbTltM5orzzqaYg== X-Received: by 2002:ac2:43c6:0:b0:59b:717b:c152 with SMTP id 2adb3069b0e04-59b717bc2dcmr2791726e87.45.1768057777417; Sat, 10 Jan 2026 07:09:37 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:35 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:09 +0200 Subject: [PATCH RFC v3 11/15] 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: <20260110-this_module_fix-v3-11-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=12781; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=vEu6o7mqu+RFkiHGwwnRAU9DOgppBhVS6nTew5ATpME=; b=NnABEyE/Pk4bWy5hCOXEnQHtaEsQAntdgS2iZw1heZr/zKZ6hQcUo0u71m4Mp+yEw2OywjHwp CaCAIC96IlRCBULnLQIFLppfR103aY/W+5Qeek2yDE7NO8zrxDif7Pb 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 84d67c5c87c8..8536a8eba45d 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 04:34:40 2026 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 39F37349B10 for ; Sat, 10 Jan 2026 15:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057784; cv=none; b=DPpZ1jf74m+4MrPgIazowU069uStFef7u0ZnlktDMclFa6xHXgC6iAdfTLocarGtTNNjOSOebQZngP9EoRw2Qj/6DH6fVPNN7qfkcQElQurX3EGnEe8d/hnhy75yFQHNarEqPzRrXJ1SZP+guxN18pEd4kaLiQiX9xjzA1N4NBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057784; c=relaxed/simple; bh=RPwYcsbO6FvGujOyqzQn4sJnbXGyGs4NpzWn8HY+yNY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pnlM8BkcyzU+0Sf+SsOJmBDy3CbFqr2x9VJ2wLljYv6lNYVFfISS1CPlC93prAGKJneedwKisRn+nqb1KigbY1anOVs5UdkUZFq/n3Zfs+zL97MlcTvlmDllTDLO/W/BYfsr7CbuQjuxamtOBvAMzLoe2+XYDuugAjbzrneo/dk= 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=iMjyDMUP; arc=none smtp.client-ip=209.85.167.42 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="iMjyDMUP" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-59b834e3d64so1533282e87.2 for ; Sat, 10 Jan 2026 07:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057780; x=1768662580; 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=TJZFqk7vh2YSe9SFh94/y7TJPpOJJYaVuu6o0W+r2E0=; b=iMjyDMUPSEY8Lmq3R0FAa3quZjmWCFnzj0ccxNiTn8rYW7WDyI0Zy1DMSxJqXW3bzx +P7cmQGSiY6AJ09TTWqJrN9NN5gsp+USi011s0g/poVghoANObGOmlrdwhioBkvc4eKe wgBk1NtkzuYjILvPgOuWXEKNMTsfhSd/MHRGwf3+zmmYDnDFJXiT6x+IHJAEYLdg0edC kj/yXGQc1l6pImih45hk/lGhJHapUXVSd7LaPVpYX0U8daR2qqpKaQpTnzD7ViL50OxR G71kYh5mUcCq9pIuyl3n+6ag8HtO7stfVCaR9nGRACS41OnKZamqmy27MoJ6+hWmtXvm pCSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057780; x=1768662580; 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=TJZFqk7vh2YSe9SFh94/y7TJPpOJJYaVuu6o0W+r2E0=; b=jJfOBC9YQNTueqEjj3ejRRwMx3n1GrZwSsBq09NeSCPXdiaoowyDORb+qjMoTL8mNd RyR4nn4Y6F4jdOwwZvJTd+cqbShuF3FAwhc9M6yQ9GqZ8+GSwgqWI64BRYgO/BTAIshK rRE6XIqQ1t1HuLmnlFN14xjKloSQoXEapffg1Oq/9OEjUd/+wMMsPcqqaM6UDQv2YJd7 wvOWbe3eOnpOZM5OZWUL8XAf0+VkUBI4igPtA4hTLn6awzj+lJR370VAqFLSpyxUCM4D 2CV1tcRwFtM+R/JwqTVQHUJZ4sfEkm0EcRcDZ2WxxZdi6AjnGeTXz2NqkEj+uMoGNng2 Y47A== X-Forwarded-Encrypted: i=1; AJvYcCXyOD5hFSlohk7zR84dXj9q4RRUl3pGxYBnL/CaiCwr/YeAFqzdFwbWBqmIRcZ1riR1WcEdL1RLvQUDIwk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxk1gyhc5Pg9odg0GysRwx18+SUjwKzx1TxF7xwZ4qZSDaclStt wM/QLXAWTMevamYzoNwsWae+DiLS+3S92IFMVitgKX0lC/48jFN0jCx6 X-Gm-Gg: AY/fxX67QyOAtb6Uet2+52BpSt7gZux4Lo55+PUVSFUP5tOrqEfVckfZmJD0xQ68u1B aYq13a7F+iHVij8DGmp9ytnlfYzeYm+K///itiQjrlgusKVhbvM81RnhyabzhTGsr5BSY5MUnMO nQOMRiWt8g0A/JuWkbIeva++bQYypDF+IlQSBzJ5rcPehml52L+bJ8SFP4RFMVB85aokKsI0DRM vWrdxabsOCJzOxceFTovzrMIoFZ6SYRtlu2kLwmbU/hXYZSoRhYcwhzFY6LjWNYf+4fyWtSAKxj SgnuoIMxvIIj8sKaqcJCWJnKXNom3BRYmoxWGCh3qTYm6qiuCk0eVvaeeBr1w1s8TkoLtwumsYw gipKN3/rtrVnQf8X0Nj7wgo1sEdIhS19B6bG4RBjZNDktzDe1ev7/x9SnCK8Iz3Zdj1IZEsE3+Y lF8qjN28cSo5o18Q1mzo/sKIob2DWtmnmiVSFp+t0wc2uNe0svKCpIKYJC52bMZVhs1lBgJxbn X-Google-Smtp-Source: AGHT+IGrXaDwrVcPD7nQyKOzD7OZoH3I9M3zAJdjB+Pw3+clRX2CyUU8JcGUGqOgg81EpbJqhGCXjg== X-Received: by 2002:a05:6512:3b92:b0:598:efe3:42d9 with SMTP id 2adb3069b0e04-59b6ef23c6cmr4461411e87.5.1768057779866; Sat, 10 Jan 2026 07:09:39 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:39 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:10 +0200 Subject: [PATCH RFC v3 12/15] 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: <20260110-this_module_fix-v3-12-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=3371; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=RPwYcsbO6FvGujOyqzQn4sJnbXGyGs4NpzWn8HY+yNY=; b=eOz1FkieCkXNv0LbzaUrw6lJv8jXnr2v2Ev87tDvYXN97UoTGaEAUQ7gOBLgSrC/C9PzjTfOI uNR/UatFeLaAqdfhARe65M84rWjJrWC14lZyJdS7QY5ojhJUns9YC/1 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 3ca99db5cccf..ef9c4be4f1ad 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 }) @@ -889,12 +899,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 04:34:40 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 367AA34A3D2 for ; Sat, 10 Jan 2026 15:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057795; cv=none; b=MSJZubuLL/i07U+I4I2wXWqPmmvVPaKyGKA7PZf91bK/OnDBde72qX0pFv+UkXWN4aMZVQxOpIdIi7XO3XKkrzaI7oBll0rIW74s9+knuWqFLXsR1fhdwzmM0hI5rwfPk09sEUCpL5ZuSPHyQkDh6HLxQ/SIOdaoISWBtyuT6kA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057795; c=relaxed/simple; bh=UABoSaxqonAoKMSM1A63J++kkIOF/YOhd1jPbvYZYCc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i0aivJE7Twct0VyJcuwvBpBUGAyXSm/6UJ3g6hhZYRFTUrjAw3QON4Vwf22nSyt+2ZOJiHuPHppJ6DVUFQvzpLM/St0m0MfelZkqzandhYrC45DD8TMdtxxEX0F3QV9umGBtvBt8LrE0/nJitYorFlaKQzYjGx96GpX8DvpMUvo= 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=ZWQ7eOxf; arc=none smtp.client-ip=209.85.167.44 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="ZWQ7eOxf" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-59b6f04cae6so3703830e87.2 for ; Sat, 10 Jan 2026 07:09:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057782; x=1768662582; 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=07QAswGWdpTr3hHbMzjaD5v4uBQulILTtvUpre8K2Ow=; b=ZWQ7eOxf97xHLhIPvfuTd49AeMmU/28Rn9hpFcVKv4/6JCVpEEmjkyE++hkGYeAyy9 u/XabzGwc0iWeDWmIjbwzuihKZ6BI/v7x+v3gt0fewJ05etbStoq1FtDOOHC+hpV3dsj qDpjWhxezIpKrwTU09yeQvsrKOavty4/k0qX9yU2Hg+kH9f2BzP+AA9eeR2+dxNhx3ce r2fUeEaeUS6HktASLy5+8lDi14tSLTI81jKlStsHTnc7KXHd5HFnm0d5zrHLvlAb3RW7 eu7BmtBb1qkc+Uyr97VyiiCrPWHyLtZQyPWjh6IdO8WBTirnwsmexiwENvOB0qLxKem9 aFbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057782; x=1768662582; 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=07QAswGWdpTr3hHbMzjaD5v4uBQulILTtvUpre8K2Ow=; b=JsWI6kggiLlyDNgRABW40OLrQMtmIYag3uOY20X5Ahl8JhyWfguVStVkToVXud59tL 9Oq+AFfg9IeMC7AYlEjEvC6dqSKIBKa8m3VhAGI7OYXWAlanQowLp6XXgtv5Of4HT27T NeTwaFiUkUZNUTlY/09iThIITzcUtkOOlsTYP0Zz5V78qjst7ptiEDKyhsoX0Kx5nWi2 jgGlNi765VQFok8KymFvbBKNLiiREgqCQpEWQ+gNh1SZexx6ARIC424Xfm1ARbBDntPv 9kXUtuut61lA2ujLNVOyHoa4OjZBIHJFw6luGcbdr8Y1oBltu2fuA1yw+WzvgFc94nmV uH4g== X-Forwarded-Encrypted: i=1; AJvYcCUk250jeOXdT00OnEhWynqkc6g6LxhobZCbvgsxUkEs5lXU1RZDbPlq25YNXTdWfBmZrS/Vn3qlA32aJfo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxq7jLGBqJR1I9TeA9KwmPZcp8ydWZ2flNRrUullqBMJQ9FDujn xf10gT/zCatMWT71lsDQV3JoP2Tgko7MMZhaMHvok+SEhYfzS2xHil7d X-Gm-Gg: AY/fxX4qAE/KUqTsqWTWTZqzfOaKSDdH0Hank+UyU/jeG9AGG9HTxs9BnicrdULd4/a L9PHz9q2XSEAyPipUwqM3/d78kfxzm4l77Jv92TezjyZx+p0nA6JgKwcBmwk3JnwWgZsAfnheRK B/4qSB/rksUL8T3cRjhRLy1L+AbaJyNedmIWIC2Ty7jzkL+un0YxPOzKytRYTc+L00Aty1S1+7R RpgouBZTFuhTYPKNXTsKwwXXiATIZgpPn5oJxV0qzLUZLJGszXBN5ttp//5z57HDqeDJNTJ86az /0SrgQhUtphaojJsagWnlCTQudgVaMX+DaiqVyAr/b6WE6rHHR1n0YfGvGENhOaXh7QgD++wGBv CHekg8PHyIAF3kC4dtg1nXvFHHAb9RCiwjDhANWW3OZbi8KxNPoT/VarE1Uv1i1E2xkN72I0XvO EriPzPZroyOZi5aPh75L5fhKbsS13UXkgDIxEnW4OCMus7ov54+KMqSX2hY858ms8qCR0NcD7Q X-Google-Smtp-Source: AGHT+IF14K6flXm/FKp0Ka/5zTocdLoJ5AAn0WrROFOXnN5R/o8ywfpYrSkhDWVGQCOP2bqs184yBA== X-Received: by 2002:ac2:4894:0:b0:59b:6ff4:195a with SMTP id 2adb3069b0e04-59b6ff41a97mr2884280e87.43.1768057782129; Sat, 10 Jan 2026 07:09:42 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:41 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:11 +0200 Subject: [PATCH RFC v3 13/15] 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: <20260110-this_module_fix-v3-13-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=13585; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=UABoSaxqonAoKMSM1A63J++kkIOF/YOhd1jPbvYZYCc=; b=H8JijuxSUV9Ec+/8vdofzKs+jAGXj7xuXT0odKnocxFhcVjniBAuXPiabaJPIL97UNO5cZ25B VZPXUEk5+R3B4f+LjgQQo5XrzcH1KpLUpfXBWU/lIKy6c0QeXpEk2Mr 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 2702f01c0403..42bae71f6af1 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 4b899f75e56d..d6111a44fb3a 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 ef9c4be4f1ad..4c4dc376bd5a 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -899,7 +899,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 8536a8eba45d..528866b953aa 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 04:34:40 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 B7143347BBE for ; Sat, 10 Jan 2026 15:09:46 +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=1768057796; cv=none; b=MIa/Fhhpw8ZbhxguBxBiUooDSfPe4f8WyUvBwSF7wb/azzftKMonXFZWdOubeLs0WyxDuQgOZGImS6/kICKiOfk+3I6J63qiGPbiUyF7zbpQEBpfSX3TDwKSn4zIIQ9w7EuBhIQy5ns44/ApUKaeuGJGaDWazAKzmgJIPEmr0EM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057796; c=relaxed/simple; bh=pfH3AGgm+K0TiaxJVDEaqs35RUJB1GsVoRO74Bd7vBY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NbuB+nhNFVvx/uKx/oPg1ZQgeffMNKwLQNhyLa8VpcRupWqGt+0eqKxqHnTdvSsRUwYjGZBnOA7WlIuS0RHMbkSb9/0aampTbz/JMYAaNKTQn2ZHfkHt/uR9jBXrUwGuud8yKYKWuQ3ar/y+0XVgAjgfSM226j66fC1Uc/ir6AM= 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=DUzJ5XyC; 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="DUzJ5XyC" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-59b679cff1fso3996147e87.0 for ; Sat, 10 Jan 2026 07:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057784; x=1768662584; 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=QEO230ig7NJAkoe13wY9aF3OcdLkvsjJUe6hRkAMlIw=; b=DUzJ5XyCyDSe5px7b8/qIA1OjfRFUhfxcDpQ7/Yo/nvf9q45qfD3FAEK/vesX/vT3S gEUYThv/t+baQc2CURHqVI4jTSzZYZDj1Hwu2bNiyFXtOySEhhWsf8abOjQsR+LeDQwO dZVXIg4OcMyOGBJ4i/QZleBwBBtZ2DeObV9ypRfLWWEiZ4l3OMr1Lk+X5QJphQxvAaW8 ZwERNJY3S8Dk1nDhSE7o5wlSGZeW5qjOZGleA7i2pfP4lwHBNnzJUPYMX7o2l/e5xg5R wbduCaps4UqRzI/l9b18+4tum/DsqiyBJpBWrt8onTj+J7fBVDibTfF/C2V0cTdRAamM 2k/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057784; x=1768662584; 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=QEO230ig7NJAkoe13wY9aF3OcdLkvsjJUe6hRkAMlIw=; b=oG/1deVC1x1qlx5IiUcV6o7dNIfg6QNNOG0CPaMSHVJrYDSmuiR5ixVSi334yPIAti rGelTPJZZ0e3BWHDj+/OzJ6vhVsDJdFL/XBoJaAu8DEBuOeDNbEkVEwqe2RFXiNtAYh0 QDCIxQnuTzNe9/s6KPrcoCn77sTF/5cvoMJZaidhZqyOrZ5LePGkfmL2pAOa+Nga+QrW pScYTqV2T6AZH/wzZA4FjBSX+93Bv8227iDd7+oCnFLLqWwefvTLwxIpIn7e3AObppn4 PHT6Z7TUf5U9JWP6su9Id560l62dzjhRexqpjzGFpa7RiTmpS1JRLWstHhgPQj41Ytjv cEwA== X-Forwarded-Encrypted: i=1; AJvYcCUHKt8TjoWO1OecMpDqoHi4LqPK0Y1cv5xrXNcw/ctrTxwan5RL9eC4zJ3I+fqNGCP+f3XXsgHrAhLOSGo=@vger.kernel.org X-Gm-Message-State: AOJu0YxeobTodCVfmr1veC9uPfJ0/EkRtApSPmuLLEOU7zT1XVeXYY8d +dE+i3xRklqX7eF/CqvgXKAixAteKPDM9bJKnQ+fHCTzIE1ffXuXD7Uq X-Gm-Gg: AY/fxX5pIeIOMYqRJUs1al13e8y1OqSssikeWJ34zsl+GeubRS9oydJeIVOe+xDc9JM o5/0aYVHkU9KMfgWRdso8IeO4TNHrtiLA3i9shs1V7ASt6S+ZJBHxqXdkYbpYeE8BQRDzE1fixi wkAePMkdrVY01C+Wq/mGeFTpKX62Do9SxhdhSlH+B/OTI6rJAltWiNoa4ctvbL/oUpc2ZXpP5KY q4kL5w1/bb/DJ7Tttc9eoHasj7GgdU6euHgd35MJGuNuyPx+Z2QSiQJ23hR5OaLQeYOy+i/uxHq T/GXmfjht3jcqcn0q+Nr1DCB0jJLUuLlKU1nqqsznn8RagYj3d2H7FCu7eQBp4fbUYi78rHSvAD IXYT8Ua42vUJ5fgvoUZjUxXv7tKKs5wXUPcCgtQp93vhEsMIG8awZ2ng2//n06RFEq6hHv9FaLS +mqlP8+xAIEALwb+hrBXx/aJ91bskcYOMEHqG/nKhQb2M93cAd5dObsQwMbG6sHuuwdhOdYZyU X-Google-Smtp-Source: AGHT+IEIQmFQiF0ZLik1zsJlq+OUA/lbf5+EKmbrA0WWELNhEphwh4e3fJyxYtg4u5UlIhAQwIseJg== X-Received: by 2002:a05:6512:1052:b0:59b:7c9f:625e with SMTP id 2adb3069b0e04-59b7c9f62c2mr1936509e87.44.1768057784204; Sat, 10 Jan 2026 07:09:44 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:43 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:12 +0200 Subject: [PATCH RFC v3 14/15] 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: <20260110-this_module_fix-v3-14-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=1735; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=pfH3AGgm+K0TiaxJVDEaqs35RUJB1GsVoRO74Bd7vBY=; b=NyjzfLzXSJdPJdEypMEaLFZ1UzScd7sLn91FWqga5fbZGrFtuuTya8mHIF9TK+GjZjdQY4J9f 0F7dL8GFLgbDaw+9kU8HkJChnr21OqYRxiKEYyWkXpspR6iPeBG1oC5 X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= We have all information available also in THIS_MODULE. All users use that already so there is no users for this anymore so remove it. Signed-off-by: Kari Argillander --- rust/kernel/lib.rs | 6 ------ rust/macros/module.rs | 8 -------- 2 files changed, 14 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index d6111a44fb3a..3acc60a83b09 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 {{ --=20 2.43.0 From nobody Sun Feb 8 04:34:40 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 1871E349B06 for ; Sat, 10 Jan 2026 15:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057795; cv=none; b=lybBZJmmECNaNR69sjnp2uO2m31yqlAIbF/tBxil77VF66e51p1x9KDP0mgxIbOjrRhZ0Mh0lVUJNV26F6q3DkSM+tEtmgcsHnC9cYTC2WptGWQSRK29c9fSMfcYtuX8SuiohH1+4HlTipPu7kFGCjK3Bdz/Ftkeg2wkKZ7lX+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768057795; c=relaxed/simple; bh=evAHr1gD6EfPZW8LvM5pPL6GuIcZSSelhlqgoHK4/G4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pTSnGrR1xRYxLOlRdHwXR/2REE6/Jk1Y8FmtZTJBlW1T7lSpWBLE51ZsCs4NR3rkp7U1Obh0vEvxMpjBE1cQ+snht21ZjzWpvazAIjSYyBN+4kaYROiIZPeeFvqekljnHkSsl7tP2NQXdgu9OAv5xXgLxf80469IZcqQcEEK8oY= 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=jprEPOu0; arc=none smtp.client-ip=209.85.167.46 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="jprEPOu0" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-59b76844f89so2762737e87.1 for ; Sat, 10 Jan 2026 07:09:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768057787; x=1768662587; 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=csZdrKP5V1PNFMXR8xX+/RBApYgeOuQXpn5FzbDjqFQ=; b=jprEPOu0JzVzUqPgkTNFG82LEhmBmd8CMiU24akxRrZ81ucHFywlnF2Hxl3iuD+zs8 ivkU4jY33zar8xxSnocmAIgMNQRMiXOG8xUTVoNOzUIz/5ehNP8Wg2YeGTJ/yJNzXzD2 LWWTGI/TqEDtS1wxmM7z5IG1KvC7Z5FbCM7BKeGlvwoT5l11RSh5utFkRdvEIMlJwlDI jD3nV2IBfdaBJ8IEeTfDsTx5/3cnJsZ/Ftb39BWQuEhdPu1MPXevjtLbOSXy0SfNt8HF JDL6NQNEooW+V4RvzzCFw1S1/zeQFpwB+Cp61bgtT9a/4DzZkL4sM2lpKexJ/Sc1bxGM Odzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768057787; x=1768662587; 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=csZdrKP5V1PNFMXR8xX+/RBApYgeOuQXpn5FzbDjqFQ=; b=W7ku+Honlcan9AT086uWqRJtHLwoV2TG2UfhOQsFzDIhZuje52APM6YgGEJZzIO+2V LvBmiDSVqMntF6cPI8tYldofKSF/BfZg7zgMU9K8WYj5E7QommNNYkcPf6Ti7kKXPGuX yLEOMGrsFopSLUuzA4pPSsEtmMGBagi/dR+9weNn5CW2Ka1MuMUjIMwKIQYF8wvD62j8 E8ZslR713EveStn3C0Ay+9gxYl8L2Bm92z8hONvUR/ZMbjVOWRfScTZ4Awz3HZGfUNtX bcN36qbvLIOWWawYuC7z5F/HNjM2hI/iSmDk+spfoAVMyPtmW56sczZUZP8NsbXlBIq4 EXBg== X-Forwarded-Encrypted: i=1; AJvYcCUouQJ0nDVQLWHldZitaVRVtjpNFbm1mfbLjsggJrEf0DpsdAhOZDSme9RH/RlvDJ++UYGCnlLuAl/Pihk=@vger.kernel.org X-Gm-Message-State: AOJu0YzGKzaLdw53KuW1hrq81cMMbnmRwRxJSAKahnuXunhPdhELI1La OugodPyiA/4ZPpw4JIo6t0KWCzOiXvwqVt2LJ0zVz4btJ3kehua5Yvl/ X-Gm-Gg: AY/fxX56cJPHXH07aukW0wjsxPcPBXeTl+r/KmliC4ErgJZdjJndmlRI/KJ8K48aC7P Yp1Kn+GMkq37MerJSFFH+anhMwmJ73S3AmhL79c45drpeJsmppaYnj4GUXO9ZWyTwZegdL7xXhH U92fstu9U9n9+H7g8Ts8DjMFvoucpBg61qRsdN621H2gE6fJhT0QBESgurPCduZD8UmZY3RhHuf yaqCl4JInfvo1wommUHu8SBekxNNQ3ZmJlZAiBKrGD67Ued1TWHJL89G/KTU8DOxy3Dk3jJHnHK 3kLGODIQ+KvPOGqf+CheU8yHYmnji5bJrgWWHtD/KC9XvwZilYZWQB7JI1HIvbalFMoM8CqLPYy dz5nkoA18I5sEBOY1e6dITPt19eU/CtydFIuZKpMLMUrgi8o2Btp4OviIeXmvNB0aCKKprG+2sa anL4Nyl1/b7L3BKLT9ho8PXaDOvI//QU5bNl6U2v2MnTw2END4RVDVL9Ql54jbskESY5GBBft1 X-Google-Smtp-Source: AGHT+IFBX48hY3Q9PVP8SQO8XCpmSVoMleJSOwz7zkGOzjVdL6fPS2OSYcR91pM3G3FgTl60Yxo2Rg== X-Received: by 2002:a05:6512:3da7:b0:594:253c:209f with SMTP id 2adb3069b0e04-59b6f03520dmr4616760e87.39.1768057786509; Sat, 10 Jan 2026 07:09:46 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (37-33-148-7.bb.dnainternet.fi. [37.33.148.7]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59b75543a64sm2137059e87.49.2026.01.10.07.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 07:09:45 -0800 (PST) From: Kari Argillander Date: Sat, 10 Jan 2026 17:08:13 +0200 Subject: [PATCH RFC v3 15/15] 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: <20260110-this_module_fix-v3-15-97a3d9c14e8b@gmail.com> References: <20260110-this_module_fix-v3-0-97a3d9c14e8b@gmail.com> In-Reply-To: <20260110-this_module_fix-v3-0-97a3d9c14e8b@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=1768057742; l=3438; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=evAHr1gD6EfPZW8LvM5pPL6GuIcZSSelhlqgoHK4/G4=; b=PFKAsdYOgAKKCPm1WVwlkXpmaaN/dpAj9cbBEmgQyEeJJ4usBhD6p46VpXhsFr7jQVDIR8GLy nz5qXpoXcCEDRCygmv7YowFfq5KDSq1Gvbqm9IS5/ewHkyP6TQswkse 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 3acc60a83b09..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() - ) - }}; - - /// 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