Skip to content

Commit 5d67b55

Browse files
authored
Merge pull request #293 from nbdd0121/misc
Misc cleanups
2 parents 50f2249 + 91ae92b commit 5d67b55

File tree

9 files changed

+26
-11
lines changed

9 files changed

+26
-11
lines changed

lib/Kconfig.debug

+1
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,7 @@ choice
26452645
prompt "Build-time assertions"
26462646
default RUST_BUILD_ASSERT_ALLOW if RUST_OPT_LEVEL_0
26472647
default RUST_BUILD_ASSERT_DENY if !RUST_OPT_LEVEL_0
2648+
depends on RUST
26482649
help
26492650
Controls how are `build_error!` and `build_assert!` handled during build.
26502651

rust/Makefile

+8-5
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,17 @@ bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
8484
$(bindgen_extra_c_flags)
8585
endif
8686

87-
bindgen_opaque_types := xregs_state desc_struct arch_lbr_state local_apic
88-
8987
# To avoid several recompilations in PowerPC, which inserts `-D_TASK_CPU`
9088
bindgen_c_flags_final = $(filter-out -D_TASK_CPU=%, $(bindgen_c_flags))
9189

9290
quiet_cmd_bindgen = BINDGEN $@
9391
cmd_bindgen = \
94-
$(BINDGEN) $< $(addprefix --opaque-type , $(bindgen_opaque_types)) \
92+
$(BINDGEN) $< $(shell grep -v '^\#\|^$$' $(srctree)/rust/bindgen_parameters) \
9593
--use-core --with-derive-default --ctypes-prefix c_types \
9694
--size_t-is-usize -o $@ -- $(bindgen_c_flags_final) -DMODULE
9795

98-
$(objtree)/rust/bindings_generated.rs: $(srctree)/rust/kernel/bindings_helper.h FORCE
96+
$(objtree)/rust/bindings_generated.rs: $(srctree)/rust/kernel/bindings_helper.h \
97+
$(srctree)/rust/bindgen_parameters FORCE
9998
$(call if_changed_dep,bindgen)
10099

101100
quiet_cmd_exports = EXPORTS $@
@@ -126,7 +125,11 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
126125
mv $(objtree)/rust/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \
127126
sed -i '/^\#/d' $(depfile)
128127

129-
$(objtree)/rust/libmodule.so: $(srctree)/rust/module.rs FORCE
128+
# Procedural macros can only be used with the `rustc` that compiled it.
129+
# Therefore, to get `libmodule.so` automatically recompiled when the compiler
130+
# version changes, we add `core.o` as a dependency (even if it is not needed).
131+
$(objtree)/rust/libmodule.so: $(srctree)/rust/module.rs \
132+
$(objtree)/rust/core.o FORCE
130133
$(call if_changed_dep,rustc_procmacro)
131134

132135
quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@

rust/bindgen_parameters

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
--opaque-type xregs_state
4+
--opaque-type desc_struct
5+
--opaque-type arch_lbr_state
6+
--opaque-type local_apic
7+
8+
# If SMP is disabled, `arch_spinlock_t` is defined as a ZST which triggers a Rust
9+
# warning. We don't need to peek into it anyway.
10+
--opaque-type spinlock

rust/kernel/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![deny(clippy::correctness)]
2828
#![deny(clippy::perf)]
2929
#![deny(clippy::style)]
30+
#![deny(rust_2018_idioms)]
3031

3132
// Ensure conditional compilation based on the kernel configuration works;
3233
// otherwise we may silently break things like initcall handling.

rust/kernel/pages.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<const ORDER: u32> Pages<ORDER> {
132132
}
133133

134134
/// Maps the page at index `index`.
135-
fn kmap(&self, index: usize) -> Option<PageMapping> {
135+
fn kmap(&self, index: usize) -> Option<PageMapping<'_>> {
136136
if index >= 1usize << ORDER {
137137
return None;
138138
}

rust/kernel/sync/condvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl CondVar {
6565
///
6666
/// Returns whether there is a signal pending.
6767
#[must_use = "wait returns if a signal is pending, so the caller must check the return value"]
68-
pub fn wait<L: Lock>(&self, guard: &mut Guard<L>) -> bool {
68+
pub fn wait<L: Lock>(&self, guard: &mut Guard<'_, L>) -> bool {
6969
let lock = guard.lock;
7070
let mut wait = MaybeUninit::<bindings::wait_queue_entry>::uninit();
7171

rust/kernel/sync/locked_by.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<T, L: Lock + ?Sized> LockedBy<T, L> {
7878
impl<T: ?Sized, L: Lock + ?Sized> LockedBy<T, L> {
7979
/// Returns a reference to the protected data when the caller provides evidence (via a
8080
/// [`Guard`]) that the owner is locked.
81-
pub fn access<'a>(&'a self, guard: &'a Guard<L>) -> &'a T {
81+
pub fn access<'a>(&'a self, guard: &'a Guard<'_, L>) -> &'a T {
8282
if !ptr::eq(guard.deref(), self.owner) {
8383
panic!("guard does not match owner");
8484
}
@@ -89,7 +89,7 @@ impl<T: ?Sized, L: Lock + ?Sized> LockedBy<T, L> {
8989

9090
/// Returns a mutable reference to the protected data when the caller provides evidence (via a
9191
/// mutable [`Guard`]) that the owner is locked mutably.
92-
pub fn access_mut<'a>(&'a self, guard: &'a mut Guard<L>) -> &'a mut T {
92+
pub fn access_mut<'a>(&'a self, guard: &'a mut Guard<'_, L>) -> &'a mut T {
9393
if !ptr::eq(guard.deref().deref(), self.owner) {
9494
panic!("guard does not match owner");
9595
}

rust/kernel/sync/mutex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<T> Mutex<T> {
6464
impl<T: ?Sized> Mutex<T> {
6565
/// Locks the mutex and gives the caller access to the data protected by it. Only one thread at
6666
/// a time is allowed to access the protected data.
67-
pub fn lock(&self) -> Guard<Self> {
67+
pub fn lock(&self) -> Guard<'_, Self> {
6868
self.lock_noguard();
6969
// SAFETY: The mutex was just acquired.
7070
unsafe { Guard::new(self) }

rust/kernel/sync/spinlock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<T> SpinLock<T> {
7878
impl<T: ?Sized> SpinLock<T> {
7979
/// Locks the spinlock and gives the caller access to the data protected by it. Only one thread
8080
/// at a time is allowed to access the protected data.
81-
pub fn lock(&self) -> Guard<Self> {
81+
pub fn lock(&self) -> Guard<'_, Self> {
8282
self.lock_noguard();
8383
// SAFETY: The spinlock was just acquired.
8484
unsafe { Guard::new(self) }

0 commit comments

Comments
 (0)