[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0ac7cfba-6b69-439e-a9ee-1175ca8d0913@nvidia.com>
Date: Tue, 29 Apr 2025 13:28:09 -0700
From: John Hubbard <jhubbard@...dia.com>
To: Boqun Feng <boqun.feng@...il.com>, Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Andrew Morton
<akpm@...ux-foundation.org>, Alexander Viro <viro@...iv.linux.org.uk>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Gary Guo
<gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/2] uaccess: rust: add strncpy_from_user
On 4/29/25 10:30 AM, Boqun Feng wrote:
> On Tue, Apr 29, 2025 at 09:02:22AM +0000, Alice Ryhl wrote:
...
>> +#[inline]
>> +pub fn raw_strncpy_from_user(ptr: UserPtr, buf: &mut [MaybeUninit<u8>]) -> Result<usize> {
>> + // CAST: Slice lengths are guaranteed to be `<= isize::MAX`.
>> + let len = buf.len() as isize;
>> +
>> + // SAFETY: `buf` is valid for writing `buf.len()` bytes.
>> + let res = unsafe {
>> + bindings::strncpy_from_user(buf.as_mut_ptr().cast::<c_char>(), ptr as *const c_char, len)
>> + };
>> +
>> + if res < 0 {
>> + return Err(Error::from_errno(res as i32));
>> + }
>> +
>
> Nit: this can be a
>
> let copy_len = kernel::error::to_result(res)?;
>
Doesn't that discard the length, though, by returning Ok(()) ?
thanks,
--
John Hubbard
Powered by blists - more mailing lists