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 the
lock region exponents in `as_start_update()` from `u8` to `u32`.

`as_start_update()` works out the size of the region to lock as a power
of two. It takes the exponents from `trailing_zeros()` and
`leading_zeros()`, which return `u32`, and narrows them to `u8` with
`as`. The result is then widened back to `u32` for `checked_shl()`.

Keep the exponents as `u32`, which removes the casts.

No functional change intended.

Signed-off-by: Daniel Almeida <[email protected]>
---
 drivers/gpu/drm/tyr/mmu/address_space.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs 
b/drivers/gpu/drm/tyr/mmu/address_space.rs
index a388c0087b20..f6ccb0d7e3ed 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -362,7 +362,7 @@ fn as_start_update(&mut self, as_nr: usize, region: 
&Range<u64>) -> Result {
         // Count the number of trailing zero bits (zeros at the 
right/least-significant
         // end of the binary representation). For a power-of-two value, this 
equals the
         // base-2 exponent (e.g., 32 KiB = 2^15 → 15).
-        let lock_region_min_size_log2 = lock_region_min_size.trailing_zeros() 
as u8;
+        let lock_region_min_size_log2 = lock_region_min_size.trailing_zeros();
 
         // XOR the first and last addresses to identify which bits differ 
between them.
         // The highest set bit in the result determines the exponent of the 
smallest
@@ -373,11 +373,11 @@ fn as_start_update(&mut self, as_nr: usize, region: 
&Range<u64>) -> Result {
         //   highest set bit in 0x3FFF is bit 13
         //   minimum region size = 2^(13 + 1) = 16 KiB
         let addr_xor = region.start ^ (region.end - 1);
-        let region_size_log2 = 64 - addr_xor.leading_zeros() as u8;
+        let region_size_log2 = 64 - addr_xor.leading_zeros();
 
         let lock_region_log2 = core::cmp::max(region_size_log2, 
lock_region_min_size_log2);
 
-        let lock_region_size = 
1u64.checked_shl(lock_region_log2.into()).ok_or(EINVAL)?;
+        let lock_region_size = 
1u64.checked_shl(lock_region_log2).ok_or(EINVAL)?;
         // Align the LOCKADDR base address down to the lock region size (1 << 
lock_region_log2).
         //
         // The MMU ignores the low lock_region_log2 bits of LOCKADDR base, so 
ensure

-- 
2.56.0

Reply via email to