Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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@samsung.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Acked-by: Daniel Gomez <da.gomez@samsung.com>
Link: https://patch.msgid.link/20251028-pwm_fixes-v1-1-25a532d31998@samsung.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Michal Wilczynski and committed by
Uwe Kleine-König
739ad9be 3a866087

+8
+8
rust/macros/module.rs
··· 98 98 description: Option<String>, 99 99 alias: Option<Vec<String>>, 100 100 firmware: Option<Vec<String>>, 101 + imports_ns: Option<Vec<String>>, 101 102 } 102 103 103 104 impl ModuleInfo { ··· 113 112 "license", 114 113 "alias", 115 114 "firmware", 115 + "imports_ns", 116 116 ]; 117 117 const REQUIRED_KEYS: &[&str] = &["type", "name", "license"]; 118 118 let mut seen_keys = Vec::new(); ··· 139 137 "license" => info.license = expect_string_ascii(it), 140 138 "alias" => info.alias = Some(expect_string_array(it)), 141 139 "firmware" => info.firmware = Some(expect_string_array(it)), 140 + "imports_ns" => info.imports_ns = Some(expect_string_array(it)), 142 141 _ => panic!("Unknown key \"{key}\". Valid keys are: {EXPECTED_KEYS:?}."), 143 142 } 144 143 ··· 196 193 if let Some(firmware) = info.firmware { 197 194 for fw in firmware { 198 195 modinfo.emit("firmware", &fw); 196 + } 197 + } 198 + if let Some(imports) = info.imports_ns { 199 + for ns in imports { 200 + modinfo.emit("import_ns", &ns); 199 201 } 200 202 } 201 203