Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: cleanup unnecessary casts

With `long` mapped to `isize`, `size_t`/`__kernel_size_t` mapped to
`usize` and `char` mapped to `u8`, many of the existing casts are no
longer necessary.

Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240913213041.395655-6-gary@garyguo.net
[ Moved `uaccess` changes to the previous commit, since they were
irrefutable patterns that Rust >= 1.82.0 warns about. Removed a
couple casts that now use `c""` literals. Rebased on top of
`rust-next`. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Gary Guo and committed by
Miguel Ojeda
9b98be76 1bae8729

+5 -5
+2 -2
rust/kernel/print.rs
··· 107 107 // SAFETY: TODO. 108 108 unsafe { 109 109 bindings::_printk( 110 - format_string.as_ptr() as _, 110 + format_string.as_ptr(), 111 111 module_name.as_ptr(), 112 112 &args as *const _ as *const c_void, 113 113 ); ··· 128 128 #[cfg(CONFIG_PRINTK)] 129 129 unsafe { 130 130 bindings::_printk( 131 - format_strings::CONT.as_ptr() as _, 131 + format_strings::CONT.as_ptr(), 132 132 &args as *const _ as *const c_void, 133 133 ); 134 134 }
+3 -3
rust/kernel/str.rs
··· 189 189 // to a `NUL`-terminated C string. 190 190 let len = unsafe { bindings::strlen(ptr) } + 1; 191 191 // SAFETY: Lifetime guaranteed by the safety precondition. 192 - let bytes = unsafe { core::slice::from_raw_parts(ptr as _, len as _) }; 192 + let bytes = unsafe { core::slice::from_raw_parts(ptr as _, len) }; 193 193 // SAFETY: As `len` is returned by `strlen`, `bytes` does not contain interior `NUL`. 194 194 // As we have added 1 to `len`, the last byte is known to be `NUL`. 195 195 unsafe { Self::from_bytes_with_nul_unchecked(bytes) } ··· 248 248 /// Returns a C pointer to the string. 249 249 #[inline] 250 250 pub const fn as_char_ptr(&self) -> *const crate::ffi::c_char { 251 - self.0.as_ptr() as _ 251 + self.0.as_ptr() 252 252 } 253 253 254 254 /// Convert the string to a byte slice without the trailing `NUL` byte. ··· 838 838 // SAFETY: The buffer is valid for read because `f.bytes_written()` is bounded by `size` 839 839 // (which the minimum buffer size) and is non-zero (we wrote at least the `NUL` terminator) 840 840 // so `f.bytes_written() - 1` doesn't underflow. 841 - let ptr = unsafe { bindings::memchr(buf.as_ptr().cast(), 0, (f.bytes_written() - 1) as _) }; 841 + let ptr = unsafe { bindings::memchr(buf.as_ptr().cast(), 0, f.bytes_written() - 1) }; 842 842 if !ptr.is_null() { 843 843 return Err(EINVAL); 844 844 }