[PATCH 07/13] drm/tyr: use `cv!` for constant conversions
From: Daniel Almeida
Date: Wed Nov 25 2026 - 17:48:33 EST
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@xxxxxxxxxxxxx>
---
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(®_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