build: Fix beta clippy issue (unnecessary_cast)

warning: casting raw pointers to the same type and constness is unnecessary (`*const protocol::MemoryRange` -> `*const protocol::MemoryRange`)
   --> vm-migration/src/protocol.rs:280:17
    |
280 |                 self.data.as_ptr() as *const MemoryRange as *const u8,
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.data.as_ptr()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
    = note: `#[warn(clippy::unnecessary_cast)]` on by default

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
This commit is contained in:
Yu Li 2023-07-12 12:02:38 +08:00 committed by Bo Chen
parent 9abf8d6868
commit aac614e2ec
4 changed files with 11 additions and 14 deletions

View File

@ -73,7 +73,7 @@ impl AsyncIo for RawFileSync {
let result = unsafe { let result = unsafe {
libc::preadv( libc::preadv(
self.fd as libc::c_int, self.fd as libc::c_int,
iovecs.as_ptr() as *const libc::iovec, iovecs.as_ptr(),
iovecs.len() as libc::c_int, iovecs.len() as libc::c_int,
offset, offset,
) )
@ -98,7 +98,7 @@ impl AsyncIo for RawFileSync {
let result = unsafe { let result = unsafe {
libc::pwritev( libc::pwritev(
self.fd as libc::c_int, self.fd as libc::c_int,
iovecs.as_ptr() as *const libc::iovec, iovecs.as_ptr(),
iovecs.len() as libc::c_int, iovecs.len() as libc::c_int,
offset, offset,
) )

View File

@ -87,7 +87,7 @@ impl TxVirtio {
let result = unsafe { let result = unsafe {
libc::writev( libc::writev(
tap.as_raw_fd() as libc::c_int, tap.as_raw_fd() as libc::c_int,
iovecs.as_ptr() as *const libc::iovec, iovecs.as_ptr(),
iovecs.len() as libc::c_int, iovecs.len() as libc::c_int,
) )
}; };
@ -226,7 +226,7 @@ impl RxVirtio {
let result = unsafe { let result = unsafe {
libc::readv( libc::readv(
tap.as_raw_fd() as libc::c_int, tap.as_raw_fd() as libc::c_int,
iovecs.as_ptr() as *const libc::iovec, iovecs.as_ptr(),
iovecs.len() as libc::c_int, iovecs.len() as libc::c_int,
) )
}; };

View File

@ -136,7 +136,7 @@ impl VsockPacket {
.translate_gva(access_platform, head.len() as usize), .translate_gva(access_platform, head.len() as usize),
VSOCK_PKT_HDR_SIZE, VSOCK_PKT_HDR_SIZE,
) )
.ok_or(VsockError::GuestMemory)? as *mut u8, .ok_or(VsockError::GuestMemory)?,
buf: None, buf: None,
buf_size: 0, buf_size: 0,
}; };
@ -175,7 +175,7 @@ impl VsockPacket {
.translate_gva(access_platform, buf_desc.len() as usize), .translate_gva(access_platform, buf_desc.len() as usize),
pkt.buf_size, pkt.buf_size,
) )
.ok_or(VsockError::GuestMemory)? as *mut u8, .ok_or(VsockError::GuestMemory)?,
); );
Ok(pkt) Ok(pkt)
@ -221,7 +221,7 @@ impl VsockPacket {
.translate_gva(access_platform, head.len() as usize), .translate_gva(access_platform, head.len() as usize),
VSOCK_PKT_HDR_SIZE, VSOCK_PKT_HDR_SIZE,
) )
.ok_or(VsockError::GuestMemory)? as *mut u8, .ok_or(VsockError::GuestMemory)?,
buf: Some( buf: Some(
get_host_address_range( get_host_address_range(
desc_chain.memory(), desc_chain.memory(),
@ -230,7 +230,7 @@ impl VsockPacket {
.translate_gva(access_platform, buf_desc.len() as usize), .translate_gva(access_platform, buf_desc.len() as usize),
buf_size, buf_size,
) )
.ok_or(VsockError::GuestMemory)? as *mut u8, .ok_or(VsockError::GuestMemory)?,
), ),
buf_size, buf_size,
}) })
@ -428,8 +428,8 @@ mod tests {
fn set_pkt_len(len: u32, guest_desc: &GuestQDesc, mem: &GuestMemoryMmap) { fn set_pkt_len(len: u32, guest_desc: &GuestQDesc, mem: &GuestMemoryMmap) {
let hdr_gpa = guest_desc.addr.get(); let hdr_gpa = guest_desc.addr.get();
let hdr_ptr = get_host_address_range(mem, GuestAddress(hdr_gpa), VSOCK_PKT_HDR_SIZE) let hdr_ptr =
.unwrap() as *mut u8; get_host_address_range(mem, GuestAddress(hdr_gpa), VSOCK_PKT_HDR_SIZE).unwrap();
let len_ptr = unsafe { hdr_ptr.add(HDROFF_LEN) }; let len_ptr = unsafe { hdr_ptr.add(HDROFF_LEN) };
LittleEndian::write_u32(unsafe { std::slice::from_raw_parts_mut(len_ptr, 4) }, len); LittleEndian::write_u32(unsafe { std::slice::from_raw_parts_mut(len_ptr, 4) }, len);

View File

@ -276,10 +276,7 @@ impl MemoryRangeTable {
pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> { pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> {
// SAFETY: the slice is construted with the correct arguments // SAFETY: the slice is construted with the correct arguments
fd.write_all(unsafe { fd.write_all(unsafe {
std::slice::from_raw_parts( std::slice::from_raw_parts(self.data.as_ptr() as *const u8, self.length() as usize)
self.data.as_ptr() as *const MemoryRange as *const u8,
self.length() as usize,
)
}) })
.map_err(MigratableError::MigrateSocket) .map_err(MigratableError::MigrateSocket)
} }