Skip to content

Commit c41d1ad

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 79020a2 commit c41d1ad

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
@@ -125,12 +125,12 @@ impl VirtioMem {
125125

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

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

136136
/// Gets the block size.
@@ -140,12 +140,12 @@ impl VirtioMem {
140140

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

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

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

0 commit comments

Comments
 (0)