Fix clippy and compiler warings

This commit is contained in:
Jianfeng Jiang
2023-09-04 11:04:42 +08:00
committed by Tate, Hongliang Tian
parent 20a90426a0
commit 9ca64c281e
156 changed files with 539 additions and 603 deletions

View File

@ -39,8 +39,7 @@ impl phy::RxToken for RxToken {
F: FnOnce(&mut [u8]) -> R,
{
let packet_but = self.0.packet_mut();
let res = f(packet_but);
res
f(packet_but)
}
}

View File

@ -91,7 +91,7 @@ pub fn handle_recv_irq(name: &String) {
}
}
pub fn all_devices() -> Vec<(String, Arc<SpinLock<Box<dyn NetworkDevice>>>)> {
pub fn all_devices() -> Vec<(String, NetworkDeviceRef)> {
let lock = COMPONENT.get().unwrap().devices.lock();
let mut vec = Vec::new();
for (name, (_, device)) in lock.iter() {
@ -112,17 +112,12 @@ fn init() -> Result<(), ComponentInitError> {
Ok(())
}
type NetDeviceIrqHandlerListRef = Arc<SpinLock<Vec<Arc<dyn NetDeviceIrqHandler>>>>;
type NetworkDeviceRef = Arc<SpinLock<Box<dyn NetworkDevice>>>;
struct Component {
/// Device list, the key is device name, value is (callbacks, device);
devices: SpinLock<
BTreeMap<
String,
(
Arc<SpinLock<Vec<Arc<dyn NetDeviceIrqHandler>>>>,
Arc<SpinLock<Box<dyn NetworkDevice>>>,
),
>,
>,
devices: SpinLock<BTreeMap<String, (NetDeviceIrqHandlerListRef, NetworkDeviceRef)>>,
}
impl Component {

View File

@ -26,7 +26,7 @@ pub fn is_updating() -> bool {
pub fn read() -> SystemTime {
update_time();
READ_TIME.lock().clone()
*READ_TIME.lock()
}
/// read year,month,day and other data
@ -34,22 +34,21 @@ pub fn read() -> SystemTime {
fn update_time() {
let mut last_time: SystemTime;
let register_b: u8;
let mut lock = READ_TIME.lock();
lock.update_from_rtc();
last_time = lock.clone();
last_time = *lock;
lock.update_from_rtc();
while *lock != last_time {
last_time = lock.clone();
last_time = *lock;
lock.update_from_rtc();
}
register_b = get_cmos(0x0B);
let register_b: u8 = get_cmos(0x0B);
lock.convert_bcd_to_binary(register_b);
lock.convert_12_hour_to_24_hour(register_b);

View File

@ -9,7 +9,7 @@ use pod::Pod;
use crate::transport::VirtioTransport;
pub const BLK_SIZE: usize = 512;
pub static DEVICE_NAME: &'static str = "Virtio-Block";
pub static DEVICE_NAME: &str = "Virtio-Block";
bitflags! {
/// features for virtio block device
@ -112,7 +112,7 @@ pub struct VirtioBlkTopology {
}
impl VirtioBlkConfig {
pub(self) fn new(transport: &mut dyn VirtioTransport) -> SafePtr<Self, IoMem> {
pub(self) fn new(transport: &dyn VirtioTransport) -> SafePtr<Self, IoMem> {
let memory = transport.device_config_memory();
SafePtr::new(memory, 0)
}

View File

@ -63,6 +63,7 @@ pub struct InputDevice {
event_queue: SpinLock<VirtQueue>,
status_queue: VirtQueue,
event_buf: SpinLock<Box<[InputEvent; QUEUE_SIZE as usize]>>,
#[allow(clippy::type_complexity)]
callbacks: SpinLock<Vec<Arc<dyn Fn(DecodeType) + Send + Sync + 'static>>>,
transport: Box<dyn VirtioTransport>,
}
@ -161,7 +162,7 @@ impl InputDevice {
.write(&(select as u8))
.unwrap();
field_ptr!(&self.config, VirtioInputConfig, subsel)
.write(&(subsel as u8))
.write(&subsel)
.unwrap();
let size = field_ptr!(&self.config, VirtioInputConfig, size)
.read()

View File

@ -30,7 +30,7 @@ use jinux_frame::io_mem::IoMem;
use jinux_util::safe_ptr::SafePtr;
use pod::Pod;
pub static DEVICE_NAME: &'static str = "Virtio-Input";
pub static DEVICE_NAME: &str = "Virtio-Input";
/// Select value used for [`VirtIOInput::query_config_select()`].
#[repr(u8)]
@ -72,7 +72,7 @@ pub struct VirtioInputConfig {
}
impl VirtioInputConfig {
pub(self) fn new(transport: &mut dyn VirtioTransport) -> SafePtr<Self, IoMem> {
pub(self) fn new(transport: &dyn VirtioTransport) -> SafePtr<Self, IoMem> {
let memory = transport.device_config_memory();
SafePtr::new(memory, 0)
}

View File

@ -71,7 +71,7 @@ pub struct VirtioNetConfig {
}
impl VirtioNetConfig {
pub(super) fn new(transport: &mut dyn VirtioTransport) -> SafePtr<Self, IoMem> {
pub(super) fn new(transport: &dyn VirtioTransport) -> SafePtr<Self, IoMem> {
let memory = transport.device_config_memory();
SafePtr::new(memory, 0)
}

View File

@ -60,7 +60,7 @@ impl NetworkDevice {
let mut rx_buffers = SlotVec::new();
for i in 0..QUEUE_SIZE {
let mut rx_buffer = RxBuffer::new(RX_BUFFER_LEN, size_of::<VirtioNetHdr>());
let token = recv_queue.add(&[], &mut [rx_buffer.buf_mut()])?;
let token = recv_queue.add(&[], &[rx_buffer.buf_mut()])?;
assert_eq!(i, token);
assert_eq!(rx_buffers.put(rx_buffer) as u16, i);
}
@ -109,7 +109,7 @@ impl NetworkDevice {
fn add_rx_buffer(&mut self, mut rx_buffer: RxBuffer) -> Result<(), VirtioNetError> {
let token = self
.recv_queue
.add(&[], &mut [rx_buffer.buf_mut()])
.add(&[], &[rx_buffer.buf_mut()])
.map_err(queue_to_network_error)?;
assert!(self.rx_buffers.put_at(token as usize, rx_buffer).is_none());
if self.recv_queue.should_notify() {
@ -140,7 +140,7 @@ impl NetworkDevice {
let header = VirtioNetHdr::default();
let token = self
.send_queue
.add(&[header.as_bytes(), tx_buffer.buf()], &mut [])
.add(&[header.as_bytes(), tx_buffer.buf()], &[])
.map_err(queue_to_network_error)?;
if self.send_queue.should_notify() {

View File

@ -2,4 +2,4 @@ pub mod config;
pub mod device;
pub mod header;
pub static DEVICE_NAME: &'static str = "Virtio-Net";
pub static DEVICE_NAME: &str = "Virtio-Net";

View File

@ -67,21 +67,21 @@ impl VirtQueue {
}
let descriptor_ptr: SafePtr<Descriptor, VmFrame> = SafePtr::new(
VmFrameVec::allocate(&VmAllocOptions::new(1).uninit(false).can_dma(true))
VmFrameVec::allocate(VmAllocOptions::new(1).uninit(false).can_dma(true))
.unwrap()
.pop()
.unwrap(),
0,
);
let avail_ring_ptr: SafePtr<AvailRing, VmFrame> = SafePtr::new(
VmFrameVec::allocate(&VmAllocOptions::new(1).uninit(false).can_dma(true))
VmFrameVec::allocate(VmAllocOptions::new(1).uninit(false).can_dma(true))
.unwrap()
.pop()
.unwrap(),
0,
);
let used_ring_ptr: SafePtr<UsedRing, VmFrame> = SafePtr::new(
VmFrameVec::allocate(&VmAllocOptions::new(1).uninit(false).can_dma(true))
VmFrameVec::allocate(VmAllocOptions::new(1).uninit(false).can_dma(true))
.unwrap()
.pop()
.unwrap(),
@ -311,6 +311,7 @@ pub struct Descriptor {
}
#[inline]
#[allow(clippy::type_complexity)]
fn set_buf(ptr: &SafePtr<Descriptor, &VmFrame, TRightSet<TRights![Dup, Write]>>, buf: &[u8]) {
let va = buf.as_ptr() as usize;
let pa = jinux_frame::vm::vaddr_to_paddr(va).unwrap();
@ -323,7 +324,7 @@ fn set_buf(ptr: &SafePtr<Descriptor, &VmFrame, TRightSet<TRights![Dup, Write]>>,
}
bitflags! {
/// Descriptor flags
#[derive(Pod)]
#[derive(Pod, Default)]
#[repr(C)]
struct DescFlags: u16 {
const NEXT = 1;
@ -331,13 +332,6 @@ bitflags! {
const INDIRECT = 4;
}
}
impl Default for DescFlags {
fn default() -> Self {
Self {
bits: Default::default(),
}
}
}
/// The driver uses the available ring to offer buffers to the device:
/// each ring entry refers to the head of a descriptor chain.

View File

@ -7,6 +7,7 @@ use jinux_frame::bus::pci::{
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
#[allow(clippy::enum_variant_names)]
pub enum VirtioPciCpabilityType {
CommonCfg = 1,
NotifyCfg = 2,
@ -72,16 +73,15 @@ impl VirtioPciCapabilityData {
let mut io_bar = None;
let mut memory_bar = None;
match bar_manager.bar(bar) {
Some(bar) => match bar {
if let Some(bar) = bar_manager.bar(bar) {
match bar {
Bar::Memory(memory) => {
memory_bar = Some(memory);
}
Bar::Io(io) => {
io_bar = Some(io);
}
},
None => {}
}
};
Self {
cfg_type,

View File

@ -49,7 +49,7 @@ pub struct VirtioPciTransport {
impl PciDevice for VirtioPciDevice {
fn device_id(&self) -> PciDeviceId {
self.device_id.clone()
self.device_id
}
}
@ -78,13 +78,13 @@ impl VirtioTransport for VirtioPciTransport {
return Err(VirtioTransportError::InvalidArgs);
}
field_ptr!(&self.common_cfg, VirtioPciCommonCfg, queue_select)
.write(&(idx as u16))
.write(&idx)
.unwrap();
debug_assert_eq!(
field_ptr!(&self.common_cfg, VirtioPciCommonCfg, queue_select)
.read()
.unwrap(),
idx as u16
idx
);
field_ptr!(&self.common_cfg, VirtioPciCommonCfg, queue_size)
@ -189,13 +189,13 @@ impl VirtioTransport for VirtioPciTransport {
fn max_queue_size(&self, idx: u16) -> Result<u16, crate::transport::VirtioTransportError> {
field_ptr!(&self.common_cfg, VirtioPciCommonCfg, queue_select)
.write(&(idx as u16))
.write(&idx)
.unwrap();
debug_assert_eq!(
field_ptr!(&self.common_cfg, VirtioPciCommonCfg, queue_select)
.read()
.unwrap(),
idx as u16
idx
);
Ok(field_ptr!(&self.common_cfg, VirtioPciCommonCfg, queue_size)
@ -250,6 +250,7 @@ impl VirtioPciTransport {
&self.device
}
#[allow(clippy::result_large_err)]
pub(super) fn new(
common_device: PciCommonDevice,
) -> Result<Self, (PciDriverProbeError, PciCommonDevice)> {
@ -280,8 +281,7 @@ impl VirtioPciTransport {
for cap in common_device.capabilities().iter() {
match cap.capability_data() {
CapabilityData::Vndr(vendor) => {
let data =
VirtioPciCapabilityData::new(common_device.bar_manager(), vendor.clone());
let data = VirtioPciCapabilityData::new(common_device.bar_manager(), *vendor);
match data.typ() {
VirtioPciCpabilityType::CommonCfg => {
common_cfg = Some(VirtioPciCommonCfg::new(&data));
@ -317,7 +317,7 @@ impl VirtioPciTransport {
let common_cfg = common_cfg.unwrap();
let device_cfg = device_cfg.unwrap();
let msix_manager = VirtioMsixManager::new(msix);
let device_id = common_device.device_id().clone();
let device_id = *common_device.device_id();
Ok(Self {
common_device,
common_cfg,