[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251028-pwm_fixes-v1-1-25a532d31998@samsung.com>
Date: Tue, 28 Oct 2025 13:22:32 +0100
From: Michal Wilczynski <m.wilczynski@...sung.com>
To: 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
	<lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,  Alice Ryhl
	<aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,  Danilo Krummrich
	<dakr@...nel.org>,  Michal Wilczynski <m.wilczynski@...sung.com>,  Drew
	Fustini <fustini@...nel.org>, Guo Ren <guoren@...nel.org>,  Fu Wei
	<wefu@...hat.com>,  Uwe Kleine-König <ukleinek@...nel.org>
Cc: Stephen Rothwell <sfr@...b.auug.org.au>, rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-pwm@...r.kernel.org, 
	linux-riscv@...ts.infradead.org
Subject: [PATCH 1/4] rust: macros: Add support for 'imports_ns' to module!
Kernel modules that use C symbols exported via `EXPORT_SYMBOL_NS` must
declare this dependency for `modpost` verification. C modules achieve
this by using the `MODULE_IMPORT_NS(NAMESPACE)` macro, which embeds an
`import_ns=<NAMESPACE>` tag into the `.modinfo` section.
The Rust `module!` macro lacked the ability to generate these tags,
resulting in build warnings for Rust drivers (like the PWM driver) that
call namespaced C functions.
Modify the `module!` macro's internal parser (`ModuleInfo`) to accept a
new optional field `imports_ns`, which takes an array of namespace
strings.  Update the code generator (`ModInfoBuilder::emit`) loop to
iterate over these strings and emit the corresponding
`import_ns=<NAMESPACE>` tags into the `.modinfo` section using the
existing `#[link_section]` mechanism.
This provides the necessary infrastructure for Rust modules to correctly
declare their C namespace dependencies.
Signed-off-by: Michal Wilczynski <m.wilczynski@...sung.com>
---
 rust/macros/module.rs | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 5ee54a00c0b65699596e660b2d4d60e64be2a50c..408cd115487514c8be79724d901c676435696376 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -98,6 +98,7 @@ struct ModuleInfo {
     description: Option<String>,
     alias: Option<Vec<String>>,
     firmware: Option<Vec<String>>,
+    imports_ns: Option<Vec<String>>,
 }
 
 impl ModuleInfo {
@@ -112,6 +113,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
             "license",
             "alias",
             "firmware",
+            "imports_ns",
         ];
         const REQUIRED_KEYS: &[&str] = &["type", "name", "license"];
         let mut seen_keys = Vec::new();
@@ -137,6 +139,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
                 "license" => info.license = expect_string_ascii(it),
                 "alias" => info.alias = Some(expect_string_array(it)),
                 "firmware" => info.firmware = Some(expect_string_array(it)),
+                "imports_ns" => info.imports_ns = Some(expect_string_array(it)),
                 _ => panic!("Unknown key \"{key}\". Valid keys are: {EXPECTED_KEYS:?}."),
             }
 
@@ -195,6 +198,11 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
             modinfo.emit("firmware", &fw);
         }
     }
+    if let Some(imports) = info.imports_ns {
+        for ns in imports {
+            modinfo.emit("import_ns", &ns);
+        }
+    }
 
     // Built-in modules also export the `file` modinfo string.
     let file =
-- 
2.34.1
Powered by blists - more mailing lists
 
