diff options
| author | Alexandre Courbot <acourbot@nvidia.com> | 2025-10-27 23:12:31 +0900 |
|---|---|---|
| committer | Alexandre Courbot <acourbot@nvidia.com> | 2025-11-08 08:22:45 +0900 |
| commit | 84e2b401bcc551e7c2e1a995f90cce421bce5bfd (patch) | |
| tree | 22c198ec547b70bb4dce9ade00601d5eb0a8eb84 /drivers/gpu/nova-core/firmware.rs | |
| parent | 5525ac03ca7adec61d39f3fd3a143b5e294bdff7 (diff) | |
gpu: nova-core: replace use of `as` with functions from `num`
Use the newly-introduced `num` module to replace the use of `as`
wherever it is safe to do. This ensures that a given conversion cannot
lose data if its source or destination type ever changes.
Acked-by: Danilo Krummrich <dakr@kernel.org>
[acourbot@nvidia.com: fix merge conflicts after rebase.]
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251029-nova-as-v3-5-6a30c7333ad9@nvidia.com>
Diffstat (limited to 'drivers/gpu/nova-core/firmware.rs')
| -rw-r--r-- | drivers/gpu/nova-core/firmware.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs index 163b746f03ef..2d2008b33fb4 100644 --- a/drivers/gpu/nova-core/firmware.rs +++ b/drivers/gpu/nova-core/firmware.rs @@ -16,7 +16,11 @@ use kernel::{ use crate::{ dma::DmaObject, falcon::FalconFirmware, - gpu, // + gpu, + num::{ + FromSafeCast, + IntoSafeCast, // + }, }; pub(crate) mod booter; @@ -78,7 +82,7 @@ impl FalconUCodeDescV3 { const HDR_SIZE_SHIFT: u32 = 16; const HDR_SIZE_MASK: u32 = 0xffff0000; - ((self.hdr & HDR_SIZE_MASK) >> HDR_SIZE_SHIFT) as usize + ((self.hdr & HDR_SIZE_MASK) >> HDR_SIZE_SHIFT).into_safe_cast() } } @@ -193,8 +197,8 @@ impl<'a> BinFirmware<'a> { /// Returns the data payload of the firmware, or `None` if the data range is out of bounds of /// the firmware image. fn data(&self) -> Option<&[u8]> { - let fw_start = self.hdr.data_offset as usize; - let fw_size = self.hdr.data_size as usize; + let fw_start = usize::from_safe_cast(self.hdr.data_offset); + let fw_size = usize::from_safe_cast(self.hdr.data_size); self.fw.get(fw_start..fw_start + fw_size) } |