mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-28 16:52:18 +00:00
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>
This commit is contained in:
parent
1bae8729e5
commit
9b98be7685
@ -107,7 +107,7 @@ pub unsafe fn call_printk(
|
||||
// SAFETY: TODO.
|
||||
unsafe {
|
||||
bindings::_printk(
|
||||
format_string.as_ptr() as _,
|
||||
format_string.as_ptr(),
|
||||
module_name.as_ptr(),
|
||||
&args as *const _ as *const c_void,
|
||||
);
|
||||
@ -128,7 +128,7 @@ pub fn call_printk_cont(args: fmt::Arguments<'_>) {
|
||||
#[cfg(CONFIG_PRINTK)]
|
||||
unsafe {
|
||||
bindings::_printk(
|
||||
format_strings::CONT.as_ptr() as _,
|
||||
format_strings::CONT.as_ptr(),
|
||||
&args as *const _ as *const c_void,
|
||||
);
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ pub unsafe fn from_char_ptr<'a>(ptr: *const crate::ffi::c_char) -> &'a Self {
|
||||
// to a `NUL`-terminated C string.
|
||||
let len = unsafe { bindings::strlen(ptr) } + 1;
|
||||
// SAFETY: Lifetime guaranteed by the safety precondition.
|
||||
let bytes = unsafe { core::slice::from_raw_parts(ptr as _, len as _) };
|
||||
let bytes = unsafe { core::slice::from_raw_parts(ptr as _, len) };
|
||||
// SAFETY: As `len` is returned by `strlen`, `bytes` does not contain interior `NUL`.
|
||||
// As we have added 1 to `len`, the last byte is known to be `NUL`.
|
||||
unsafe { Self::from_bytes_with_nul_unchecked(bytes) }
|
||||
@ -248,7 +248,7 @@ pub unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &mut CStr {
|
||||
/// Returns a C pointer to the string.
|
||||
#[inline]
|
||||
pub const fn as_char_ptr(&self) -> *const crate::ffi::c_char {
|
||||
self.0.as_ptr() as _
|
||||
self.0.as_ptr()
|
||||
}
|
||||
|
||||
/// Convert the string to a byte slice without the trailing `NUL` byte.
|
||||
@ -838,7 +838,7 @@ pub fn try_from_fmt(args: fmt::Arguments<'_>) -> Result<Self, Error> {
|
||||
// SAFETY: The buffer is valid for read because `f.bytes_written()` is bounded by `size`
|
||||
// (which the minimum buffer size) and is non-zero (we wrote at least the `NUL` terminator)
|
||||
// so `f.bytes_written() - 1` doesn't underflow.
|
||||
let ptr = unsafe { bindings::memchr(buf.as_ptr().cast(), 0, (f.bytes_written() - 1) as _) };
|
||||
let ptr = unsafe { bindings::memchr(buf.as_ptr().cast(), 0, f.bytes_written() - 1) };
|
||||
if !ptr.is_null() {
|
||||
return Err(EINVAL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user