From: "Danilo Krummrich" <dakr@kernel.org>
To: "Lorenzo Delgado" <lnsdev@proton.me>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Alexandre Courbot" <acourbot@nvidia.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>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Robin Murphy" <robin.murphy@arm.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
nova-gpu@lists.linux.dev, driver-core@lists.linux.dev,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3] rust: io: convert ResourceSize into a transparent newtype
Date: Thu, 24 Sep 2026 19:21:51 +0200 [thread overview]
Message-ID: <DLNPXJ4WPH4L.2MBUGV1TAESYY@kernel.org> (raw)
In-Reply-To: <20260920-resource-size-newtype-v3-1-9451444e83bb@proton.me>
On Sun Sep 20, 2026 at 2:13 PM CEST, Lorenzo Delgado wrote:
> `ResourceSize` is a bare type alias for `resource_size_t`, so it
> inherits every integer operation and `as` cast. That allows operations
> that make no sense for the size of a hardware resource, such as mixing
> it with unrelated integers or truncating it with a cast.
>
> Wrap it in a `#[repr(transparent)]` newtype so each conversion at a
> boundary is explicit. The representation is unchanged, so this is
> ABI-identical; only the spelling at the FFI boundary changes. Provide
> `from_raw`/`into_raw`, `From` in both directions, and a fallible
> `TryFrom<ResourceSize> for usize`. On 64-bit, where `resource_size_t`
> is a `u64`, also implement `FromSafeCastArch<ResourceSize> for usize`,
> so code that is specific to 64-bit can keep the conversion infallible.
This looks good now, but it makes me notice that dma_len() shouldn't return
ResourceSize in the first place.
The length of a single SG segment is bounded by max_segment_size, which is also
unsigned int.
So, I think we should change dma_len() to just return u32 (I'm also fine with a
new type, but it might be slighly overkill).
I'd usually pick this patch regardless and leave that for a follow-up, as it is
a separate issue. But if we change dma_len() first, we only have to update tyr
once, whereas if change it after we end up touching nova and tyr twice.
Thanks,
Danilo
next prev parent reply other threads:[~2026-09-24 17:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 12:13 [PATCH v3] rust: io: convert ResourceSize into a transparent newtype Lorenzo Delgado
2026-09-24 17:21 ` Danilo Krummrich [this message]
2026-09-27 18:11 ` Lorenzo Delgado
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=DLNPXJ4WPH4L.2MBUGV1TAESYY@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lnsdev@proton.me \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.