mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-07-01 22:50:54 +00:00
dragonball: Remove unnecessary unsafe blocks in cpuid
Rust 1.94 now warns about unnecessary unsafe blocks around __get_cpuid_max(), __cpuid_count(), and host_cpuid() calls. Remove the unsafe blocks as they are no longer needed. This fixes the following clippy warnings in dbs-arch: - warning: unnecessary `unsafe` block at brand_string.rs:106 - warning: unnecessary `unsafe` block at brand_string.rs:114 - warning: unnecessary `unsafe` block at common.rs:28 - warning: unnecessary `unsafe` block at common.rs:36 Signed-off-by: stevenhorsman <steven@uk.ibm.com> Generated-By: IBM Bob
This commit is contained in:
@@ -103,7 +103,7 @@ impl BrandString {
|
||||
/// of the host CPU.
|
||||
fn from_host_cpuid() -> Result<Self, Error> {
|
||||
let mut this = Self::new();
|
||||
let mut cpuid_regs = unsafe { host_cpuid(0x8000_0000) };
|
||||
let mut cpuid_regs = host_cpuid(0x8000_0000);
|
||||
|
||||
if cpuid_regs.eax < 0x8000_0004 {
|
||||
// Brand string not supported by the host CPU
|
||||
@@ -111,7 +111,7 @@ impl BrandString {
|
||||
}
|
||||
|
||||
for leaf in 0x8000_0002..=0x8000_0004 {
|
||||
cpuid_regs = unsafe { host_cpuid(leaf) };
|
||||
cpuid_regs = host_cpuid(leaf);
|
||||
this.set_reg_for_leaf(leaf, Reg::Eax, cpuid_regs.eax);
|
||||
this.set_reg_for_leaf(leaf, Reg::Ebx, cpuid_regs.ebx);
|
||||
this.set_reg_for_leaf(leaf, Reg::Ecx, cpuid_regs.ecx);
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
|
||||
// TODO: replace with validation based on `has_cpuid()` when it becomes stable:
|
||||
// https://doc.rust-lang.org/core/arch/x86/fn.has_cpuid.html
|
||||
// this is safe because the host supports the `cpuid` instruction
|
||||
let max_function = unsafe { __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0 };
|
||||
let max_function = __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0;
|
||||
if function > max_function {
|
||||
return Err(Error::InvalidParameters(format!(
|
||||
"Function not supported: 0x{function:x}",
|
||||
@@ -33,7 +33,7 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
|
||||
}
|
||||
|
||||
// this is safe because the host supports the `cpuid` instruction
|
||||
let entry = unsafe { __cpuid_count(function, count) };
|
||||
let entry = __cpuid_count(function, count);
|
||||
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
|
||||
return Err(Error::InvalidParameters(format!("Invalid count: {count}")));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user