Skip to content

Commit

Permalink
Merge pull request torvalds#293 from nbdd0121/misc
Browse files Browse the repository at this point in the history
Misc cleanups
  • Loading branch information
ojeda authored May 26, 2021
2 parents 50f2249 + 91ae92b commit 5d67b55
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,7 @@ choice
prompt "Build-time assertions"
default RUST_BUILD_ASSERT_ALLOW if RUST_OPT_LEVEL_0
default RUST_BUILD_ASSERT_DENY if !RUST_OPT_LEVEL_0
depends on RUST
help
Controls how are `build_error!` and `build_assert!` handled during build.

Expand Down
13 changes: 8 additions & 5 deletions rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,17 @@ bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
$(bindgen_extra_c_flags)
endif

bindgen_opaque_types := xregs_state desc_struct arch_lbr_state local_apic

# To avoid several recompilations in PowerPC, which inserts `-D_TASK_CPU`
bindgen_c_flags_final = $(filter-out -D_TASK_CPU=%, $(bindgen_c_flags))

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

$(objtree)/rust/bindings_generated.rs: $(srctree)/rust/kernel/bindings_helper.h FORCE
$(objtree)/rust/bindings_generated.rs: $(srctree)/rust/kernel/bindings_helper.h \
$(srctree)/rust/bindgen_parameters FORCE
$(call if_changed_dep,bindgen)

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

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

quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
Expand Down
10 changes: 10 additions & 0 deletions rust/bindgen_parameters
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: GPL-2.0

--opaque-type xregs_state
--opaque-type desc_struct
--opaque-type arch_lbr_state
--opaque-type local_apic

# If SMP is disabled, `arch_spinlock_t` is defined as a ZST which triggers a Rust
# warning. We don't need to peek into it anyway.
--opaque-type spinlock
1 change: 1 addition & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#![deny(clippy::correctness)]
#![deny(clippy::perf)]
#![deny(clippy::style)]
#![deny(rust_2018_idioms)]

// Ensure conditional compilation based on the kernel configuration works;
// otherwise we may silently break things like initcall handling.
Expand Down
2 changes: 1 addition & 1 deletion rust/kernel/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<const ORDER: u32> Pages<ORDER> {
}

/// Maps the page at index `index`.
fn kmap(&self, index: usize) -> Option<PageMapping> {
fn kmap(&self, index: usize) -> Option<PageMapping<'_>> {
if index >= 1usize << ORDER {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion rust/kernel/sync/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl CondVar {
///
/// Returns whether there is a signal pending.
#[must_use = "wait returns if a signal is pending, so the caller must check the return value"]
pub fn wait<L: Lock>(&self, guard: &mut Guard<L>) -> bool {
pub fn wait<L: Lock>(&self, guard: &mut Guard<'_, L>) -> bool {
let lock = guard.lock;
let mut wait = MaybeUninit::<bindings::wait_queue_entry>::uninit();

Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/sync/locked_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T, L: Lock + ?Sized> LockedBy<T, L> {
impl<T: ?Sized, L: Lock + ?Sized> LockedBy<T, L> {
/// Returns a reference to the protected data when the caller provides evidence (via a
/// [`Guard`]) that the owner is locked.
pub fn access<'a>(&'a self, guard: &'a Guard<L>) -> &'a T {
pub fn access<'a>(&'a self, guard: &'a Guard<'_, L>) -> &'a T {
if !ptr::eq(guard.deref(), self.owner) {
panic!("guard does not match owner");
}
Expand All @@ -89,7 +89,7 @@ impl<T: ?Sized, L: Lock + ?Sized> LockedBy<T, L> {

/// Returns a mutable reference to the protected data when the caller provides evidence (via a
/// mutable [`Guard`]) that the owner is locked mutably.
pub fn access_mut<'a>(&'a self, guard: &'a mut Guard<L>) -> &'a mut T {
pub fn access_mut<'a>(&'a self, guard: &'a mut Guard<'_, L>) -> &'a mut T {
if !ptr::eq(guard.deref().deref(), self.owner) {
panic!("guard does not match owner");
}
Expand Down
2 changes: 1 addition & 1 deletion rust/kernel/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T> Mutex<T> {
impl<T: ?Sized> Mutex<T> {
/// Locks the mutex and gives the caller access to the data protected by it. Only one thread at
/// a time is allowed to access the protected data.
pub fn lock(&self) -> Guard<Self> {
pub fn lock(&self) -> Guard<'_, Self> {
self.lock_noguard();
// SAFETY: The mutex was just acquired.
unsafe { Guard::new(self) }
Expand Down
2 changes: 1 addition & 1 deletion rust/kernel/sync/spinlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T> SpinLock<T> {
impl<T: ?Sized> SpinLock<T> {
/// Locks the spinlock and gives the caller access to the data protected by it. Only one thread
/// at a time is allowed to access the protected data.
pub fn lock(&self) -> Guard<Self> {
pub fn lock(&self) -> Guard<'_, Self> {
self.lock_noguard();
// SAFETY: The spinlock was just acquired.
unsafe { Guard::new(self) }
Expand Down

0 comments on commit 5d67b55

Please sign in to comment.