mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Daniel Almeida" <daniel.almeida@collabora.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Benno Lossin" <lossin@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>
Cc: dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: [PATCH 07/13] drm/tyr: use `cv!` for constant conversions
Date: Wed, 25 Nov 2026 19:46:58 -0300	[thread overview]
Message-ID: <20261125-b4-tyr-as-casts-v1-7-2b2f53164d86@collabora.com> (raw)
In-Reply-To: <20261125-b4-tyr-as-casts-v1-0-2b2f53164d86@collabora.com>

An `as` cast silently drops the bits that do not fit the target type,
and nothing at the cast shows whether that can happen. As part of a
larger effort to reduce the number of `as` casts in Tyr, convert
constants with `cv!`, which fails the build if the value does not fit
the target type.

No functional change intended.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
 drivers/gpu/drm/tyr/file.rs | 2 +-
 drivers/gpu/drm/tyr/regs.rs | 6 +++---
 drivers/gpu/drm/tyr/vm.rs   | 8 +++++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs
index 9030e535b7d0..78c2147328e1 100644
--- a/drivers/gpu/drm/tyr/file.rs
+++ b/drivers/gpu/drm/tyr/file.rs
@@ -79,7 +79,7 @@ pub(crate) fn dev_query(
         if devquery.pointer == 0 {
             match devquery.type_ {
                 uapi::drm_panthor_dev_query_type_DRM_PANTHOR_DEV_QUERY_GPU_INFO => {
-                    devquery.size = core::mem::size_of_val(&reg_data.gpu_info) as u32;
+                    devquery.size = cv!(size_of::<uapi::drm_panthor_gpu_info>() => u32);
                     Ok(0)
                 }
                 _ => Err(EINVAL),
diff --git a/drivers/gpu/drm/tyr/regs.rs b/drivers/gpu/drm/tyr/regs.rs
index 603a9052c439..49e4adf2231d 100644
--- a/drivers/gpu/drm/tyr/regs.rs
+++ b/drivers/gpu/drm/tyr/regs.rs
@@ -751,11 +751,11 @@ fn from(access: AccessType) -> Self {
     #[repr(u8)]
     pub(crate) enum CoherencyMode {
         /// ACE-Lite coherency protocol.
-        AceLite = uapi::drm_panthor_gpu_coherency_DRM_PANTHOR_GPU_COHERENCY_ACE_LITE as u8,
+        AceLite = cv!(uapi::drm_panthor_gpu_coherency_DRM_PANTHOR_GPU_COHERENCY_ACE_LITE => u8),
         /// ACE coherency protocol.
-        Ace = uapi::drm_panthor_gpu_coherency_DRM_PANTHOR_GPU_COHERENCY_ACE as u8,
+        Ace = cv!(uapi::drm_panthor_gpu_coherency_DRM_PANTHOR_GPU_COHERENCY_ACE => u8),
         /// No coherency protocol.
-        None = uapi::drm_panthor_gpu_coherency_DRM_PANTHOR_GPU_COHERENCY_NONE as u8,
+        None = cv!(uapi::drm_panthor_gpu_coherency_DRM_PANTHOR_GPU_COHERENCY_NONE => u8),
     }
 
     impl TryFrom<Bounded<u32, 32>> for CoherencyMode {
diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
index d15db120352b..9b52f3562004 100644
--- a/drivers/gpu/drm/tyr/vm.rs
+++ b/drivers/gpu/drm/tyr/vm.rs
@@ -80,11 +80,13 @@
     #[derive(Debug, Clone, Copy, PartialEq, Eq)]
     pub(crate) enum VmFlag {
         /// Map as read-only.
-        Readonly = uapi::drm_panthor_vm_bind_op_flags_DRM_PANTHOR_VM_BIND_OP_MAP_READONLY as u32,
+        Readonly =
+            cv!(uapi::drm_panthor_vm_bind_op_flags_DRM_PANTHOR_VM_BIND_OP_MAP_READONLY => u32),
         /// Map as non-executable.
-        Noexec = uapi::drm_panthor_vm_bind_op_flags_DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC as u32,
+        Noexec = cv!(uapi::drm_panthor_vm_bind_op_flags_DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC => u32),
         /// Map as uncached.
-        Uncached = uapi::drm_panthor_vm_bind_op_flags_DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED as u32,
+        Uncached =
+            cv!(uapi::drm_panthor_vm_bind_op_flags_DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED => u32),
     }
 );
 

-- 
2.56.0


  parent reply	other threads:[~2026-11-25 22:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 22:46 [PATCH 00/13] drm/tyr: reduce the number of `as` casts Daniel Almeida
2026-11-25 22:46 ` [PATCH 01/13] drm/tyr: convert SeatInfo::slot from u8 to usize Daniel Almeida
2026-11-25 22:46 ` [PATCH 02/13] drm/tyr: convert VmAsData::va_bits from u8 to u32 Daniel Almeida
2026-11-25 22:46 ` [PATCH 03/13] drm/tyr: convert the lock region exponents " Daniel Almeida
2026-11-25 22:46 ` [PATCH 04/13] drm/tyr: convert EntryHeader to `bitfield!` Daniel Almeida
2026-11-25 22:46 ` [PATCH 05/13] drm/tyr: use SizeConstants for the u32 and u64 size constants Daniel Almeida
2026-11-25 22:46 ` [PATCH 06/13] drm/tyr: replace lossless `as` casts with From and FromSafeCast Daniel Almeida
2026-11-25 22:46 ` Daniel Almeida [this message]
2026-11-25 22:46 ` [PATCH 08/13] drm/tyr: use VmMapFlags::all_bits() to validate map flags Daniel Almeida
2026-11-25 22:47 ` [PATCH 09/13] drm/tyr: justify the casts of enums to their integer value Daniel Almeida
2026-11-25 22:47 ` [PATCH 10/13] drm/tyr: add split_u64() for the 64-bit register values Daniel Almeida
2026-11-25 22:47 ` [PATCH 11/13] drm/tyr: return usize from get_pgsize() Daniel Almeida
2026-11-25 22:47 ` [PATCH 12/13] drm/tyr: justify the physical address cast in pt_map() Daniel Almeida
2026-11-25 22:47 ` [PATCH 13/13] drm/tyr: deny `clippy::as_conversions` Daniel Almeida

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=20261125-b4-tyr-as-casts-v1-7-2b2f53164d86@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --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

all inboxes | Powered by JetHome®