Skip to content

Commit 61104a0

Browse files
authored
Merge pull request torvalds#847 from ojeda/cleanups
treewide: cleanups and clarifications
2 parents 5f48fa8 + ecd8e1f commit 61104a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+206
-131
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,8 +1716,9 @@ help:
17161716
@echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
17171717
@echo ' (requires kernel .config)'
17181718
@echo ' dir/file.[os] - Build specified target only'
1719-
@echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing'
1720-
@echo ' (run with RUSTFMT=n to skip reformatting if needed)'
1719+
@echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
1720+
@echo ' Run with RUSTFMT=n to skip reformatting if needed.'
1721+
@echo ' The output is not intended to be compilable.'
17211722
@echo ' dir/file.ll - Build the LLVM assembly file'
17221723
@echo ''
17231724
@$(if $(dtstree), \

drivers/android/transaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ impl Transaction {
196196

197197
impl DeliverToRead for Transaction {
198198
fn do_work(self: Ref<Self>, thread: &Thread, writer: &mut UserSlicePtrWriter) -> Result<bool> {
199-
/* TODO: Initialise the following fields from tr:
200-
pub sender_pid: pid_t,
201-
pub sender_euid: uid_t,
202-
*/
199+
// TODO: Initialise the following fields from `tr`:
200+
// - `pub sender_pid: pid_t`.
201+
// - `pub sender_euid: uid_t`.
202+
203203
let send_failed_reply = ScopeGuard::new(|| {
204204
if self.node_ref.is_some() && self.flags & TF_ONE_WAY == 0 {
205205
let reply = Either::Right(BR_FAILED_REPLY);

include/linux/compiler_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#ifndef __ASSEMBLY__
66

7+
/*
8+
* Skipped when running bindgen due to a libclang issue;
9+
* see https://github.com/rust-lang/rust-bindgen/issues/2244.
10+
*/
711
#if defined(CONFIG_DEBUG_INFO_BTF) && defined(CONFIG_PAHOLE_HAS_BTF_TAG) && \
812
__has_attribute(btf_type_tag) && !defined(__BINDGEN__)
913
# define BTF_TYPE_TAG(value) __attribute__((btf_type_tag(#value)))

include/linux/spinlock.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ static inline void __spin_lock_init(spinlock_t *lock, const char *name,
338338
__raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
339339
}
340340

341-
# define spin_lock_init(lock) \
342-
do { \
343-
static struct lock_class_key __key; \
344-
\
345-
__spin_lock_init(lock, #lock, &__key); \
341+
# define spin_lock_init(lock) \
342+
do { \
343+
static struct lock_class_key __key; \
344+
\
345+
__spin_lock_init(lock, #lock, &__key); \
346346
} while (0)
347347

348348
#else

rust/alloc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# `alloc`
22

33
These source files come from the Rust standard library, hosted in
4-
the https://github.com/rust-lang/rust repository, licensed under
4+
the <https://github.com/rust-lang/rust> repository, licensed under
55
"Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
6-
see https://github.com/rust-lang/rust/blob/master/COPYRIGHT.
6+
see <https://github.com/rust-lang/rust/blob/master/COPYRIGHT>.
77

88
Please note that these files should be kept as close as possible to
99
upstream. In general, only additions should be performed (e.g. new

rust/alloc/boxed/thin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
13
// Based on
24
// https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs
35
// by matthieu-m

rust/alloc/ffi/c_str.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
13
#[cfg(test)]
24
mod tests;
35

rust/alloc/ffi/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: Apache-2.0 OR MIT
2+
13
//! Utilities related to FFI bindings.
24
//!
35
//! This module provides utilities to handle data across non-Rust

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/errname.h>
1414
#include <linux/file.h>
1515
#include <linux/fs.h>
16+
#include <linux/fs_parser.h>
1617
#include <linux/gpio/driver.h>
1718
#include <linux/hw_random.h>
1819
#include <linux/interrupt.h>
@@ -36,7 +37,6 @@
3637
#include <linux/uaccess.h>
3738
#include <linux/uio.h>
3839
#include <uapi/linux/android/binder.h>
39-
#include <linux/fs_parser.h>
4040

4141
/* `bindgen` gets confused at certain things. */
4242
const gfp_t BINDINGS_GFP_KERNEL = GFP_KERNEL;

rust/bindings/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
#![no_std]
1212
#![feature(core_ffi_c)]
13-
// See https://github.com/rust-lang/rust-bindgen/issues/1651.
13+
// See <https://github.com/rust-lang/rust-bindgen/issues/1651>.
1414
#![cfg_attr(test, allow(deref_nullptr))]
1515
#![cfg_attr(test, allow(unaligned_references))]
1616
#![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))]

rust/exports.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include <linux/module.h>
1515

16-
#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym);
16+
#define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)
1717

1818
#include "exports_core_generated.h"
1919
#include "exports_alloc_generated.h"

rust/helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/build_bug.h>
2424
#include <linux/clk.h>
2525
#include <linux/errname.h>
26+
#include <linux/fs_parser.h>
2627
#include <linux/gfp.h>
2728
#include <linux/highmem.h>
2829
#include <linux/io.h>
@@ -38,7 +39,6 @@
3839
#include <linux/skbuff.h>
3940
#include <linux/uaccess.h>
4041
#include <linux/uio.h>
41-
#include <linux/fs_parser.h>
4242

4343
__noreturn void rust_helper_BUG(void)
4444
{

rust/kernel/amba.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ unsafe extern "C" fn probe_callback<T: Driver>(
120120
} else {
121121
// SAFETY: The offset comes from a previous call to `offset_from` in `IdArray::new`,
122122
// which guarantees that the resulting pointer is within the table.
123-
let ptr = unsafe { aid.cast::<u8>().offset(offset as _).cast::<Option<T::IdInfo>>() };
123+
let ptr = unsafe {
124+
aid.cast::<u8>()
125+
.offset(offset as _)
126+
.cast::<Option<T::IdInfo>>()
127+
};
124128
// SAFETY: The id table has a static lifetime, so `ptr` is guaranteed to be valid for
125129
// read.
126130
unsafe { (&*ptr).as_ref() }
@@ -243,9 +247,9 @@ macro_rules! module_amba_driver {
243247
/// # fn probe(_dev: &mut amba::Device, _id: Option<&Self::IdInfo>) -> Result {
244248
/// # Ok(())
245249
/// # }
246-
/// define_amba_id_table! {(), [
247-
/// ({ id: 0x00041061, mask: 0x000fffff }, None),
248-
/// ]}
250+
/// define_amba_id_table! {(), [
251+
/// ({ id: 0x00041061, mask: 0x000fffff }, None),
252+
/// ]}
249253
/// # }
250254
/// ```
251255
#[macro_export]

rust/kernel/build_assert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/// be called, a build error will be triggered.
1010
///
1111
/// # Examples
12+
///
1213
/// ```
1314
/// # use kernel::build_error;
1415
/// #[inline]

rust/kernel/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn coarse_sleep_conversion(duration: Duration) -> core::ffi::c_uint {
5252
/// coarse_sleep(Duration::new(1, 2)); // Equivalent to `msleep(1001)`.
5353
/// ```
5454
pub fn coarse_sleep(duration: Duration) {
55-
// SAFETY: msleep is safe for all values of an `unsigned int`.
55+
// SAFETY: `msleep` is safe for all values of its argument.
5656
unsafe { bindings::msleep(coarse_sleep_conversion(duration)) }
5757
}
5858

rust/kernel/device.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ use crate::c_str;
3131
/// related to `self`, that is, actions on it will affect `self`. For example, if one calls
3232
/// `get_device`, then the refcount on the device represented by `self` will be incremented.
3333
///
34-
/// Additionally, implementers must ensure that the device is never renamed. Commit a5462516aa994
35-
/// has details on why `device_rename` should not be used.
34+
/// Additionally, implementers must ensure that the device is never renamed. Commit a5462516aa99
35+
/// ("driver-core: document restrictions on device_rename()") has details on why `device_rename`
36+
/// should not be used.
3637
pub unsafe trait RawDevice {
3738
/// Returns the raw `struct device` related to `self`.
3839
fn raw_device(&self) -> *mut bindings::device;

rust/kernel/driver.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ macro_rules! first_item {
280280
/// assert_eq!([] as [u32; 0], second_item!());
281281
/// assert_eq!([10u32], second_item!((X, 10u32)));
282282
/// assert_eq!([10u32], second_item!((X, 10u32),));
283-
/// assert_eq!([10u32], second_item!(({X}, 10u32)));
284-
/// assert_eq!([10u32], second_item!(({X}, 10u32),));
283+
/// assert_eq!([10u32], second_item!(({ X }, 10u32)));
284+
/// assert_eq!([10u32], second_item!(({ X }, 10u32),));
285285
/// assert_eq!([10u32, 20], second_item!((X, 10u32), (X, 20)));
286286
/// assert_eq!([10u32, 20], second_item!((X, 10u32), (X, 20),));
287-
/// assert_eq!([10u32, 20], second_item!(({X}, 10u32), ({X}, 20)));
288-
/// assert_eq!([10u32, 20], second_item!(({X}, 10u32), ({X}, 20),));
287+
/// assert_eq!([10u32, 20], second_item!(({ X }, 10u32), ({ X }, 20)));
288+
/// assert_eq!([10u32, 20], second_item!(({ X }, 10u32), ({ X }, 20),));
289289
/// assert_eq!([10u32, 20, 30], second_item!((X, 10u32), (X, 20), (X, 30)));
290290
/// assert_eq!([10u32, 20, 30], second_item!((X, 10u32), (X, 20), (X, 30),));
291-
/// assert_eq!([10u32, 20, 30], second_item!(({X}, 10u32), ({X}, 20), ({X}, 30)));
292-
/// assert_eq!([10u32, 20, 30], second_item!(({X}, 10u32), ({X}, 20), ({X}, 30),));
291+
/// assert_eq!([10u32, 20, 30], second_item!(({ X }, 10u32), ({ X }, 20), ({ X }, 30)));
292+
/// assert_eq!([10u32, 20, 30], second_item!(({ X }, 10u32), ({ X }, 20), ({ X }, 30),));
293293
/// ```
294294
#[macro_export]
295295
macro_rules! second_item {

rust/kernel/file.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub mod flags {
4747
/// Ensure that this file is created with the `open(2)` call.
4848
pub const O_EXCL: u32 = bindings::O_EXCL;
4949

50-
/// Large file size enabled (`off64_t` over `off_t`)
50+
/// Large file size enabled (`off64_t` over `off_t`).
5151
pub const O_LARGEFILE: u32 = bindings::O_LARGEFILE;
5252

5353
/// Do not update the file last access time.
@@ -326,15 +326,16 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
326326
offset: *mut bindings::loff_t,
327327
) -> core::ffi::c_ssize_t {
328328
from_kernel_result! {
329-
let mut data = unsafe { UserSlicePtr::new(buf as *mut core::ffi::c_void, len).writer() };
329+
let mut data =
330+
unsafe { UserSlicePtr::new(buf as *mut core::ffi::c_void, len).writer() };
330331
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
331332
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
332333
// `release` callback, which the C API guarantees that will be called only when all
333334
// references to `file` have been released, so we know it can't be called while this
334335
// function is running.
335336
let f = unsafe { T::Data::borrow((*file).private_data) };
336337
// No `FMODE_UNSIGNED_OFFSET` support, so `offset` must be in [0, 2^63).
337-
// See discussion in https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113
338+
// See <https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113>.
338339
let read = T::read(
339340
f,
340341
unsafe { File::from_ptr(file) },
@@ -360,8 +361,12 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
360361
// references to `file` have been released, so we know it can't be called while this
361362
// function is running.
362363
let f = unsafe { T::Data::borrow((*file).private_data) };
363-
let read =
364-
T::read(f, unsafe { File::from_ptr(file) }, &mut iter, offset.try_into()?)?;
364+
let read = T::read(
365+
f,
366+
unsafe { File::from_ptr(file) },
367+
&mut iter,
368+
offset.try_into()?,
369+
)?;
365370
unsafe { (*iocb).ki_pos += bindings::loff_t::try_from(read).unwrap() };
366371
Ok(read as _)
367372
}
@@ -374,20 +379,21 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
374379
offset: *mut bindings::loff_t,
375380
) -> core::ffi::c_ssize_t {
376381
from_kernel_result! {
377-
let mut data = unsafe { UserSlicePtr::new(buf as *mut core::ffi::c_void, len).reader() };
382+
let mut data =
383+
unsafe { UserSlicePtr::new(buf as *mut core::ffi::c_void, len).reader() };
378384
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
379385
// `T::Data::into_pointer`. `T::Data::from_pointer` is only called by the
380386
// `release` callback, which the C API guarantees that will be called only when all
381387
// references to `file` have been released, so we know it can't be called while this
382388
// function is running.
383389
let f = unsafe { T::Data::borrow((*file).private_data) };
384390
// No `FMODE_UNSIGNED_OFFSET` support, so `offset` must be in [0, 2^63).
385-
// See discussion in https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113
391+
// See <https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113>.
386392
let written = T::write(
387393
f,
388394
unsafe { File::from_ptr(file) },
389395
&mut data,
390-
unsafe { *offset }.try_into()?
396+
unsafe { *offset }.try_into()?,
391397
)?;
392398
unsafe { (*offset) += bindings::loff_t::try_from(written).unwrap() };
393399
Ok(written as _)
@@ -408,8 +414,12 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
408414
// references to `file` have been released, so we know it can't be called while this
409415
// function is running.
410416
let f = unsafe { T::Data::borrow((*file).private_data) };
411-
let written =
412-
T::write(f, unsafe { File::from_ptr(file) }, &mut iter, offset.try_into()?)?;
417+
let written = T::write(
418+
f,
419+
unsafe { File::from_ptr(file) },
420+
&mut iter,
421+
offset.try_into()?,
422+
)?;
413423
unsafe { (*iocb).ki_pos += bindings::loff_t::try_from(written).unwrap() };
414424
Ok(written as _)
415425
}

rust/kernel/fs.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ impl<T: Type + ?Sized> Tables<T> {
166166
// SAFETY: The callback contract guarantees the parameter key to be valid and last at
167167
// least the duration of the callback.
168168
T::Context::parse_unknown_param(
169-
&mut data, unsafe { CStr::from_char_ptr(param.key) }, val)?;
169+
&mut data,
170+
unsafe { CStr::from_char_ptr(param.key) },
171+
val,
172+
)?;
170173
Ok(0)
171174
}
172175
}
@@ -291,8 +294,9 @@ impl<T: Type + ?Sized> Tables<T> {
291294
// SAFETY: Both `fc` and `buf` are guaranteed to be valid; the former because the
292295
// callback is still ongoing and the latter because its lifefime is tied to that of
293296
// `page`, which is also valid for the duration of the callback.
294-
to_result(
295-
unsafe { bindings::generic_parse_monolithic(fc, buf.as_mut_ptr().cast()) })?;
297+
to_result(unsafe {
298+
bindings::generic_parse_monolithic(fc, buf.as_mut_ptr().cast())
299+
})?;
296300
}
297301
Ok(0)
298302
}

rust/kernel/fs/param.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,12 @@ impl<S, T: Fn(&mut S, &bindings::fs_parameter, &bindings::fs_parse_result) -> Re
417417
/// # use kernel::count_brace_items;
418418
///
419419
/// assert_eq!(0, count_brace_items!());
420-
/// assert_eq!(1, count_brace_items!({A}));
421-
/// assert_eq!(1, count_brace_items!({A},));
422-
/// assert_eq!(2, count_brace_items!({A}, {B}));
423-
/// assert_eq!(2, count_brace_items!({A}, {B},));
424-
/// assert_eq!(3, count_brace_items!({A}, {B}, {C}));
425-
/// assert_eq!(3, count_brace_items!({A}, {B}, {C},));
420+
/// assert_eq!(1, count_brace_items!({ A }));
421+
/// assert_eq!(1, count_brace_items!({ A },));
422+
/// assert_eq!(2, count_brace_items!({ A }, { B }));
423+
/// assert_eq!(2, count_brace_items!({ A }, { B },));
424+
/// assert_eq!(3, count_brace_items!({ A }, { B }, { C }));
425+
/// assert_eq!(3, count_brace_items!({ A }, { B }, { C },));
426426
/// ```
427427
#[macro_export]
428428
macro_rules! count_brace_items {
@@ -434,6 +434,7 @@ macro_rules! count_brace_items {
434434
/// Defines the file system parameters of a given file system context.
435435
///
436436
/// # Examples
437+
///
437438
/// ```
438439
/// # use kernel::prelude::*;
439440
/// # use kernel::{c_str, fs, str::CString};
@@ -461,7 +462,7 @@ macro_rules! count_brace_items {
461462
/// impl fs::Context<Self> for Example {
462463
/// type Data = Box<State>;
463464
///
464-
/// kernel::define_fs_params!{Box<State>,
465+
/// kernel::define_fs_params! {Box<State>,
465466
/// {flag, "flag", |s, v| { s.flag = Some(v); Ok(()) } },
466467
/// {flag_no, "flagno", |s, v| { s.flag_no = Some(v); Ok(()) } },
467468
/// {bool, "bool", |s, v| { s.bool_value = Some(v); Ok(()) } },

rust/kernel/gpio.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ pub trait Chip {
7979
///
8080
/// ```
8181
/// # use kernel::prelude::*;
82-
/// use kernel::{device::RawDevice, gpio::{self, Registration}};
82+
/// use kernel::{
83+
/// device::RawDevice,
84+
/// gpio::{self, Registration},
85+
/// };
8386
///
8487
/// struct MyGpioChip;
8588
/// #[vtable]

rust/kernel/hwrng.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ impl<T: Operations> Registration<T> {
9696

9797
let name = CString::try_from_fmt(name)?;
9898

99-
// SAFETY: Registration is pinned and contains allocated and set to zero `bindings::hwrng` structure.
99+
// SAFETY: Registration is pinned and contains allocated and set to zero
100+
// `bindings::hwrng` structure.
100101
Self::init_hwrng(
101102
unsafe { &mut *this.hwrng.get() },
102103
&name,

rust/kernel/io_mem.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ impl Resource {
5656
///
5757
/// Ok(())
5858
/// }
59-
///
6059
/// ```
6160
pub struct IoMem<const SIZE: usize> {
6261
ptr: usize,

0 commit comments

Comments
 (0)