"Benno Lossin" <los...@kernel.org> writes: > On Thu Jun 19, 2025 at 2:20 PM CEST, Andreas Hindborg wrote: >> "Benno Lossin" <los...@kernel.org> writes: >>> On Thu Jun 12, 2025 at 3:40 PM CEST, Andreas Hindborg wrote:
[...] >>>> + crate::error::from_result(|| { >>>> + let new_value = T::try_from_param_arg(arg)?; >>>> + >>>> + // SAFETY: By function safety requirements `param` is be valid >>>> for reads. >>>> + let old_value = unsafe { (*param).__bindgen_anon_1.arg as *mut T >>>> }; >>>> + >>>> + // SAFETY: By function safety requirements, the target of >>>> `old_value` is valid for writes >>>> + // and is initialized. >>>> + unsafe { *old_value = new_value }; >>> >>> So if we keep the `ModuleParam: Copy` bound from above, then we don't >>> need to drop the type here (as `Copy` implies `!Drop`). So we could also >>> remove the requirement for initialized memory and use `ptr::write` here >>> instead. Thoughts? >> >> Yes, that is the rationale for the `Copy` bound. What would be the >> benefit of using `ptr::write`? They should be equivalent for `Copy` >> types, right. > > They should be equivalent, but if we drop the requirement that the value > is initialized to begin with, then removing `Copy` will result in UB > here. > >> I was using `ptr::replace`, but Alice suggested the pace expression >> assignment instead, since I was not using the old value. > > That makes sense, but if we also remove the initialized requirement, > then I would prefer `ptr::write`. OK, we can do that. Best regards, Andreas Hindborg