diff --git a/rust/kernel/buffer.rs b/rust/kernel/buffer.rs index e5eb0e406dba33..ef1525f5b45d78 100644 --- a/rust/kernel/buffer.rs +++ b/rust/kernel/buffer.rs @@ -7,10 +7,7 @@ pub struct Buffer<'a> { impl<'a> Buffer<'a> { pub fn new(slice: &'a mut [u8]) -> Self { - Buffer { - slice, - pos: 0, - } + Buffer { slice, pos: 0 } } pub fn bytes_written(&self) -> usize { diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs index 0131a2f001532d..23823e608a7f37 100644 --- a/rust/kernel/module_param.rs +++ b/rust/kernel/module_param.rs @@ -9,7 +9,7 @@ use core::fmt::Write; /// Types that can be used for module parameters. /// Note that displaying the type in `sysfs` will fail if `to_string` returns /// more than `kernel::PAGE_SIZE` bytes (including an additional null terminator). -pub trait ModuleParam : core::fmt::Display + core::marker::Sized { +pub trait ModuleParam: core::fmt::Display + core::marker::Sized { /// Setting this to `true` allows the parameter to be passed without an /// argument (e.g. just `module.param` instead of `module.param=foo`). const NOARG_ALLOWED: bool; @@ -23,15 +23,22 @@ pub trait ModuleParam : core::fmt::Display + core::marker::Sized { /// /// If `val` is non-null then it must point to a valid null-terminated /// string. The `arg` field of `param` must be an instance of `Self`. - unsafe extern "C" fn set_param(val: *const crate::c_types::c_char, param: *const crate::bindings::kernel_param) -> crate::c_types::c_int { - let arg = if val.is_null() { None } else { Some(crate::c_types::c_string_bytes(val)) }; + unsafe extern "C" fn set_param( + val: *const crate::c_types::c_char, + param: *const crate::bindings::kernel_param, + ) -> crate::c_types::c_int { + let arg = if val.is_null() { + None + } else { + Some(crate::c_types::c_string_bytes(val)) + }; match Self::try_from_param_arg(arg) { Some(new_value) => { let old_value = (*param).__bindgen_anon_1.arg as *mut Self; let _ = core::ptr::replace(old_value, new_value); 0 } - None => crate::error::Error::EINVAL.to_kernel_errno() + None => crate::error::Error::EINVAL.to_kernel_errno(), } } @@ -39,7 +46,10 @@ pub trait ModuleParam : core::fmt::Display + core::marker::Sized { /// /// `buf` must be a buffer of length at least `kernel::PAGE_SIZE` that is /// writeable. The `arg` field of `param` must be an instance of `Self`. - unsafe extern "C" fn get_param(buf: *mut crate::c_types::c_char, param: *const crate::bindings::kernel_param) -> crate::c_types::c_int { + unsafe extern "C" fn get_param( + buf: *mut crate::c_types::c_char, + param: *const crate::bindings::kernel_param, + ) -> crate::c_types::c_int { let slice = core::slice::from_raw_parts_mut(buf as *mut u8, crate::PAGE_SIZE); let mut buf = crate::buffer::Buffer::new(slice); match write!(buf, "{}\0", *((*param).__bindgen_anon_1.arg as *mut Self)) { @@ -61,7 +71,7 @@ pub trait ModuleParam : core::fmt::Display + core::marker::Sized { /// otherwise are parsed as octal. Anything else is parsed as decimal. A /// leading `+` or `-` is also permitted. Any string parsed by `kstrtol` or /// `kstrtoul` will be successfully parsed. -trait ParseInt : Sized { +trait ParseInt: Sized { fn from_str_radix(src: &str, radix: u32) -> Result; fn checked_neg(self) -> Option; @@ -106,7 +116,7 @@ macro_rules! impl_parse_int { self.checked_neg() } } - } + }; } impl_parse_int!(i8); @@ -131,7 +141,7 @@ macro_rules! impl_module_param { <$ty as crate::module_param::ParseInt>::from_str(utf8) } } - } + }; } macro_rules! make_param_ops { @@ -143,11 +153,11 @@ macro_rules! make_param_ops { } else { 0 }, - set: Some(<$ty as crate::module_param::ModuleParam>::set_param), + set: Some(<$ty as crate::module_param::ModuleParam>::set_param), get: Some(<$ty as crate::module_param::ModuleParam>::get_param), free: Some(<$ty as crate::module_param::ModuleParam>::free), }; - } + }; } impl_module_param!(i8);