diff --git a/vhost-device-scmi/Cargo.toml b/vhost-device-scmi/Cargo.toml index c3f7cda..83de800 100644 --- a/vhost-device-scmi/Cargo.toml +++ b/vhost-device-scmi/Cargo.toml @@ -24,4 +24,7 @@ vmm-sys-util = "0.14" [dev-dependencies] assert_matches = "1.5" -virtio-queue = { version = "0.16", features = ["test-utils"] } \ No newline at end of file +virtio-queue = { version = "0.16", features = ["test-utils"] } + +[lints] +workspace = true diff --git a/vhost-device-scmi/src/devices/iio.rs b/vhost-device-scmi/src/devices/iio.rs index 82e7880..0c997fa 100644 --- a/vhost-device-scmi/src/devices/iio.rs +++ b/vhost-device-scmi/src/devices/iio.rs @@ -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(); @@ -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; @@ -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); diff --git a/vhost-device-scmi/src/scmi.rs b/vhost-device-scmi/src/scmi.rs index 3c9a8be..da30463 100644 --- a/vhost-device-scmi/src/scmi.rs +++ b/vhost-device-scmi/src/scmi.rs @@ -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, @@ -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)); diff --git a/vhost-device-scmi/src/vhu_scmi.rs b/vhost-device-scmi/src/vhu_scmi.rs index 507eeaa..73bf1ae 100644 --- a/vhost-device-scmi/src/vhu_scmi.rs +++ b/vhost-device-scmi/src/vhu_scmi.rs @@ -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(); } }