Skip to content

Commit 1dd4191

Browse files
committed
Merge tag 'rust-fixes-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull rust fixes from Miguel Ojeda: "Toolchain and infrastructure: - Pass '-Zunstable-options' flag required by the future Rust 1.95.0 - Fix 'objtool' warning for Rust 1.84.0 'kernel' crate: - 'irq' module: add missing bound detected by the future Rust 1.95.0 - 'list' module: add missing 'unsafe' blocks and placeholder safety comments to macros (an issue for future callers within the crate) 'pin-init' crate: - Clean Clippy warning that changed behavior in the future Rust 1.95.0" * tag 'rust-fixes-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: rust: list: Add unsafe blocks for container_of and safety comments rust: pin-init: replace clippy `expect` with `allow` rust: irq: add `'static` bounds to irq callbacks objtool/rust: add one more `noreturn` Rust function rust: kbuild: pass `-Zunstable-options` for Rust 1.95.0
2 parents d2ba6e9 + 97b281d commit 1dd4191

5 files changed

Lines changed: 32 additions & 15 deletions

File tree

rust/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
570570
$(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
571571
+$(call if_changed_dep,rustc_procmacro)
572572

573+
# `rustc` requires `-Zunstable-options` to use custom target specifications
574+
# since Rust 1.95.0 (https://github.com/rust-lang/rust/pull/151534).
573575
quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
574576
cmd_rustc_library = \
575577
OBJTREE=$(abspath $(objtree)) \
@@ -580,6 +582,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
580582
--crate-type rlib -L$(objtree)/$(obj) \
581583
--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
582584
--sysroot=/dev/null \
585+
-Zunstable-options \
583586
$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
584587
$(cmd_objtool)
585588

rust/kernel/irq/request.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ impl<T: Handler + 'static> Registration<T> {
260260
/// # Safety
261261
///
262262
/// This function should be only used as the callback in `request_irq`.
263-
unsafe extern "C" fn handle_irq_callback<T: Handler>(_irq: i32, ptr: *mut c_void) -> c_uint {
263+
unsafe extern "C" fn handle_irq_callback<T: Handler + 'static>(
264+
_irq: i32,
265+
ptr: *mut c_void,
266+
) -> c_uint {
264267
// SAFETY: `ptr` is a pointer to `Registration<T>` set in `Registration::new`
265268
let registration = unsafe { &*(ptr as *const Registration<T>) };
266269
// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq
@@ -478,7 +481,7 @@ impl<T: ThreadedHandler + 'static> ThreadedRegistration<T> {
478481
/// # Safety
479482
///
480483
/// This function should be only used as the callback in `request_threaded_irq`.
481-
unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>(
484+
unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler + 'static>(
482485
_irq: i32,
483486
ptr: *mut c_void,
484487
) -> c_uint {
@@ -494,7 +497,10 @@ unsafe extern "C" fn handle_threaded_irq_callback<T: ThreadedHandler>(
494497
/// # Safety
495498
///
496499
/// This function should be only used as the callback in `request_threaded_irq`.
497-
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler>(_irq: i32, ptr: *mut c_void) -> c_uint {
500+
unsafe extern "C" fn thread_fn_callback<T: ThreadedHandler + 'static>(
501+
_irq: i32,
502+
ptr: *mut c_void,
503+
) -> c_uint {
498504
// SAFETY: `ptr` is a pointer to `ThreadedRegistration<T>` set in `ThreadedRegistration::new`
499505
let registration = unsafe { &*(ptr as *const ThreadedRegistration<T>) };
500506
// SAFETY: The irq callback is removed before the device is unbound, so the fact that the irq

rust/kernel/list/impl_list_item_mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ macro_rules! impl_has_list_links_self_ptr {
8484
// right type.
8585
unsafe impl$(<$($generics)*>)? $crate::list::HasSelfPtr<$item_type $(, $id)?> for $self {}
8686

87+
// SAFETY: TODO.
8788
unsafe impl$(<$($generics)*>)? $crate::list::HasListLinks$(<$id>)? for $self {
8889
#[inline]
8990
unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut $crate::list::ListLinks$(<$id>)? {
90-
// SAFETY: The caller promises that the pointer is not dangling.
9191
let ptr: *mut $crate::list::ListLinksSelfPtr<$item_type $(, $id)?> =
92+
// SAFETY: The caller promises that the pointer is not dangling.
9293
unsafe { ::core::ptr::addr_of_mut!((*ptr)$(.$field)*) };
9394
ptr.cast()
9495
}
@@ -217,7 +218,7 @@ macro_rules! impl_list_item {
217218
// SAFETY: `me` originates from the most recent call to `prepare_to_insert`, so it
218219
// points at the field `$field` in a value of type `Self`. Thus, reversing that
219220
// operation is still in-bounds of the allocation.
220-
$crate::container_of!(me, Self, $($field).*)
221+
unsafe { $crate::container_of!(me, Self, $($field).*) }
221222
}
222223

223224
// GUARANTEES:
@@ -242,7 +243,7 @@ macro_rules! impl_list_item {
242243
// SAFETY: `me` originates from the most recent call to `prepare_to_insert`, so it
243244
// points at the field `$field` in a value of type `Self`. Thus, reversing that
244245
// operation is still in-bounds of the allocation.
245-
$crate::container_of!(me, Self, $($field).*)
246+
unsafe { $crate::container_of!(me, Self, $($field).*) }
246247
}
247248
}
248249
)*};
@@ -270,9 +271,12 @@ macro_rules! impl_list_item {
270271
// SAFETY: The caller promises that `me` points at a valid value of type `Self`.
271272
let links_field = unsafe { <Self as $crate::list::ListItem<$num>>::view_links(me) };
272273

273-
let container = $crate::container_of!(
274-
links_field, $crate::list::ListLinksSelfPtr<Self, $num>, inner
275-
);
274+
// SAFETY: TODO.
275+
let container = unsafe {
276+
$crate::container_of!(
277+
links_field, $crate::list::ListLinksSelfPtr<Self, $num>, inner
278+
)
279+
};
276280

277281
// SAFETY: By the same reasoning above, `links_field` is a valid pointer.
278282
let self_ptr = unsafe {
@@ -319,9 +323,12 @@ macro_rules! impl_list_item {
319323
// `ListArc` containing `Self` until the next call to `post_remove`. The value cannot
320324
// be destroyed while a `ListArc` reference exists.
321325
unsafe fn view_value(links_field: *mut $crate::list::ListLinks<$num>) -> *const Self {
322-
let container = $crate::container_of!(
323-
links_field, $crate::list::ListLinksSelfPtr<Self, $num>, inner
324-
);
326+
// SAFETY: TODO.
327+
let container = unsafe {
328+
$crate::container_of!(
329+
links_field, $crate::list::ListLinksSelfPtr<Self, $num>, inner
330+
)
331+
};
325332

326333
// SAFETY: By the same reasoning above, `links_field` is a valid pointer.
327334
let self_ptr = unsafe {

rust/pin-init/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,13 +1143,13 @@ pub const unsafe fn init_from_closure<T: ?Sized, E>(
11431143
///
11441144
/// - `*mut U` must be castable to `*mut T` and any value of type `T` written through such a
11451145
/// pointer must result in a valid `U`.
1146-
#[expect(clippy::let_and_return)]
11471146
pub const unsafe fn cast_pin_init<T, U, E>(init: impl PinInit<T, E>) -> impl PinInit<U, E> {
11481147
// SAFETY: initialization delegated to a valid initializer. Cast is valid by function safety
11491148
// requirements.
11501149
let res = unsafe { pin_init_from_closure(|ptr: *mut U| init.__pinned_init(ptr.cast::<T>())) };
11511150
// FIXME: remove the let statement once the nightly-MSRV allows it (1.78 otherwise encounters a
11521151
// cycle when computing the type returned by this function)
1152+
#[allow(clippy::let_and_return)]
11531153
res
11541154
}
11551155

@@ -1159,13 +1159,13 @@ pub const unsafe fn cast_pin_init<T, U, E>(init: impl PinInit<T, E>) -> impl Pin
11591159
///
11601160
/// - `*mut U` must be castable to `*mut T` and any value of type `T` written through such a
11611161
/// pointer must result in a valid `U`.
1162-
#[expect(clippy::let_and_return)]
11631162
pub const unsafe fn cast_init<T, U, E>(init: impl Init<T, E>) -> impl Init<U, E> {
11641163
// SAFETY: initialization delegated to a valid initializer. Cast is valid by function safety
11651164
// requirements.
11661165
let res = unsafe { init_from_closure(|ptr: *mut U| init.__init(ptr.cast::<T>())) };
11671166
// FIXME: remove the let statement once the nightly-MSRV allows it (1.78 otherwise encounters a
11681167
// cycle when computing the type returned by this function)
1168+
#[allow(clippy::let_and_return)]
11691169
res
11701170
}
11711171

tools/objtool/check.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ static bool is_rust_noreturn(const struct symbol *func)
197197
* as well as changes to the source code itself between versions (since
198198
* these come from the Rust standard library).
199199
*/
200-
return str_ends_with(func->name, "_4core3num22from_ascii_radix_panic") ||
200+
return str_ends_with(func->name, "_4core3num20from_str_radix_panic") ||
201+
str_ends_with(func->name, "_4core3num22from_ascii_radix_panic") ||
201202
str_ends_with(func->name, "_4core5sliceSp15copy_from_slice17len_mismatch_fail") ||
202203
str_ends_with(func->name, "_4core6option13expect_failed") ||
203204
str_ends_with(func->name, "_4core6option13unwrap_failed") ||

0 commit comments

Comments
 (0)