From: Anisse Astier <anisse@astier.eu>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
linux-pm@vger.kernel.org,
"Vincent Guittot" <vincent.guittot@linaro.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Anisse Astier" <anisse@astier.eu>
Subject: [PATCH v2] rust: macros: enable use of hyphens in module names
Date: Wed, 22 Jan 2025 14:39:52 +0100 [thread overview]
Message-ID: <20250122133952.501055-1-anisse@astier.eu> (raw)
In-Reply-To: <20250122131812.466080-1-anisse@astier.eu>
Some modules might need naming that contains hyphens "-" to match the
auto-probing by name in the platform devices that comes from the device
tree.
But rust identifiers cannot contain hyphens, so replace the module name
by an underscore anywhere we'd use it as an identifier.
Signed-off-by: Anisse Astier <anisse@astier.eu>
---
Hello,
Change since v1:
- rebase on branch rfl/staging/dev
Sorry for sending a v2 so quickly, but v1 was based on the wrong branch :-/
Kind regards,
Anisse
---
rust/macros/module.rs | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index cdf94f4982df..1eff30d2ca6a 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -182,7 +182,9 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
let info = ModuleInfo::parse(&mut it);
- let mut modinfo = ModInfoBuilder::new(info.name.as_ref());
+ /* Rust does not allow hyphens in identifiers, use underscore instead */
+ let name_identifier = info.name.replace("-", "_");
+ let mut modinfo = ModInfoBuilder::new(name_identifier.as_ref());
if let Some(author) = info.author {
modinfo.emit("author", &author);
}
@@ -298,14 +300,14 @@ mod __module_init {{
#[doc(hidden)]
#[link_section = \"{initcall_section}\"]
#[used]
- pub static __{name}_initcall: extern \"C\" fn() -> kernel::ffi::c_int = __{name}_init;
+ pub static __{name_identifier}_initcall: extern \"C\" fn() -> kernel::ffi::c_int = __{name_identifier}_init;
#[cfg(not(MODULE))]
#[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)]
core::arch::global_asm!(
r#\".section \"{initcall_section}\", \"a\"
- __{name}_initcall:
- .long __{name}_init - .
+ __{name_identifier}_initcall:
+ .long __{name_identifier}_init - .
.previous
\"#
);
@@ -313,7 +315,7 @@ mod __module_init {{
#[cfg(not(MODULE))]
#[doc(hidden)]
#[no_mangle]
- pub extern \"C\" fn __{name}_init() -> kernel::ffi::c_int {{
+ pub extern \"C\" fn __{name_identifier}_init() -> kernel::ffi::c_int {{
// SAFETY: This function is inaccessible to the outside due to the double
// module wrapping it. It is called exactly once by the C side via its
// placement above in the initcall section.
@@ -323,12 +325,12 @@ mod __module_init {{
#[cfg(not(MODULE))]
#[doc(hidden)]
#[no_mangle]
- pub extern \"C\" fn __{name}_exit() {{
+ pub extern \"C\" fn __{name_identifier}_exit() {{
// SAFETY:
// - This function is inaccessible to the outside due to the double
// module wrapping it. It is called exactly once by the C side via its
// unique name,
- // - furthermore it is only called after `__{name}_init` has returned `0`
+ // - furthermore it is only called after `__{name_identifier}_init` has returned `0`
// (which delegates to `__init`).
unsafe {{ __exit() }}
}}
@@ -369,6 +371,7 @@ unsafe fn __exit() {{
",
type_ = info.type_,
name = info.name,
+ name_identifier = name_identifier,
modinfo = modinfo.buffer,
initcall_section = ".initcall6.init"
)
--
2.48.1
next prev parent reply other threads:[~2025-01-22 13:39 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 11:22 [PATCH V7 00/16] Rust bindings for cpufreq and OPP core + sample driver Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 01/16] cpufreq: Use enum for cpufreq flags that use BIT() Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 02/16] PM / OPP: Add reference counting helpers for Rust implementation Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 03/16] rust: cpu: Add from_cpu() Viresh Kumar
2025-01-14 18:44 ` Greg KH
2025-01-15 7:20 ` Viresh Kumar
2025-01-15 7:54 ` Greg KH
2025-01-15 7:58 ` Viresh Kumar
2025-01-15 8:09 ` Greg KH
2025-01-16 9:17 ` Viresh Kumar
2025-01-15 8:10 ` Alice Ryhl
2025-01-15 8:33 ` Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 04/16] rust: device: Add property_present() Viresh Kumar
2025-01-14 18:42 ` Greg Kroah-Hartman
2025-01-14 18:42 ` Greg Kroah-Hartman
2025-01-15 7:15 ` Viresh Kumar
2025-01-15 7:35 ` Viresh Kumar
2025-01-15 17:21 ` Greg Kroah-Hartman
2025-01-13 11:23 ` [PATCH V7 05/16] rust: Add cpumask helpers Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 06/16] rust: Add bindings for cpumask Viresh Kumar
2025-01-22 14:40 ` Miguel Ojeda
2025-01-23 3:43 ` Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 07/16] rust: Add bare minimal bindings for clk framework Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 08/16] rust: Add initial bindings for OPP framework Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 09/16] rust: Extend OPP bindings for the OPP table Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 10/16] rust: Extend OPP bindings for the configuration options Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 11/16] rust: Add initial bindings for cpufreq framework Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 12/16] rust: Extend cpufreq bindings for policy and driver ops Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 13/16] rust: Extend cpufreq bindings for driver registration Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 14/16] rust: Extend OPP bindings with CPU frequency table Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 15/16] cpufreq: Add Rust based cpufreq-dt driver Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 16/16] DO-NOT_MERGE: cpufreq: Rename cpufreq-dt platdev Viresh Kumar
2025-01-22 13:18 ` [PATCH] rust: macros: enable use of hyphens in module names Anisse Astier
2025-01-22 13:39 ` Anisse Astier [this message]
2025-01-22 14:38 ` [PATCH v2] " Viresh Kumar
2025-01-30 4:58 ` Viresh Kumar
2025-01-30 6:08 ` Anisse Astier
2025-01-30 11:51 ` Alice Ryhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250122133952.501055-1-anisse@astier.eu \
--to=anisse@astier.eu \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox