From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: "Deborah Brouwer" <deborah.brouwer@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 2/2] drm/tyr: allow userspace buffers to be mismatched
Date: Sat, 17 Oct 2026 10:36:49 +0900 [thread overview]
Message-ID: <DM6Q8HOV2J6Z.19M92D448I2JQ@nvidia.com> (raw)
In-Reply-To: <atHwZg245MM7l9Ty@google.com>
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.
prev parent reply other threads:[~2026-10-17 1:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 18:35 [PATCH v2 0/2] drm/tyr: allow mismatched buffers for dev_query Deborah Brouwer
2026-10-15 18:35 ` [PATCH v2 1/2] rust: uaccess: add UserSliceWriter::clear() Deborah Brouwer
2026-10-16 8:02 ` Alice Ryhl
2026-10-15 18:35 ` [PATCH v2 2/2] drm/tyr: allow userspace buffers to be mismatched Deborah Brouwer
2026-10-16 9:37 ` Alice Ryhl
2026-10-17 1:36 ` Alexandre Courbot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM6Q8HOV2J6Z.19M92D448I2JQ@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=deborah.brouwer@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox