hypervisor: Wrap get_device_attr with unsafe

`get_device_attr` in 0.19.0 kvm-ioctls is marked as unsafe, wrap
invokation of `get_device_attr` with `unsafe` block.

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
Ruoqing He 2024-11-04 15:04:36 +08:00 committed by Rob Bradford
parent 95229b24ab
commit 838a857311
4 changed files with 7 additions and 14 deletions

View File

@ -103,9 +103,8 @@ fn dist_attr_get(gic: &DeviceFd, offset: u32) -> Result<u32> {
flags: 0, flags: 0,
}; };
// get_device_attr should be marked as unsafe, and will be in future.
// SAFETY: gic_dist_attr.addr is safe to write to. // SAFETY: gic_dist_attr.addr is safe to write to.
gic.get_device_attr(&mut gic_dist_attr).map_err(|e| { unsafe { gic.get_device_attr(&mut gic_dist_attr) }.map_err(|e| {
Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into())) Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into()))
})?; })?;
@ -131,9 +130,8 @@ fn get_interrupts_num(gic: &DeviceFd) -> Result<u32> {
addr: &mut num_irq as *mut u32 as u64, addr: &mut num_irq as *mut u32 as u64,
flags: 0, flags: 0,
}; };
// get_device_attr should be marked as unsafe, and will be in future.
// SAFETY: nr_irqs_attr.addr is safe to write to. // SAFETY: nr_irqs_attr.addr is safe to write to.
gic.get_device_attr(&mut nr_irqs_attr).map_err(|e| { unsafe { gic.get_device_attr(&mut nr_irqs_attr) }.map_err(|e| {
Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into())) Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into()))
})?; })?;
Ok(num_irq) Ok(num_irq)

View File

@ -105,9 +105,8 @@ fn icc_attr_get(gic: &DeviceFd, offset: u64, typer: u64) -> Result<u32> {
flags: 0, flags: 0,
}; };
// get_device_attr should be marked as unsafe, and will be in future.
// SAFETY: gic_icc_attr.addr is safe to write to. // SAFETY: gic_icc_attr.addr is safe to write to.
gic.get_device_attr(&mut gic_icc_attr).map_err(|e| { unsafe { gic.get_device_attr(&mut gic_icc_attr) }.map_err(|e| {
Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into())) Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into()))
})?; })?;

View File

@ -49,13 +49,10 @@ fn gicv3_its_attr_get(its_device: &DeviceFd, group: u32, attr: u32) -> Result<u6
flags: 0, flags: 0,
}; };
// get_device_attr should be marked as unsafe, and will be in future.
// SAFETY: gicv3_its_attr.addr is safe to write to. // SAFETY: gicv3_its_attr.addr is safe to write to.
its_device unsafe { its_device.get_device_attr(&mut gicv3_its_attr) }.map_err(|e| {
.get_device_attr(&mut gicv3_its_attr) Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into()))
.map_err(|e| { })?;
Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into()))
})?;
Ok(val) Ok(val)
} }

View File

@ -121,9 +121,8 @@ fn redist_attr_get(gic: &DeviceFd, offset: u32, typer: u64) -> Result<u32> {
flags: 0, flags: 0,
}; };
// get_device_attr should be marked as unsafe, and will be in future.
// SAFETY: gic_redist_attr.addr is safe to write to. // SAFETY: gic_redist_attr.addr is safe to write to.
gic.get_device_attr(&mut gic_redist_attr).map_err(|e| { unsafe { gic.get_device_attr(&mut gic_redist_attr) }.map_err(|e| {
Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into())) Error::GetDeviceAttribute(HypervisorDeviceError::GetDeviceAttribute(e.into()))
})?; })?;