Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues: - [High] `ModuleParamAccess` lacks `#[repr(C)]`, leading to potential Undefined Behavior and memory corruption when its pointer is cast to `SetOnce<T>`. -- --- Patch [1]: [PATCH 1/3] rust: sync: return `Result<&T, T>` from `SetOnce::populate()` --- commit e0d10f7a2c42bcda24ee9851cc2fda3d4c4bc480 Author: Alice Ryhl <[email protected]> rust: sync: return Result<&T, T> from SetOnce::populate() This commit changes the return value of SetOnce::populate() from a boolean to a Result to allow infallible access to the inserted value on success. It also ensures the inserted value is not dropped under a lock if populate() fails, and updates ModuleParam and Binder to handle the new return type. > diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs > index 6541af218390c..8f0bd085badfe 100644 > --- a/rust/kernel/module_param.rs > +++ b/rust/kernel/module_param.rs > @@ -77,10 +77,10 @@ pub trait ModuleParam: Sized + Copy { > // SAFETY: By function safety requirements, this access is safe. > let container = unsafe { > &*((*param).__bindgen_anon_1.arg.cast::<SetOnce<T>>()) }; [Severity: High] This is a pre-existing issue, but since we are modifying this code block, is it safe to cast this void pointer directly to SetOnce<T>? Looking at the definition of ModuleParamAccess<T>, it lacks a #[repr(C)] annotation: rust/kernel/module_param.rs:ModuleParamAccess { value: SetOnce<T>, default: T, } Since it uses the default Rust layout, the compiler is free to reorder these fields. When as_void_ptr() passes a pointer to the entire struct into the C kernel parameters API: rust/kernel/module_param.rs:ModuleParamAccess::as_void_ptr() { core::ptr::from_ref(self).cast_mut().cast() } And set_param casts it back directly to SetOnce<T> (assuming it sits at offset 0), could this lead to memory corruption if the compiler decides to place default before value? > - container > - .populate(new_value) > - .then_some(0) > - .ok_or(kernel::error::code::EEXIST) > + match container.populate(new_value) { > + Ok(_) => Ok(0), > + Err(_) => Err(EEXIST), > + } > }) > } -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
