Skip to content
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
36 changes: 36 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,39 @@ members = [
"vhost-device-vsock",
"xtask",
]

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "deny"

[workspace.lints.rustdoc]
broken_intra_doc_links = "deny"
redundant_explicit_links = "deny"

[workspace.lints.clippy]
enum_glob_use = "deny"
# groups
correctness = { level = "deny", priority = -1 }
suspicious = { level = "deny", priority = -1 }
complexity = { level = "deny", priority = -1 }
perf = { level = "deny", priority = -1 }
style = { level = "deny", priority = -1 }
#nursery = { level = "deny", priority = -1 }
# restriction
dbg_macro = "deny"
rc_buffer = "deny"
as_underscore = "deny"
assertions_on_result_states = "deny"
# pedantic
cast_lossless = "deny"
cast_possible_wrap = "deny"
cast_ptr_alignment = "deny"
naive_bytecount = "deny"
ptr_as_ptr = "deny"
bool_to_int_with_if = "deny"
borrow_as_ptr = "deny"
case_sensitive_file_extension_comparisons = "deny"
significant_drop_in_scrutinee = "allow"
significant_drop_tightening = "allow"
missing_safety_doc = "deny"
undocumented_unsafe_blocks = "deny"
option_if_let_else = "allow"
4 changes: 2 additions & 2 deletions vhost-device-can/src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl CanController {

pub fn read_can_socket(controller: Arc<RwLock<CanController>>) -> Result<()> {
let can_name = &controller.read().unwrap().can_name.clone();
dbg!("Start reading from {} socket!", &can_name);
log::debug!("Start reading from {can_name} socket!");
let socket = match CanFdSocket::open(can_name) {
Ok(socket) => socket,
Err(_) => {
Expand All @@ -182,7 +182,7 @@ impl CanController {
loop {
// If the status variable is false then break and exit.
if !controller.read().unwrap().status {
dbg!("exit read can thread");
log::debug!("exit read can thread");
return Ok(());
}

Expand Down
3 changes: 2 additions & 1 deletion vhost-device-can/src/vhu_can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ impl VhostUserBackendMut for VhostUserCanBackend {
.config()
.as_slice()
.as_ptr()
.offset(offset as isize) as *const _ as *const _,
.offset(offset as isize)
.cast::<u8>(),
size as usize,
)
.to_vec()
Expand Down
3 changes: 3 additions & 0 deletions vhost-device-console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ vmm-sys-util = "0.14"
assert_matches = "1.5"
virtio-queue = { version = "0.16", features = ["test-utils"] }
vm-memory = { version = "0.16.1", features = ["backend-mmap", "backend-atomic"] }

[lints]
workspace = true
5 changes: 3 additions & 2 deletions vhost-device-gpio/src/vhu_gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ impl<D: 'static + GpioDevice + Sync + Send> VhostUserBackendMut for VhostUserGpi
.config()
.as_slice()
.as_ptr()
.offset(offset as isize) as *const _ as *const _,
.offset(offset as isize)
.cast::<u8>(),
size as usize,
)
.to_vec()
Expand Down Expand Up @@ -1157,7 +1158,7 @@ mod tests {
// reading its content from byte array.
unsafe {
from_raw_parts(
&config as *const _ as *const _,
(&raw const config).cast::<u8>(),
size_of::<VirtioGpioConfig>(),
)
.to_vec()
Expand Down
3 changes: 3 additions & 0 deletions vhost-device-i2c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ vmm-sys-util = "0.14"
assert_matches = "1.5"
virtio-queue = { version = "0.16", features = ["test-utils"] }
vm-memory = { version = "0.16.1", features = ["backend-mmap", "backend-atomic"] }

[lints]
workspace = true
3 changes: 2 additions & 1 deletion vhost-device-i2c/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ impl SmbusMsg {
// Special Read requests, reqs[0].len can be 0 or 1 only.
Err(Error::MessageLengthInvalid("read", 3))
} else {
data.word = reqs[0].buf[1] as u16 | ((reqs[0].buf[2] as u16) << 8);
data.word =
u16::from(reqs[0].buf[1]) | (u16::from(reqs[0].buf[2]) << 8);
Ok(SmbusMsg {
read_write,
command: reqs[0].buf[0],
Expand Down
6 changes: 3 additions & 3 deletions vhost-device-i2c/src/vhu_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<D: 'static + I2cDevice + Sync + Send> VhostUserBackendMut for VhostUserI2cB
}

fn set_event_idx(&mut self, enabled: bool) {
dbg!(self.event_idx = enabled);
self.event_idx = enabled;
}

fn update_memory(&mut self, mem: GuestMemoryAtomic<GuestMemoryMmap>) -> IoResult<()> {
Expand Down Expand Up @@ -407,7 +407,7 @@ mod tests {
vq.desc_table()
.store(index, RawDescriptor::from(desc_out))
.unwrap();
next_addr += desc_out.len() as u64;
next_addr += u64::from(desc_out.len());
index += 1;

// Buf descriptor: optional
Expand All @@ -430,7 +430,7 @@ mod tests {
vq.desc_table()
.store(index, RawDescriptor::from(desc_buf))
.unwrap();
next_addr += desc_buf.len() as u64;
next_addr += u64::from(desc_buf.len());
index += 1;
}

Expand Down
3 changes: 3 additions & 0 deletions vhost-device-input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ nix = { version = "0.30", features = ["ioctl"] }
assert_matches = "1.5"
virtio-queue = { version = "0.16", features = ["test-utils"] }
vm-memory = { version = "0.16", features = ["backend-mmap", "backend-atomic"] }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion vhost-device-input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! ioctl_read_buf {
for item in data.iter_mut() {
*item = $nr as u8;
}
Ok(data.len() as i32)
Ok(data.len().try_into().unwrap())
}
)
}
Expand Down
22 changes: 12 additions & 10 deletions vhost-device-input/src/vhu_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ impl<T: InputDevice> VuInputBackend<T> {
let last_sync_index = self
.ev_list
.iter()
.rposition(|event| event.ev_type == EV_SYN as u16 && event.code == SYN_REPORT as u16)
.rposition(|event| {
event.ev_type == u16::from(EV_SYN) && event.code == u16::from(SYN_REPORT)
})
.unwrap_or(0);

if last_sync_index == 0 {
Expand Down Expand Up @@ -609,15 +611,15 @@ mod tests {
.unwrap();

let ev_raw_data = VuInputEvent {
ev_type: EV_KEY as u16,
code: SYN_REPORT as u16,
ev_type: u16::from(EV_KEY),
code: u16::from(SYN_REPORT),
value: 0,
};
backend.ev_list.push_back(ev_raw_data);

let ev_raw_data = VuInputEvent {
ev_type: EV_SYN as u16,
code: SYN_REPORT as u16,
ev_type: u16::from(EV_SYN),
code: u16::from(SYN_REPORT),
value: 0,
};
backend.ev_list.push_back(ev_raw_data);
Expand All @@ -630,15 +632,15 @@ mod tests {
assert_eq!(backend.ev_list.len(), 0);

let ev_raw_data = VuInputEvent {
ev_type: EV_KEY as u16,
code: SYN_REPORT as u16,
ev_type: u16::from(EV_KEY),
code: u16::from(SYN_REPORT),
value: 0,
};
backend.ev_list.push_back(ev_raw_data);

let ev_raw_data = VuInputEvent {
ev_type: EV_SYN as u16,
code: SYN_REPORT as u16,
ev_type: u16::from(EV_SYN),
code: u16::from(SYN_REPORT),
value: 0,
};
backend.ev_list.push_back(ev_raw_data);
Expand Down Expand Up @@ -854,7 +856,7 @@ mod tests {

assert_eq!(backend.queues_per_thread(), vec![0xffff_ffff]);
assert_eq!(backend.get_config(0, 0), vec![]);
assert!(backend.update_memory(mem.clone()).is_ok());
backend.update_memory(mem.clone()).unwrap();

backend.set_event_idx(true);
assert!(backend.event_idx);
Expand Down
3 changes: 3 additions & 0 deletions vhost-device-rng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ vmm-sys-util = "0.14"
assert_matches = "1.5"
virtio-queue = { version = "0.16", features = ["test-utils"] }
vm-memory = { version = "0.16", features = ["backend-mmap", "backend-atomic"] }

[lints]
workspace = true
6 changes: 3 additions & 3 deletions vhost-device-rng/src/vhu_rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<T: 'static + ReadVolatile + Sync + Send> VhostUserBackendMut for VuRngBacke
}

fn set_event_idx(&mut self, enabled: bool) {
dbg!(self.event_idx = enabled);
self.event_idx = enabled;
}

fn update_memory(
Expand Down Expand Up @@ -369,7 +369,7 @@ mod tests {
};

let desc = RawDescriptor::from(SplitDescriptor::new(
(0x100 * (i + 1)) as u64,
u64::from(0x100 * (i + 1)),
0x200,
desc_flags,
i + 1,
Expand Down Expand Up @@ -579,7 +579,7 @@ mod tests {

assert_eq!(backend.queues_per_thread(), vec![0xffff_ffff]);
assert_eq!(backend.get_config(0, 0), vec![]);
assert!(backend.update_memory(mem).is_ok());
backend.update_memory(mem).unwrap();

backend.set_event_idx(true);
assert!(backend.event_idx);
Expand Down
5 changes: 4 additions & 1 deletion vhost-device-scmi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ vmm-sys-util = "0.14"

[dev-dependencies]
assert_matches = "1.5"
virtio-queue = { version = "0.16", features = ["test-utils"] }
virtio-queue = { version = "0.16", features = ["test-utils"] }

[lints]
workspace = true
8 changes: 4 additions & 4 deletions vhost-device-scmi/src/devices/iio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl SensorT for IIOSensor {
return Err(ScmiDeviceError::GenericError);
}

let sample_byte = (scan_type.realbits as f64 / 8_f64).ceil() as usize;
let sample_byte = (f64::from(scan_type.realbits) / 8_f64).ceil() as usize;
let sample_buffer_len = sample_byte * self.axes.len();
let mut buffer = vec![0u8; sample_buffer_len];
let mut file = self.sensor().notify_dev.as_ref().unwrap();
Expand All @@ -467,7 +467,7 @@ impl SensorT for IIOSensor {
let value =
i16::from_le_bytes(buffer[i * 2..i * 2 + 2].try_into().unwrap());
let value_i64 = self
.deal_axis_raw_data(value as i64, &self.axes[i])
.deal_axis_raw_data(i64::from(value), &self.axes[i])
.unwrap();
let sensor_value_low = (value_i64 & 0xffff_ffff) as i32;
let sensor_value_high = (value_i64 >> 32) as i32;
Expand Down Expand Up @@ -607,10 +607,10 @@ impl IIOSensor {
custom_exponent -= 1;
// Calculate the resolution of scale
custom_resolution =
(scale * 10i32.pow(-custom_exponent as u32) as f64).trunc() as u64;
(scale * f64::from(10i32.pow(-custom_exponent as u32))).trunc() as u64;
} else {
custom_resolution =
(scale / 10i32.pow(custom_exponent as u32) as f64).trunc() as u64;
(scale / f64::from(10i32.pow(custom_exponent as u32))).trunc() as u64;
}
// The SCMI exponent (unit_exponent + custom_exponent) can have max. 5 bits:
custom_exponent = min(15 - unit_exponent, custom_exponent);
Expand Down
10 changes: 5 additions & 5 deletions vhost-device-scmi/src/scmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ impl ScmiHandler {
// message_type = 0x3 [9:8]
// protocol_id=0x15; [17:10]
// 0x1 | (0x3<<8) | (0x15<<10)
let notify_header: MessageHeader = (SENSOR_UPDATE as u32)
let notify_header: MessageHeader = u32::from(SENSOR_UPDATE)
| ((MessageType::Notification as u32) << 8)
| ((SENSOR_PROTOCOL_ID as u32) << 10);
| (u32::from(SENSOR_PROTOCOL_ID) << 10);

Some(ScmiResponse::from(
notify_header,
Expand Down Expand Up @@ -1564,12 +1564,12 @@ mod tests {
for iteration in 0..2 {
for sensor_id in 0..2 {
let notification = handler.notify(NOTIFY_ALLOW_START_FD + sensor_id).unwrap();
let notify_header: MessageHeader = (SENSOR_UPDATE as u32)
let notify_header: MessageHeader = u32::from(SENSOR_UPDATE)
| ((MessageType::Notification as u32) << 8)
| ((SENSOR_PROTOCOL_ID as u32) << 10);
| (u32::from(SENSOR_PROTOCOL_ID) << 10);
let mut result = vec![];
result.push(MessageValue::Unsigned(0));
result.push(MessageValue::Unsigned(sensor_id as u32));
result.push(MessageValue::Unsigned(u32::from(sensor_id)));
for i in 0..3 {
result.push(MessageValue::Signed(iteration + 100 * i));
result.push(MessageValue::Signed(0));
Expand Down
2 changes: 1 addition & 1 deletion vhost-device-scmi/src/vhu_scmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl VuScmiBackend {
let eventfd_list = self.scmi_handler.get_device_eventfd_list();
for (device_notify_fd, device_event) in eventfd_list {
handlers[0]
.register_listener(device_notify_fd, EventSet::IN, device_event as u64)
.register_listener(device_notify_fd, EventSet::IN, u64::from(device_event))
.unwrap();
}
}
Expand Down
3 changes: 3 additions & 0 deletions vhost-device-scsi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ vmm-sys-util = "0.14"
assert_matches = "1.5"
tempfile = "3.20.0"
virtio-queue = { version = "0.16", features = ["test-utils"] }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion vhost-device-scsi/src/vhu_scsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl VhostUserBackendMut for VhostUserScsiBackend {
// access up to the size of the struct.
let config_slice = unsafe {
slice::from_raw_parts(
&config as *const virtio_scsi_config as *const u8,
(&raw const config).cast::<u8>(),
mem::size_of::<virtio_scsi_config>(),
)
};
Expand Down
3 changes: 3 additions & 0 deletions vhost-device-sound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ vm-memory = { version = "0.16.1", features = ["backend-mmap", "backend-atomic"]
[target.'cfg(target_env = "gnu")'.dev-dependencies]
rand = { version = "0.9.2" }
rusty-fork = { version = "0.3.0" }

[lints]
workspace = true
13 changes: 6 additions & 7 deletions vhost-device-sound/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,20 @@ impl PCMState {

impl std::fmt::Display for PCMState {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
use PCMState::*;
match *self {
SetParameters => {
match self {
Self::SetParameters => {
write!(fmt, "VIRTIO_SND_R_PCM_SET_PARAMS")
}
Prepare => {
Self::Prepare => {
write!(fmt, "VIRTIO_SND_R_PCM_PREPARE")
}
Release => {
Self::Release => {
write!(fmt, "VIRTIO_SND_R_PCM_RELEASE")
}
Start => {
Self::Start => {
write!(fmt, "VIRTIO_SND_R_PCM_START")
}
Stop => {
Self::Stop => {
write!(fmt, "VIRTIO_SND_R_PCM_STOP")
}
}
Expand Down
3 changes: 3 additions & 0 deletions vhost-device-spi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ bitflags = "2.9.1"
assert_matches = "1.5"
virtio-queue = { version = "0.16", features = ["test-utils"] }
vm-memory = { version = "0.16.1", features = ["backend-mmap", "backend-atomic"] }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion vhost-device-spi/src/linux_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn spi_ioc_message(n: u32) -> u64 {
if n * 32 < (1 << _IOC_SIZEBITS) {
size = n * 32;
}
(SPI_IOC_MESSAGE_BASE | (size << _IOC_SIZESHIFT)) as u64
u64::from(SPI_IOC_MESSAGE_BASE | (size << _IOC_SIZESHIFT))
}

bitflags! {
Expand Down
Loading