On Sat, Oct 17, 2026 at 10:36:49AM +0900, Alexandre Courbot wrote:
> On Fri Oct 16, 2026 at 6:37 PM JST, Alice Ryhl wrote:
> > On Thu, Oct 15, 2026 at 11:35:21AM -0700, Deborah Brouwer wrote:
> >> +// If the user buffer is at least the minimum required size, then
> >> +// copy as much of the kernel object as will fit into the user buffer.
> >> +// Don't fail if the user buffer is smaller than the kernel object.
> >> +// If the user buffer is bigger than needed, zero out the remainder.
> >> +fn set_uobj<T: AsBytes>(usr_dst: u64, size: u32, min_size: usize, 
> >> src_obj: &T) -> Result {
> >> +    if (size as usize) < min_size {
> >> +        return Err(EINVAL);
> >
> > Use `kernel::num::casts::u32_as_usize` here.
> >
> >> +    }
> >> +
> >> +    let mut writer = UserSlice::new(UserPtr::from_addr(usr_dst as usize), 
> >> size as usize).writer();
> >
> > Avoid casting to usize twice.
> >
> >     let size = kernel::num::casts::u32_as_usize(size);
> 
> Or `usize::from_safe_cast(size)` after importing `FromSafeCast` -
> `u32_as_usize` is useful in const context, but for regular conversions
> the `FromSafeCast` trait looks slightly better.

Yes, since we aren't using this in a const context I will switch over to
usize::from_safe_cast(size) in the next version, thanks.

> 

Reply via email to