Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 92797e9

Browse files
nbdd0121ojeda
authored andcommittedDec 16, 2024
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>
1 parent 4462c2b commit 92797e9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed
 

‎rust/kernel/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub unsafe fn call_printk(
107107
// SAFETY: TODO.
108108
unsafe {
109109
bindings::_printk(
110-
format_string.as_ptr() as _,
110+
format_string.as_ptr(),
111111
module_name.as_ptr(),
112112
&args as *const _ as *const c_void,
113113
);
@@ -128,7 +128,7 @@ pub fn call_printk_cont(args: fmt::Arguments<'_>) {
128128
#[cfg(CONFIG_PRINTK)]
129129
unsafe {
130130
bindings::_printk(
131-
format_strings::CONT.as_ptr() as _,
131+
format_strings::CONT.as_ptr(),
132132
&args as *const _ as *const c_void,
133133
);
134134
}

‎rust/kernel/str.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl CStr {
189189
// to a `NUL`-terminated C string.
190190
let len = unsafe { bindings::strlen(ptr) } + 1;
191191
// 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) };
193193
// SAFETY: As `len` is returned by `strlen`, `bytes` does not contain interior `NUL`.
194194
// As we have added 1 to `len`, the last byte is known to be `NUL`.
195195
unsafe { Self::from_bytes_with_nul_unchecked(bytes) }
@@ -248,7 +248,7 @@ impl CStr {
248248
/// Returns a C pointer to the string.
249249
#[inline]
250250
pub const fn as_char_ptr(&self) -> *const crate::ffi::c_char {
251-
self.0.as_ptr() as _
251+
self.0.as_ptr()
252252
}
253253

254254
/// Convert the string to a byte slice without the trailing `NUL` byte.
@@ -838,7 +838,7 @@ impl CString {
838838
// SAFETY: The buffer is valid for read because `f.bytes_written()` is bounded by `size`
839839
// (which the minimum buffer size) and is non-zero (we wrote at least the `NUL` terminator)
840840
// 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) };
842842
if !ptr.is_null() {
843843
return Err(EINVAL);
844844
}

0 commit comments

Comments
 (0)
Failed to load comments.