[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <99ca28045252ba77c302d74e57c2976e60744c4d.1738832118.git.viresh.kumar@linaro.org>
Date: Thu, 6 Feb 2025 14:58:22 +0530
From: Viresh Kumar <viresh.kumar@...aro.org>
To: "Rafael J. Wysocki" <rafael@...nel.org>,
Miguel Ojeda <miguel.ojeda.sandonis@...il.com>,
Danilo Krummrich <dakr@...hat.com>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>
Cc: Viresh Kumar <viresh.kumar@...aro.org>,
linux-pm@...r.kernel.org,
Vincent Guittot <vincent.guittot@...aro.org>,
Stephen Boyd <sboyd@...nel.org>,
Nishanth Menon <nm@...com>,
rust-for-linux@...r.kernel.org,
Manos Pitsidianakis <manos.pitsidianakis@...aro.org>,
Erik Schilling <erik.schilling@...aro.org>,
Alex Bennée <alex.bennee@...aro.org>,
Joakim Bech <joakim.bech@...aro.org>,
Rob Herring <robh@...nel.org>,
Anisse Astier <anisse@...ier.eu>,
linux-kernel@...r.kernel.org
Subject: [PATCH V8 01/14] rust: macros: enable use of hyphens in module names
From: Anisse Astier <anisse@...ier.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@...ier.eu>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
[Viresh: Replace "-" with '-']
Signed-off-by: Viresh Kumar <viresh.kumar@...aro.org>
---
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..2e740bbdb598 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.31.1.272.g89b43f80a514
Powered by blists - more mailing lists