@@ -388,9 +388,15 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
388
388
let read_func = if permissions_are_readonly ( & param_permissions) {
389
389
format ! (
390
390
"
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
+ }}
394
400
}}
395
401
" ,
396
402
name = info. name,
@@ -400,9 +406,14 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
400
406
} else {
401
407
format ! (
402
408
"
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 {{
404
411
// 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
+ }}
406
417
}}
407
418
" ,
408
419
name = info. name,
@@ -413,13 +424,15 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
413
424
let kparam = format ! (
414
425
"
415
426
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,
417
429
}},
418
430
" ,
419
431
name = info. name,
420
432
param_name = param_name,
421
433
) ;
422
- write ! ( modinfo. buffer,
434
+ write ! (
435
+ modinfo. buffer,
423
436
"
424
437
static mut __{name}_{param_name}_value: {param_type_internal} = {param_default};
425
438
@@ -443,26 +456,30 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
443
456
}}
444
457
445
458
#[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;
447
461
448
462
#[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;
450
465
451
466
#[link_section = \" __param\" ]
452
467
#[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
+ }});
466
483
" ,
467
484
name = info. name,
468
485
param_type_internal = param_type_internal,
@@ -472,7 +489,8 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
472
489
ops = ops,
473
490
permissions = param_permissions,
474
491
kparam = kparam,
475
- ) . unwrap ( ) ;
492
+ )
493
+ . unwrap ( ) ;
476
494
}
477
495
}
478
496
@@ -513,11 +531,16 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
513
531
514
532
static mut __MOD: Option<{type_}> = None;
515
533
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.
517
536
#[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
+ }};
519
540
#[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
+ }};
521
544
522
545
// Loadable modules need to export the `{{init,cleanup}}_module` identifiers.
523
546
#[cfg(MODULE)]
@@ -597,7 +620,9 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
597
620
modinfo = modinfo. buffer,
598
621
generated_array_types = generated_array_types,
599
622
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." )
601
626
}
602
627
603
628
#[ cfg( test) ]
0 commit comments