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/gsp.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/gsp.rs')
| -rw-r--r-- | drivers/gpu/nova-core/firmware/gsp.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs index 939e036896bf..72766feae36e 100644 --- a/drivers/gpu/nova-core/firmware/gsp.rs +++ b/drivers/gpu/nova-core/firmware/gsp.rs @@ -24,6 +24,7 @@ use crate::{ Chipset, // }, gsp::GSP_PAGE_SIZE, + num::FromSafeCast, }; /// Ad-hoc and temporary module to extract sections from ELF images. @@ -245,10 +246,11 @@ impl GspFirmware { fn map_into_lvl(sg_table: &SGTable<Owned<VVec<u8>>>, mut dst: VVec<u8>) -> Result<VVec<u8>> { for sg_entry in sg_table.iter() { // Number of pages we need to map. - let num_pages = (sg_entry.dma_len() as usize).div_ceil(GSP_PAGE_SIZE); + let num_pages = usize::from_safe_cast(sg_entry.dma_len()).div_ceil(GSP_PAGE_SIZE); for i in 0..num_pages { - let entry = sg_entry.dma_address() + (i as u64 * GSP_PAGE_SIZE as u64); + let entry = sg_entry.dma_address() + + (u64::from_safe_cast(i) * u64::from_safe_cast(GSP_PAGE_SIZE)); dst.extend_from_slice(&entry.to_le_bytes(), GFP_KERNEL)?; } } |