History

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

Linus Torvalds committed 8 months ago

Commit 1dd41912 parents d2ba6e9 97b281d5 files · +32 −15Browse files

Unified · Split

5 files
  1. rust/Makefile +3 −0
  2. rust/kernel/irq/request.rs +9 −3
  3. rust/kernel/list/impl_list_item_mod.rs +16 −9
  4. rust/pin-init/src/lib.rs +2 −2
  5. tools/objtool/check.c +2 −1
rust/Makefile+3−0
@@ -570,6 +570,8 @@ $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \ · 569 unmodified lines
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 · 4 unmodified lines
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+9−3
@@ -260,7 +260,10 @@ impl<T: Handler + 'static> Registration<T> { · 259 unmodified lines
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> { · 211 unmodified lines
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>( · 9 unmodified lines
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+16−9
@@ -84,11 +84,12 @@ macro_rules! impl_has_list_links_self_ptr { · 83 unmodified lines
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 { · 122 unmodified lines
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 { · 18 unmodified lines
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 { · 21 unmodified lines
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 { · 40 unmodified lines
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+2−2
@@ -1143,13 +1143,13 @@ pub const unsafe fn init_from_closure<T: ?Sized, E>( · 1142 unmodified lines
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 · 3 unmodified lines
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+2−1
@@ -197,7 +197,8 @@ static bool is_rust_noreturn(const struct symbol *func) · 196 unmodified lines
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") ||

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t