Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy erros and warnings #23

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/vhost_kern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ pub trait VhostKernBackend: AsRawFd {
.checked_add(desc_table_size)
.map_or(true, |v| !m.address_in_range(v))
{
false
} else if GuestAddress(config_data.avail_ring_addr)
return false;
}
if GuestAddress(config_data.avail_ring_addr)
.checked_add(avail_ring_size)
.map_or(true, |v| !m.address_in_range(v))
{
false
} else if GuestAddress(config_data.used_ring_addr)
return false;
}
if GuestAddress(config_data.used_ring_addr)
.checked_add(used_ring_size)
.map_or(true, |v| !m.address_in_range(v))
{
false
} else {
config_data.is_log_addr_valid()
return false;
}

config_data.is_log_addr_valid()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/vhost_kern/vhost_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(missing_docs)]
#![allow(clippy::missing_safety_doc)]

use crate::{Error, Result};
use std::os::raw;
Expand Down
1 change: 0 additions & 1 deletion src/vhost_kern/vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::fs::{File, OpenOptions};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, RawFd};

use libc;
use vm_memory::GuestAddressSpace;
use vmm_sys_util::ioctl::ioctl_with_ref;

Expand Down
10 changes: 3 additions & 7 deletions src/vhost_user/dummy_slave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
}

fn set_features(&mut self, features: u64) -> Result<()> {
if !self.owned {
return Err(Error::InvalidOperation);
} else if self.features_acked {
if !self.owned || self.features_acked {
return Err(Error::InvalidOperation);
} else if (features & !VIRTIO_FEATURES) != 0 {
return Err(Error::InvalidParam);
Expand Down Expand Up @@ -224,8 +222,7 @@ impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
) -> Result<Vec<u8>> {
if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIG.bits() == 0 {
return Err(Error::InvalidOperation);
} else if offset < VHOST_USER_CONFIG_OFFSET
|| offset >= VHOST_USER_CONFIG_SIZE
} else if !(VHOST_USER_CONFIG_OFFSET..VHOST_USER_CONFIG_SIZE).contains(&offset)
|| size > VHOST_USER_CONFIG_SIZE - VHOST_USER_CONFIG_OFFSET
|| size + offset > VHOST_USER_CONFIG_SIZE
{
Expand All @@ -238,8 +235,7 @@ impl VhostUserSlaveReqHandlerMut for DummySlaveReqHandler {
let size = buf.len() as u32;
if self.acked_protocol_features & VhostUserProtocolFeatures::CONFIG.bits() == 0 {
return Err(Error::InvalidOperation);
} else if offset < VHOST_USER_CONFIG_OFFSET
|| offset >= VHOST_USER_CONFIG_SIZE
} else if !(VHOST_USER_CONFIG_OFFSET..VHOST_USER_CONFIG_SIZE).contains(&offset)
|| size > VHOST_USER_CONFIG_SIZE - VHOST_USER_CONFIG_OFFSET
|| size + offset > VHOST_USER_CONFIG_SIZE
{
Expand Down
7 changes: 4 additions & 3 deletions src/vhost_user/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ impl VhostUserMaster for Master {
return error_code(VhostUserError::InvalidMessage);
} else if body_reply.size == 0 {
return error_code(VhostUserError::SlaveInternalError);
} else if body_reply.size != body.size || body_reply.size as usize != buf.len() {
return error_code(VhostUserError::InvalidMessage);
} else if body_reply.offset != body.offset {
} else if body_reply.size != body.size
|| body_reply.size as usize != buf.len()
|| body_reply.offset != body.offset
{
return error_code(VhostUserError::InvalidMessage);
}

Expand Down
3 changes: 1 addition & 2 deletions src/vhost_user/master_req_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (C) 2019-2021 Alibaba Cloud. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

use libc;
use std::mem;
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net::UnixStream;
Expand Down Expand Up @@ -310,7 +309,7 @@ impl<S: VhostUserMasterReqHandler> MasterReqHandler<S> {
_ => {
if rfds.is_some() {
Endpoint::<SlaveReq>::close_rfds(rfds);
return Err(Error::InvalidMessage);
Err(Error::InvalidMessage)
} else {
Ok(rfds)
}
Expand Down
2 changes: 1 addition & 1 deletion src/vhost_user/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ mod tests {
msg.guest_phys_addr = 0xFFFFFFFFFFFF0000;
msg.memory_size = 0;
assert!(!msg.is_valid());
let a = msg.clone().guest_phys_addr;
let a = msg.guest_phys_addr;
let b = msg.guest_phys_addr;
assert_eq!(a, b);

Expand Down
2 changes: 1 addition & 1 deletion src/vhost_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ mod tests {

#[test]
fn test_error_from_sys_util_error() {
let e: Error = vmm_sys_util::errno::Error::new(libc::EAGAIN.into()).into();
let e: Error = vmm_sys_util::errno::Error::new(libc::EAGAIN).into();
if let Error::SocketRetry(e1) = e {
assert_eq!(e1.raw_os_error().unwrap(), libc::EAGAIN);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/vhost_user/slave_fs_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl SlaveFsCacheReq {
) -> io::Result<u64> {
self.node()
.send_message(request, fs, fds)
.or_else(|e| Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))))
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e)))
}

/// Create a new instance from a `UnixStream` object.
Expand Down
5 changes: 1 addition & 4 deletions src/vhost_user/slave_req_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,7 @@ impl<S: VhostUserSlaveReqHandler> SlaveReqHandler<S> {
// invalid FD flag. This flag is set when there is no file descriptor
// in the ancillary data. This signals that polling will be used
// instead of waiting for the call.
let nofd = match msg.value & 0x100u64 {
0x100u64 => true,
_ => false,
};
let nofd = (msg.value & 0x100u64) == 0x100u64;

let mut rfd = None;
match rfds {
Expand Down