On Thu Jun 12, 2025 at 3:40 PM CEST, Andreas Hindborg wrote:
> +
> +    fn emit_params(&mut self, info: &ModuleInfo) {
> +        let Some(params) = &info.params else {
> +            return;
> +        };
> +
> +        for param in params {
> +            let ops = param_ops_path(&param.ptype);
> +
> +            // Note: The spelling of these fields is dictated by the user 
> space
> +            // tool `modinfo`.
> +            self.emit_param("parmtype", &param.name, &param.ptype);
> +            self.emit_param("parm", &param.name, &param.description);

I just read this part again and I want to voice my dissatisfaction with
these key names. (not that you can do anything about that :)

> +
> +            write!(
> +                self.param_buffer,
> +                "
> +                    pub(crate) static {param_name}:

Does this need to be accessed by anything else except the static below?
If no, then can we move it inside of that static? So

    #[link_section = \"__param\"]
    #[used]
    static __{module_name}_{param_name}_struct: 
::kernel::module_param::RacyKernelParam = {
        static {param_name}:
            ::kernel::module_param::ModuleParamAccess<{param_type}> =
                ::kernel::module_param::ModuleParamAccess::new({param_default});
        // ...
    };

---
Cheers,
Benno

> +                        
> ::kernel::module_param::ModuleParamAccess<{param_type}> =
> +                            
> ::kernel::module_param::ModuleParamAccess::new({param_default});
> +
> +                    #[link_section = \"__param\"]
> +                    #[used]
> +                    static __{module_name}_{param_name}_struct:
> +                        ::kernel::module_param::RacyKernelParam =
> +                        
> ::kernel::module_param::RacyKernelParam(::kernel::bindings::kernel_param {{
> +                            name: if cfg!(MODULE) {{
> +                                
> ::kernel::c_str!(\"{param_name}\").as_bytes_with_nul()
> +                            }} else {{
> +                                
> ::kernel::c_str!(\"{module_name}.{param_name}\").as_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.
> +                            #[cfg(MODULE)]
> +                            mod_: unsafe {{
> +                                (&::kernel::bindings::__this_module
> +                                    as *const ::kernel::bindings::module)
> +                                    .cast_mut()
> +                            }},
> +                            #[cfg(not(MODULE))]
> +                            mod_: ::core::ptr::null_mut(),
> +                            ops: &{ops} as *const 
> ::kernel::bindings::kernel_param_ops,
> +                            perm: 0, // Will not appear in sysfs
> +                            level: -1,
> +                            flags: 0,
> +                            __bindgen_anon_1:
> +                                
> ::kernel::bindings::kernel_param__bindgen_ty_1 {{
> +                                    arg: {param_name}.as_mut_ptr().cast()
> +                                }},
> +                        }});
> +                ",
> +                module_name = info.name,
> +                param_type = param.ptype,
> +                param_default = param.default,
> +                param_name = param.name,
> +                ops = ops,
> +            )
> +            .unwrap();
> +        }
> +    }
> +}

Reply via email to