@@ -388,9 +388,15 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
388388 let read_func = if permissions_are_readonly ( & param_permissions) {
389389 format ! (
390390 "
391- fn read(&self) -> &<{param_type_internal} as kernel::module_param::ModuleParam>::Value {{
392- // SAFETY: Parameters do not need to be locked because they are read only or sysfs is not enabled.
393- unsafe {{ <{param_type_internal} as kernel::module_param::ModuleParam>::value(&__{name}_{param_name}_value) }}
391+ fn read(&self)
392+ -> &<{param_type_internal} as kernel::module_param::ModuleParam>::Value {{
393+ // SAFETY: Parameters do not need to be locked because they are
394+ // read only or sysfs is not enabled.
395+ unsafe {{
396+ <{param_type_internal} as kernel::module_param::ModuleParam>::value(
397+ &__{name}_{param_name}_value
398+ )
399+ }}
394400 }}
395401 " ,
396402 name = info. name,
@@ -400,9 +406,14 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
400406 } else {
401407 format ! (
402408 "
403- fn read<'lck>(&self, lock: &'lck kernel::KParamGuard) -> &'lck <{param_type_internal} as kernel::module_param::ModuleParam>::Value {{
409+ fn read<'lck>(&self, lock: &'lck kernel::KParamGuard)
410+ -> &'lck <{param_type_internal} as kernel::module_param::ModuleParam>::Value {{
404411 // SAFETY: Parameters are locked by `KParamGuard`.
405- unsafe {{ <{param_type_internal} as kernel::module_param::ModuleParam>::value(&__{name}_{param_name}_value) }}
412+ unsafe {{
413+ <{param_type_internal} as kernel::module_param::ModuleParam>::value(
414+ &__{name}_{param_name}_value
415+ )
416+ }}
406417 }}
407418 " ,
408419 name = info. name,
@@ -413,13 +424,15 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
413424 let kparam = format ! (
414425 "
415426 kernel::bindings::kernel_param__bindgen_ty_1 {{
416- arg: unsafe {{ &__{name}_{param_name}_value }} as *const _ as *mut core::ffi::c_void,
427+ arg: unsafe {{ &__{name}_{param_name}_value }}
428+ as *const _ as *mut core::ffi::c_void,
417429 }},
418430 " ,
419431 name = info. name,
420432 param_name = param_name,
421433 ) ;
422- write ! ( modinfo. buffer,
434+ write ! (
435+ modinfo. buffer,
423436 "
424437 static mut __{name}_{param_name}_value: {param_type_internal} = {param_default};
425438
@@ -443,26 +456,30 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
443456 }}
444457
445458 #[cfg(not(MODULE))]
446- const __{name}_{param_name}_name: *const core::ffi::c_char = b\" {name}.{param_name}\\ 0\" as *const _ as *const core::ffi::c_char;
459+ const __{name}_{param_name}_name: *const core::ffi::c_char =
460+ b\" {name}.{param_name}\\ 0\" as *const _ as *const core::ffi::c_char;
447461
448462 #[cfg(MODULE)]
449- const __{name}_{param_name}_name: *const core::ffi::c_char = b\" {param_name}\\ 0\" as *const _ as *const core::ffi::c_char;
463+ const __{name}_{param_name}_name: *const core::ffi::c_char =
464+ b\" {param_name}\\ 0\" as *const _ as *const core::ffi::c_char;
450465
451466 #[link_section = \" __param\" ]
452467 #[used]
453- static __{name}_{param_name}_struct: __{name}_{param_name}_RacyKernelParam = __{name}_{param_name}_RacyKernelParam(kernel::bindings::kernel_param {{
454- name: __{name}_{param_name}_name,
455- // SAFETY: `__this_module` is constructed by the kernel at load time and will not be freed until the module is unloaded.
456- #[cfg(MODULE)]
457- mod_: unsafe {{ &kernel::bindings::__this_module as *const _ as *mut _ }},
458- #[cfg(not(MODULE))]
459- mod_: core::ptr::null_mut(),
460- ops: unsafe {{ &{ops} }} as *const kernel::bindings::kernel_param_ops,
461- perm: {permissions},
462- level: -1,
463- flags: 0,
464- __bindgen_anon_1: {kparam}
465- }});
468+ static __{name}_{param_name}_struct: __{name}_{param_name}_RacyKernelParam =
469+ __{name}_{param_name}_RacyKernelParam(kernel::bindings::kernel_param {{
470+ name: __{name}_{param_name}_name,
471+ // SAFETY: `__this_module` is constructed by the kernel at load time
472+ // and will not be freed until the module is unloaded.
473+ #[cfg(MODULE)]
474+ mod_: unsafe {{ &kernel::bindings::__this_module as *const _ as *mut _ }},
475+ #[cfg(not(MODULE))]
476+ mod_: core::ptr::null_mut(),
477+ ops: unsafe {{ &{ops} }} as *const kernel::bindings::kernel_param_ops,
478+ perm: {permissions},
479+ level: -1,
480+ flags: 0,
481+ __bindgen_anon_1: {kparam}
482+ }});
466483 " ,
467484 name = info. name,
468485 param_type_internal = param_type_internal,
@@ -472,7 +489,8 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
472489 ops = ops,
473490 permissions = param_permissions,
474491 kparam = kparam,
475- ) . unwrap ( ) ;
492+ )
493+ . unwrap ( ) ;
476494 }
477495 }
478496
@@ -513,11 +531,16 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
513531
514532 static mut __MOD: Option<{type_}> = None;
515533
516- // SAFETY: `__this_module` is constructed by the kernel at load time and will not be freed until the module is unloaded.
534+ // SAFETY: `__this_module` is constructed by the kernel at load time and will not be
535+ // freed until the module is unloaded.
517536 #[cfg(MODULE)]
518- static THIS_MODULE: kernel::ThisModule = unsafe {{ kernel::ThisModule::from_ptr(&kernel::bindings::__this_module as *const _ as *mut _) }};
537+ static THIS_MODULE: kernel::ThisModule = unsafe {{
538+ kernel::ThisModule::from_ptr(&kernel::bindings::__this_module as *const _ as *mut _)
539+ }};
519540 #[cfg(not(MODULE))]
520- static THIS_MODULE: kernel::ThisModule = unsafe {{ kernel::ThisModule::from_ptr(core::ptr::null_mut()) }};
541+ static THIS_MODULE: kernel::ThisModule = unsafe {{
542+ kernel::ThisModule::from_ptr(core::ptr::null_mut())
543+ }};
521544
522545 // Loadable modules need to export the `{{init,cleanup}}_module` identifiers.
523546 #[cfg(MODULE)]
@@ -597,7 +620,9 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
597620 modinfo = modinfo. buffer,
598621 generated_array_types = generated_array_types,
599622 initcall_section = ".initcall6.init"
600- ) . parse ( ) . expect ( "Error parsing formatted string into token stream." )
623+ )
624+ . parse ( )
625+ . expect ( "Error parsing formatted string into token stream." )
601626}
602627
603628#[ cfg( test) ]
0 commit comments