[windows_kext] Fix some clippy warnings

This commit is contained in:
Vladimir Stoilov 2024-06-28 16:12:07 +03:00
parent 81bee82b8f
commit ea59c11d0d
8 changed files with 18 additions and 26 deletions

View file

@ -43,8 +43,8 @@ unsafe impl GlobalAlloc for WindowsAllocator {
}
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let pool = self.alloc(layout);
pool
self.alloc(layout)
}
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {

View file

@ -37,9 +37,7 @@ impl ClassifyDefer {
}
ClassifyDefer::Reauthorization(_callout_id, packet_list) => {
// There is no way to reset single filter. If another request for filter reset is trigger at the same time it will fail.
if let Err(err) = filter_engine.reset_all_filters() {
return Err(err);
}
filter_engine.reset_all_filters()?;
return Ok(packet_list);
}
}

View file

@ -113,9 +113,7 @@ pub(crate) fn register_callout(
check_ntstatus(status)?;
if let Err(err) = callout_add(filter_engine_handle, guid, layer, name, description) {
return Err(err);
}
callout_add(filter_engine_handle, guid, layer, name, description)?;
return Ok(callout_id);
}

View file

@ -154,10 +154,10 @@ impl FwpsIncomingMetadataValues {
#[allow(dead_code)]
#[repr(C)]
enum FwpsDiscardModule0 {
FwpsDiscardModuleNetwork = 0,
FwpsDiscardModuleTransport = 1,
FwpsDiscardModuleGeneral = 2,
FwpsDiscardModuleMax = 3,
Network = 0,
Transport = 1,
General = 2,
Max = 3,
}
#[repr(C)]

View file

@ -107,9 +107,7 @@ impl FilterEngine {
filter_engine.callouts = Some(boxed_callouts);
}
if let Err(err) = filter_engine.commit() {
return Err(err);
}
filter_engine.commit()?
}
self.committed = true;
info!("transaction committed");
@ -147,9 +145,7 @@ impl FilterEngine {
}
}
// Commit transaction.
if let Err(err) = filter_engine.commit() {
return Err(err);
}
filter_engine.commit()?;
return Ok(());
}

View file

@ -85,7 +85,7 @@ impl NetBufferList {
}
// Allocate space in buffer, if buffer is too small.
let mut buffer = alloc::vec![0 as u8; data_length as usize];
let mut buffer = alloc::vec![0_u8; data_length as usize];
let ptr = NdisGetDataBuffer(nb, data_length, buffer.as_mut_ptr(), 1, 0);
@ -209,7 +209,7 @@ impl Iterator for NetBufferListIter {
}
}
pub fn read_packet_partial<'a>(nbl: *mut NET_BUFFER_LIST, buffer: &'a mut [u8]) -> Result<(), ()> {
pub fn read_packet_partial(nbl: *mut NET_BUFFER_LIST, buffer: &mut [u8]) -> Result<(), ()> {
unsafe {
let Some(nbl) = nbl.as_ref() else {
return Err(());

View file

@ -105,9 +105,9 @@ impl Injector {
}
let mut remote_ip: [u8; 16] = [0; 16];
if ipv6 {
remote_ip[0..16].copy_from_slice(&remote_ip_slice);
remote_ip[0..16].copy_from_slice(remote_ip_slice);
} else {
remote_ip[0..4].copy_from_slice(&remote_ip_slice);
remote_ip[0..4].copy_from_slice(remote_ip_slice);
}
TransportPacketList {

View file

@ -67,7 +67,7 @@ impl ReadRequest<'_> {
for i in 0..bytes_to_write {
self.buffer[self.fill_index + i] = bytes[i];
}
self.fill_index = self.fill_index + bytes_to_write;
self.fill_index += bytes_to_write;
bytes_to_write
}
@ -94,7 +94,7 @@ impl WriteRequest<'_> {
}
pub fn get_buffer(&self) -> &[u8] {
&self.buffer
self.buffer
}
pub fn mark_all_as_read(&mut self) {
@ -155,7 +155,7 @@ impl DeviceControlRequest<'_> {
}
pub fn get_buffer(&self) -> &[u8] {
&self.buffer
self.buffer
}
pub fn write(&mut self, bytes: &[u8]) -> usize {
let mut bytes_to_write: usize = bytes.len();
@ -168,7 +168,7 @@ impl DeviceControlRequest<'_> {
for i in 0..bytes_to_write {
self.buffer[self.fill_index + i] = bytes[i];
}
self.fill_index = self.fill_index + bytes_to_write;
self.fill_index += bytes_to_write;
bytes_to_write
}