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>
(cherry picked from commit aac614e2ec42c05862a4def078de7be8c2e9688d)
This commit is contained in:
Yu Li 2023-07-12 12:02:38 +08:00 committed by Bo Chen
parent e0b863ecfe
commit 496d4c204b
4 changed files with 11 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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