Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Feb 20, 2025
1 parent f05f872 commit 28c1fc7
Show file tree
Hide file tree
Showing 45 changed files with 74 additions and 80 deletions.
2 changes: 1 addition & 1 deletion arch/rv32i/src/pmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl TORRegionSpec {
|| (end as usize) % 4 != 0
|| (end as usize)
.checked_sub(start as usize)
.map_or(true, |size| size < 4)
.is_none_or(|size| size < 4)
{
None
} else {
Expand Down
2 changes: 1 addition & 1 deletion boards/nordic/nrf52840dk/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl IoWrite for Writer {
Writer::WriterRtt(rtt_memory) => {
rtt_memory.write_sync(buf);
}
};
}
buf.len()
}
}
Expand Down
2 changes: 1 addition & 1 deletion capsules/core/src/low_level_debug/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl core::fmt::Write for WriteAdapter<'_> {
if let Some(slice) = self.buffer.get_mut(self.used..(self.used + msg.len())) {
slice.copy_from_slice(msg.as_bytes());
self.used += msg.len();
};
}
Ok(())
}
}
6 changes: 3 additions & 3 deletions capsules/core/src/process_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ impl<
self.command_index.set(next_command_len);
self.cursor.set(next_command_len);
command[next_command_len] = EOL;
};
}
});
}
EscKey::Left if cursor > 0 => {
Expand Down Expand Up @@ -1310,7 +1310,7 @@ impl<
}
}
_ => {}
};
}
} else if read_buf[0] == NLINE || read_buf[0] == CR {
if (previous_byte == NLINE || previous_byte == CR)
&& previous_byte != read_buf[0]
Expand Down Expand Up @@ -1429,7 +1429,7 @@ impl<
"ProcessConsole issues reads of 1 byte, but receive_complete was length {}",
rx_len
),
};
}
}
let _ = self.uart.receive_buffer(read_buf, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion capsules/core/src/virtualizers/virtual_alarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'a, A: Alarm<'a>> Alarm<'a> for VirtualMuxAlarm<'a, A> {
let expiration = reference.wrapping_add(dt);
if !cur_alarm.within_range(reference, expiration) {
let next = self.mux.next_tick_vals.get();
if next.map_or(true, |(next_reference, next_dt)| {
if next.is_none_or(|(next_reference, next_dt)| {
now.within_range(next_reference, next_reference.wrapping_add(next_dt))
}) {
self.mux.set_alarm(reference, dt);
Expand Down
2 changes: 1 addition & 1 deletion capsules/core/src/virtualizers/virtual_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'a, F: hil::flash::Flash> MuxFlash<'a, F> {
let _ = self.flash.erase_page(page_number);
}
_ => {}
};
}
},
|buf| {
match node.operation.get() {
Expand Down
6 changes: 3 additions & 3 deletions capsules/core/src/virtualizers/virtual_i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a, I: i2c::I2CMaster<'a>, S: i2c::SMBusMaster<'a>> MuxI2C<'a, I, S> {
node.operation.set(Op::CommandComplete(Err(e.0)));
node.mux.do_next_op_async();
}
};
}
}
Op::Read(len) => {
match self.smbus.unwrap().smbus_read(node.addr, buf, len) {
Expand All @@ -144,7 +144,7 @@ impl<'a, I: i2c::I2CMaster<'a>, S: i2c::SMBusMaster<'a>> MuxI2C<'a, I, S> {
node.operation.set(Op::CommandComplete(Err(e.0)));
node.mux.do_next_op_async();
}
};
}
}
Op::WriteRead(wlen, rlen) => {
match self
Expand All @@ -158,7 +158,7 @@ impl<'a, I: i2c::I2CMaster<'a>, S: i2c::SMBusMaster<'a>> MuxI2C<'a, I, S> {
node.operation.set(Op::CommandComplete(Err(e.0)));
node.mux.do_next_op_async();
}
};
}
}
Op::CommandComplete(err) => {
self.command_complete(buf, err);
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl<Can: can::Can> can::ReceiveClient<{ can::STANDARD_CAN_PACKET_SIZE }> for Ca
(error_upcalls::ERROR_RX, kernel_err.into(), 0),
)
}
};
}
}

fn stopped(&self, buffer: &'static mut [u8; can::STANDARD_CAN_PACKET_SIZE]) {
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/gpio_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<Port: hil::gpio_async::Port> SyscallDriver for GPIOAsync<'_, Port> {
// On any command other than 0, we check if another command is in flight
if self.configuring_process.is_some() {
return CommandReturn::failure(ErrorCode::BUSY);
};
}

let res = match command_number {
// enable output
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/ieee802154/framer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ impl<'a, M: Mac<'a>, A: AES128CCM<'a>> CCMClient for Framer<'a, M, A> {
};
self.rx_state.replace(other_state);
}
};
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/lpm013m126.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ where
_ => {
self.extcomin.toggle();
}
};
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions capsules/extra/src/lsm6dsoxtr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl<I: i2c::I2CDevice> i2c::I2CClient for Lsm6dsoxtrI2C<'_, I> {
self.nine_dof_client.map(|client| {
client.callback(0, 0, 0);
});
};
}
self.buffer.replace(buffer);
self.i2c.disable();
self.state.set(State::Idle);
Expand Down Expand Up @@ -474,7 +474,7 @@ impl<I: i2c::I2CDevice> i2c::I2CClient for Lsm6dsoxtrI2C<'_, I> {
self.nine_dof_client.map(|client| {
client.callback(0, 0, 0);
});
};
}
self.buffer.replace(buffer);
self.i2c.disable();
self.state.set(State::Idle);
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/net/sixlowpan/sixlowpan_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ fn decompress_multicast(
iphc::DAM_INLINE => {
// DAC = 1, DAM = 00: 48 bits
// ffXX:XXLL:PPPP:PPPP:PPPP:PPPP:XXXX:XXXX
let prefix_bytes = ((ctx.prefix_len + 7) / 8) as usize;
let prefix_bytes = ctx.prefix_len.div_ceil(8) as usize;
if prefix_bytes > 8 {
// The maximum prefix length for this mode is 64 bits.
// If the specified prefix exceeds this length, the
Expand Down
4 changes: 2 additions & 2 deletions capsules/extra/src/net/thread/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a, A: time::Alarm<'a>> ThreadNetworkDriver<'a, A> {
self.state.replace(curr_state);
self.terminate_child_join(Err(ErrorCode::BUSY));
}
};
}
}

fn thread_mle_send(
Expand Down Expand Up @@ -738,6 +738,6 @@ impl<'a, A: time::Alarm<'a>> CCMClient for ThreadNetworkDriver<'a, A> {
.map(|code| self.terminate_child_join(Err(code)));
}
_ => (),
};
}
}
}
2 changes: 1 addition & 1 deletion capsules/extra/src/net/udp/udp_port_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl UdpPortManager {
.map_or(true, |port_query| port_query.is_bound(port));
if user_bound {
return Ok(true);
};
}
let ret = self
.port_array
.map(|table| {
Expand Down
4 changes: 2 additions & 2 deletions capsules/extra/src/public_key_crypto/rsa_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl<const L: usize> RsaPrivKey for RSAKeys<L> {
MutImutBuffer::Immutable(buf) => {
closure(buf);
}
};
}
self.private_key.replace(private_key);
Some(())
} else {
Expand Down Expand Up @@ -332,7 +332,7 @@ impl<const L: usize> RsaPrivKeyMut for RSAKeys<L> {
closure(buf);
}
MutImutBuffer::Immutable(_buf) => unreachable!(),
};
}
self.private_key.replace(private_key);
Some(())
} else {
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl<'a> Screen<'a> {
let mut write_len = buffer_size / bytes_per_pixel;
if write_len > len {
write_len = len
};
}
app.write_position += write_len * bytes_per_pixel;
kernel_data
.get_readonly_processbuffer(ro_allow::SHARED)
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/sdcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ impl<'a, A: hil::time::Alarm<'a>> SDCard<'a, A> {

pub fn is_installed(&self) -> bool {
// if there is no detect pin, assume an sd card is installed
self.detect_pin.get().map_or(true, |pin| {
self.detect_pin.get().is_none_or(|pin| {
// sd card detection pin is active low
!pin.read()
})
Expand Down
6 changes: 3 additions & 3 deletions capsules/extra/src/st77xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl<'a, A: Alarm<'a>, B: Bus<'a, BusAddr8>, P: Pin> ST77XX<'a, A, B, P> {
self.width.set(self.screen.default_height);
self.height.set(self.screen.default_width);
}
};
}
self.buffer.map_or_else(
|| panic!("st77xx: set rotation has no buffer"),
|buffer| {
Expand Down Expand Up @@ -505,7 +505,7 @@ impl<'a, A: Alarm<'a>, B: Bus<'a, BusAddr8>, P: Pin> ST77XX<'a, A, B, P> {
SendCommand::Slice(cmd, len) => {
self.send_command_slice(cmd, len);
}
};
}
},
);
} else {
Expand Down Expand Up @@ -614,7 +614,7 @@ impl<'a, A: Alarm<'a>, B: Bus<'a, BusAddr8>, P: Pin> ST77XX<'a, A, B, P> {
_ => {
panic!("ST77XX status Idle");
}
};
}
}

fn set_memory_frame(
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/tickv_kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<'a, K: KVSystem<'a, K = T>, T: KeyType> KVSystemClient<T> for TicKVKVStore<
cb.delete_complete(Err(ErrorCode::FAIL), unhashed_key);
});
}
};
}
}
Operation::GarbageCollect => {}
}
Expand Down
4 changes: 1 addition & 3 deletions capsules/extra/src/tutorials/encryption_oracle_chkpt4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ impl<'a, A: AES128<'a> + AES128Ctr> EncryptionOracleDriver<'a, A> {
iv[..copy_len].copy_to_slice(&mut static_buf[..copy_len]);

AES128::set_iv(self.aes, &static_buf[..copy_len])
})
.map_err(Into::into)
})??;
})})??;
}

// Our AES engine works with kernel-provided `&'static mut`
Expand Down
4 changes: 1 addition & 3 deletions capsules/extra/src/tutorials/encryption_oracle_chkpt5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ impl<'a, A: AES128<'a> + AES128Ctr> EncryptionOracleDriver<'a, A> {
iv[..copy_len].copy_to_slice(&mut static_buf[..copy_len]);

AES128::set_iv(self.aes, &static_buf[..copy_len])
})
.map_err(Into::into)
})??;
})})??;
}

// Our AES engine works with kernel-provided `&'static mut`
Expand Down
2 changes: 1 addition & 1 deletion capsules/extra/src/usb/usbc_client_ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl<'a, 'b, U: hil::usb::UsbController<'a>> ClientCtrl<'a, 'b, U> {
self.controller.enable_address();
}
_ => {}
};
}
self.state[endpoint].set(State::Init);
}
}
2 changes: 1 addition & 1 deletion capsules/extra/src/usb_hid_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'a, U: usb_hid::UsbHid<'a, [u8; 64]>> SyscallDriver for UsbHidDriver<'a, U>
}
} else {
return CommandReturn::failure(ErrorCode::ALREADY);
};
}

// If we were able to setup a read then next we do the
// transmit.
Expand Down
2 changes: 1 addition & 1 deletion chips/apollo3/src/clkgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ClkGen {
regs.cctrl.set(0);
regs.clkkey.set(0);
}
};
}
}

pub fn enable_ble(&self) {
Expand Down
2 changes: 1 addition & 1 deletion chips/esp32-c3/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl DeferredCallClient for Rng<'_> {
self.client.map(|client| {
if let Continue::More = client.entropy_available(&mut RngIter(self), Ok(())) {
self.deferred_call.set();
};
}
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions chips/lowrisc/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a> OtbnRsa<'a> {
);
}
MutImutBuffer::Immutable(_) => unreachable!(),
};
}
});
}
MutImutBuffer::Immutable(exponent) => {
Expand All @@ -82,7 +82,7 @@ impl<'a> OtbnRsa<'a> {
});
}
MutImutBuffer::Mutable(_) => unreachable!(),
};
}
}
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<'a> crate::otbn::Client<'a> for OtbnRsa<'a> {
);
}
MutImutBuffer::Immutable(_) => unreachable!(),
};
}
});
}
MutImutBuffer::Immutable(exponent) => {
Expand All @@ -129,7 +129,7 @@ impl<'a> crate::otbn::Client<'a> for OtbnRsa<'a> {
});
}
MutImutBuffer::Mutable(_) => unreachable!(),
};
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions chips/lowrisc/src/spi_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ impl<'a> hil::spi::SpiMaster<'a> for SpiHost<'a> {
match polarity {
ClockPolarity::IdleLow => regs.config_opts.modify(conf_opts::CPOL_0::CLEAR),
ClockPolarity::IdleHigh => regs.config_opts.modify(conf_opts::CPOL_0::SET),
};
}
Ok(())
}

Expand All @@ -713,7 +713,7 @@ impl<'a> hil::spi::SpiMaster<'a> for SpiHost<'a> {
match phase {
ClockPhase::SampleLeading => regs.config_opts.modify(conf_opts::CPHA_0::CLEAR),
ClockPhase::SampleTrailing => regs.config_opts.modify(conf_opts::CPHA_0::SET),
};
}
Ok(())
}

Expand Down
Loading

0 comments on commit 28c1fc7

Please sign in to comment.