Re: linux-next: build failure after merge of the modules tree

From: Andreas Hindborg

Date: Tue Nov 04 2025 - 05:15:40 EST


Hi,

"Stephen Rothwell" <sfr@xxxxxxxxxxxxxxxx> writes:

> Hi all,
>
> After merging the modules tree, today's linux-next build (x86_64
> allmodconfig) failed like this:
>
> error[E0308]: mismatched types
> --> rust/kernel/module_param.rs:75:47
> |
> 75 | let new_value = T::try_from_param_arg(arg)?;
> | --------------------- ^^^ expected `&BStr`, found `&CStr`
> | |
> | arguments to this function are incorrect
> |
> = note: expected reference `&BStr`
> found reference `&ffi::CStr`
> note: associated function defined here
> --> rust/kernel/module_param.rs:32:8
> |
> 32 | fn try_from_param_arg(arg: &BStr) -> Result<Self>;
> | ^^^^^^^^^^^^^^^^^^
>
> error: aborting due to 1 previous error
>
> For more information about this error, try `rustc --explain E0308`.
>
> Caused by commit
>
> 0b08fc292842 ("rust: introduce module_param module")
>
> This is some interaction with something later in linux-next - presumably
> commit
>
> 3b83f5d5e78a ("rust: replace `CStr` with `core::ffi::CStr`")
>
> from the rust tree.
>
> Hopefully someone can provide a resolution for me tomorrow.
>
> I have used the modules tree from next-20251103 for today.

Please use the following resolution:

diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs
index e7d5c930a467d..6a8a7a875643a 100644
--- a/rust/kernel/module_param.rs
+++ b/rust/kernel/module_param.rs
@@ -70,6 +70,7 @@ pub trait ModuleParam: Sized + Copy {
// SAFETY: By function safety requirement, val is non-null, null-terminated
// and valid for reads for the duration of this function.
let arg = unsafe { CStr::from_char_ptr(val) };
+ let arg: &BStr = arg.as_ref();

crate::error::from_result(|| {
let new_value = T::try_from_param_arg(arg)?;
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index d62e9c1e2a898..decb0849f3d33 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -133,10 +133,10 @@ fn emit_params(&mut self, info: &ModuleInfo) {
::kernel::module_param::KernelParam::new(
::kernel::bindings::kernel_param {{
name: if ::core::cfg!(MODULE) {{
- ::kernel::c_str!(\"{param_name}\").as_bytes_with_nul()
+ ::kernel::c_str!(\"{param_name}\").to_bytes_with_nul()
}} else {{
::kernel::c_str!(\"{module_name}.{param_name}\")
- .as_bytes_with_nul()
+ .to_bytes_with_nul()
}}.as_ptr(),
// SAFETY: `__this_module` is constructed by the kernel at load
// time and will not be freed until the module is unloaded.



Best regards,
Andreas Hindborg