Skip to content

Commit b5b70ab

Browse files
committed
refactor(virtio-mem): use u64_to_usize instead of try_into+unwrap
It's better to be explicit on the conversion we're doing as u64 to usize is always safe in our platforms. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent c69646d commit b5b70ab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/vmm/src/devices/virtio/mem/device.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ impl VirtioMem {
126126

127127
/// Gets the total hotpluggable size.
128128
pub fn total_size_mib(&self) -> usize {
129-
bytes_to_mib(self.config.region_size.try_into().unwrap())
129+
bytes_to_mib(u64_to_usize(self.config.region_size))
130130
}
131131

132132
/// Gets the block size.
133133
pub fn block_size_mib(&self) -> usize {
134-
bytes_to_mib(self.config.block_size.try_into().unwrap())
134+
bytes_to_mib(u64_to_usize(self.config.block_size))
135135
}
136136

137137
/// Gets the block size.
@@ -141,12 +141,12 @@ impl VirtioMem {
141141

142142
/// Gets the total size of the plugged memory blocks.
143143
pub fn plugged_size_mib(&self) -> usize {
144-
bytes_to_mib(self.config.plugged_size.try_into().unwrap())
144+
bytes_to_mib(u64_to_usize(self.config.plugged_size))
145145
}
146146

147147
/// Gets the requested size
148148
pub fn requested_size_mib(&self) -> usize {
149-
bytes_to_mib(self.config.requested_size.try_into().unwrap())
149+
bytes_to_mib(u64_to_usize(self.config.requested_size))
150150
}
151151

152152
pub fn status(&self) -> VirtioMemStatus {

0 commit comments

Comments
 (0)