From nobody Sat Oct 11 04:07:54 2025 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C921261575; Wed, 11 Jun 2025 10:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637421; cv=none; b=VAGQW+NYGujplLFk6Namw6iw8NmM/gfyo0NGLs0s7bJwOoXq7dX/FeqO/1n/TsFP/D/5wXexxq91B0G276uWXa3eS3eSA75IDP1pmHW4Mip8RkqdMXa+ZKBgC4Jv1rpXf2f3Z+0V+NSHcFgEYsURCpZWoGuP2H/aTrAM0B4NAD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637421; c=relaxed/simple; bh=OJYOsjrfAtnUZ6RRUjjQ47/8ulOY3IDENy/rKlhUTOU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E9RePRnHbkBeecxgYaVVHxvwIWL/6VGBX0VqhSDQgDHhZVPtJ8oiDNfUBe42unBRdjO4as5fOOkoSUs5BuxOtPYahZ5pyun6tg2uHweqv1UBDj2398OSPMbaBbTtXEiX0r8ZMO+TGfQgQMOZSDIN/lDuM+bde3yjFNEbIzezo0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LwpPNmXH; arc=none smtp.client-ip=209.85.160.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LwpPNmXH" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-4a4312b4849so78949381cf.1; Wed, 11 Jun 2025 03:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749637418; x=1750242218; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=iOBQpqIx6F/1ZiBVhO4bL8OOA5fQnbUtGxiAE50g8ds=; b=LwpPNmXHBhdaVrvYUFINfriCmzUpdTYPi+BTb8Ye5r5j5aFItfHhKaBKhygwqYUWpf jd9pzVXjv5rXD7e9ohU4+N2rbxl/kSVvSJ8XuJV+3EQIgVPxAm59P9TlUj/Jq4Z94IXk CREyCX/sHNvbWggvcSUB9fgQsPeYwhewxLaAGVuYkDK0xC6vFpmonCD59Bl7SJD1XCH1 +IJcan3WYH3tVqeORsf1M4H+pV3SX6YPYKN3lL9tbTWWweqwEKhX245LF+hqbzC9q7jZ shoG9Qsza6KTYlhr3aJffv4OP+KRV8tnJW2p/PEi4qbQWCYPGqNOcJGCoVizNZYYYho9 YeNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749637418; x=1750242218; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iOBQpqIx6F/1ZiBVhO4bL8OOA5fQnbUtGxiAE50g8ds=; b=DOp54AJWAX8isBaVWDETAWKiHNyu/4BKLOvRpHKtbum3POLgTSNB2X9uvl0cd3zleB L9py1anMjwtx3BS8q9W029wl2a/ssg4ycXY8/DFbpxqEQ4tks9e13m+EV5lz/jqFDlAw zDE5Vzc89lQvVE1E61d6Mcb/ESLTLP9tNKIovD1zL4M/q+xoVgJ22mTLkOpA0yaWRF8i CPi9Ffrn6ESXuRE6/H3yylhswsXnVgc3X64CTWJDio+jLXzvAwqIwyCgWmxU9dA6Gy7t Tqmj96e3Hz4EH83VfftleQLlICvag92gWxp+UXety4ZHsULVhTcXJtXA+giaXWWJBiOZ 59/w== X-Forwarded-Encrypted: i=1; AJvYcCUEwtNEex+tDZw5HVmUoVrtuWPY/xlzGrVOTKnLAleTeMZlZ+np1xEv+V+AuEcoOjEdwDk7c6ms2ynfIL0a@vger.kernel.org, AJvYcCUf5q4HDoexZ3UGrPNL0qTj2R+nOljOvs5dvwEpLwWaQGklXGKzirXLpk4bKXzNejAqy3o2kMF1KJhm@vger.kernel.org, AJvYcCV1xqWzNOqCEdDlqn/Gxg32DhUoUQgP+ZgDor6q28+XVaNG4/dmpIIECNpgLQ/GOzvQHrJJkofCt22dKEd3a0zG@vger.kernel.org, AJvYcCWz/8EtXF3vwkuu9fVSuhr84Le7CpaKtS9CU4YLa8wb6kIRbdSJQOG0l7K9mDJkSL0SQS8jWizf@vger.kernel.org, AJvYcCX8+OTt+tlHlgZJDSo8Z6r92M2Fdf1jOKR2iRQnTAQfB0LpY2Yvg7seq4GtwibfaN+KwmGHV+Bvu5w5zymsLCQ=@vger.kernel.org, AJvYcCXUT/MmSsw6JnjE1Uka9wutMzwyocpMXkZzpDL54DnjFOqMiN3akePfhYFZE+UNR5ocTUn+m3WE/6JV@vger.kernel.org, AJvYcCXh+5sEskd7aaNVhajH3UQCUw/xWu4DqeueY03NDufHoBfeXLrywZX8iE9mENUYNBLn4/hFdWjTPdYQNcA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1bWWVn1UiVH3DCgZ6/MEEGRlxRYDx9cb+RqZH7AHANL+leFEv SvVG05cISFv5MPZepX9NbA0//D3ANyVRgeoX1vfASv305cYXBFpY5Cl9 X-Gm-Gg: ASbGncuew8ttkhoYszyUHe4brnIvSvGoehJEyDUtGGgZyIJA0mdPfN/yseBVmlb/S8a RwfhLnaalZhHdTpEP9FTIHV19/cwmvsreq3hQIS1kDp9gg2LhQJCxMkk7pa7Dtg4xsUO63isem5 kAQr88hIlvs/gssi9gebia8wVTmbNYIP8I1NR1xxnlUBUY7UYqUnWJAIoVz84RS7B0tWBE4HYdF k93caY8+PslcKzKeXhdqbZJy6dSwkcRv9W2+jvoxSYCTCD731tfDFlBiLpH0UHPmz1KgYkGK5Me f2YtSdZbCxtkbzJdyqv92ZnocoNGFRKblzp2mOXJkgb8JHWujS/D6P0WL4HMM80AOJ8= X-Google-Smtp-Source: AGHT+IFcse7lS2d06z+yGpc6PVUSpHw7r2X3k7qm6/B/EuSzPugzslgtGfYF4YSsXkq8xBoRXuFd5g== X-Received: by 2002:ac8:6f06:0:b0:494:a235:fcbb with SMTP id d75a77b69052e-4a713c2e7c1mr46484781cf.29.1749637417946; Wed, 11 Jun 2025 03:23:37 -0700 (PDT) Received: from 1.0.0.127.in-addr.arpa ([204.93.149.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a61114ff18sm85664341cf.6.2025.06.11.03.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 03:23:37 -0700 (PDT) From: Tamir Duberstein Date: Wed, 11 Jun 2025 06:23:25 -0400 Subject: [PATCH v11 1/6] rust: enable `clippy::ptr_as_ptr` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-ptr-as-ptr-v11-1-ce5b41c6e9c6@gmail.com> References: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> In-Reply-To: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori , Nicolas Schier , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Benno Lossin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , John Stultz , Stephen Boyd , Lorenzo Stoakes , "Liam R. Howlett" , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-mm@kvack.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev In Rust 1.51.0, Clippy introduced the `ptr_as_ptr` lint [1]: > Though `as` casts between raw pointers are not terrible, > `pointer::cast` is safer because it cannot accidentally change the > pointer's mutability, nor cast the pointer to other types like `usize`. There are a few classes of changes required: - Modules generated by bindgen are marked `#[allow(clippy::ptr_as_ptr)]`. - Inferred casts (` as _`) are replaced with `.cast()`. - Ascribed casts (` as *... T`) are replaced with `.cast::()`. - Multistep casts from references (` as *const _ as *const T`) are replaced with `core::ptr::from_ref(&x).cast()` with or without `::` according to the previous rules. The `core::ptr::from_ref` call is required because `(x as *const _).cast::()` results in inference failure. - Native literal C strings are replaced with `c_str!().as_char_ptr()`. - `*mut *mut T as _` is replaced with `let *mut *const T =3D (*mut *mut T)`.cast();` since pointer to pointer can be confusing. Apply these changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr = [1] Reviewed-by: Benno Lossin Reviewed-by: Boqun Feng Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/bindings/lib.rs | 1 + rust/kernel/alloc/allocator_test.rs | 2 +- rust/kernel/alloc/kvec.rs | 4 ++-- rust/kernel/device.rs | 4 ++-- rust/kernel/devres.rs | 2 +- rust/kernel/dma.rs | 4 ++-- rust/kernel/error.rs | 2 +- rust/kernel/firmware.rs | 3 ++- rust/kernel/fs/file.rs | 2 +- rust/kernel/kunit.rs | 11 +++++++---- rust/kernel/list/impl_list_item_mod.rs | 2 +- rust/kernel/pci.rs | 2 +- rust/kernel/platform.rs | 4 +++- rust/kernel/print.rs | 6 +++--- rust/kernel/seq_file.rs | 2 +- rust/kernel/str.rs | 2 +- rust/kernel/sync/poll.rs | 2 +- rust/kernel/time/hrtimer/pin.rs | 2 +- rust/kernel/time/hrtimer/pin_mut.rs | 2 +- rust/kernel/workqueue.rs | 6 +++--- rust/uapi/lib.rs | 1 + 22 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 35e6e5240c61..21cc6e312ec9 100644 --- a/Makefile +++ b/Makefile @@ -484,6 +484,7 @@ export rust_common_flags :=3D --edition=3D2021 \ -Wclippy::needless_bitwise_bool \ -Aclippy::needless_lifetimes \ -Wclippy::no_mangle_with_rust_abi \ + -Wclippy::ptr_as_ptr \ -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs index a08eb5518cac..81b6c7aa4916 100644 --- a/rust/bindings/lib.rs +++ b/rust/bindings/lib.rs @@ -25,6 +25,7 @@ )] =20 #[allow(dead_code)] +#[allow(clippy::ptr_as_ptr)] #[allow(clippy::undocumented_unsafe_blocks)] #[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_tran= smutes))] mod bindings_raw { diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/alloca= tor_test.rs index d19c06ef0498..a3074480bd8d 100644 --- a/rust/kernel/alloc/allocator_test.rs +++ b/rust/kernel/alloc/allocator_test.rs @@ -82,7 +82,7 @@ unsafe fn realloc( =20 // SAFETY: Returns either NULL or a pointer to a memory allocation= that satisfies or // exceeds the given size and alignment requirements. - let dst =3D unsafe { libc_aligned_alloc(layout.align(), layout.siz= e()) } as *mut u8; + let dst =3D unsafe { libc_aligned_alloc(layout.align(), layout.siz= e()) }.cast::(); let dst =3D NonNull::new(dst).ok_or(AllocError)?; =20 if flags.contains(__GFP_ZERO) { diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 1a0dd852a468..0477041cbc03 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -288,7 +288,7 @@ pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUnin= it] { // - `self.len` is smaller than `self.capacity` by the type invari= ant and hence, the // resulting pointer is guaranteed to be part of the same alloca= ted object. // - `self.len` can not overflow `isize`. - let ptr =3D unsafe { self.as_mut_ptr().add(self.len) } as *mut May= beUninit; + let ptr =3D unsafe { self.as_mut_ptr().add(self.len) }.cast::>(); =20 // SAFETY: The memory between `self.len` and `self.capacity` is gu= aranteed to be allocated // and valid, but uninitialized. @@ -847,7 +847,7 @@ fn drop(&mut self) { // - `ptr` points to memory with at least a size of `size_of::(= ) * len`, // - all elements within `b` are initialized values of `T`, // - `len` does not exceed `isize::MAX`. - unsafe { Vec::from_raw_parts(ptr as _, len, len) } + unsafe { Vec::from_raw_parts(ptr.cast(), len, len) } } } =20 diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index dea06b79ecb5..5c946af3a4d5 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -195,10 +195,10 @@ unsafe fn printk(&self, klevel: &[u8], msg: fmt::Argu= ments<'_>) { #[cfg(CONFIG_PRINTK)] unsafe { bindings::_dev_printk( - klevel as *const _ as *const crate::ffi::c_char, + klevel.as_ptr().cast::(), self.as_raw(), c_str!("%pA").as_char_ptr(), - &msg as *const _ as *const crate::ffi::c_void, + core::ptr::from_ref(&msg).cast::(), ) }; } diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 0f79a2ec9474..e5475ff62da3 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -154,7 +154,7 @@ fn remove_action(this: &Arc) { =20 #[allow(clippy::missing_safety_doc)] unsafe extern "C" fn devres_callback(ptr: *mut kernel::ffi::c_void) { - let ptr =3D ptr as *mut DevresInner; + let ptr =3D ptr.cast::>(); // Devres owned this memory; now that we received the callback, dr= op the `Arc` and hence the // reference. // SAFETY: Safe, since we leaked an `Arc` reference to devm_add_ac= tion() in diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index a33261c62e0c..666bf2d64f9a 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -186,7 +186,7 @@ pub fn alloc_attrs( dev: dev.into(), dma_handle, count, - cpu_addr: ret as *mut T, + cpu_addr: ret.cast::(), dma_attrs, }) } @@ -293,7 +293,7 @@ fn drop(&mut self) { bindings::dma_free_attrs( self.dev.as_raw(), size, - self.cpu_addr as _, + self.cpu_addr.cast(), self.dma_handle, self.dma_attrs.as_raw(), ) diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 3dee3139fcd4..afcb00cb6a75 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -153,7 +153,7 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_stat= us_t { /// Returns the error encoded as a pointer. pub fn to_ptr(self) -> *mut T { // SAFETY: `self.0` is a valid error due to its invariant. - unsafe { bindings::ERR_PTR(self.0.get() as _) as *mut _ } + unsafe { bindings::ERR_PTR(self.0.get() as _).cast() } } =20 /// Returns a string representing the error, if one exists. diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs index 2494c96e105f..94fa1ea17ef0 100644 --- a/rust/kernel/firmware.rs +++ b/rust/kernel/firmware.rs @@ -62,10 +62,11 @@ impl Firmware { fn request_internal(name: &CStr, dev: &Device, func: FwFunc) -> Result= { let mut fw: *mut bindings::firmware =3D core::ptr::null_mut(); let pfw: *mut *mut bindings::firmware =3D &mut fw; + let pfw: *mut *const bindings::firmware =3D pfw.cast(); =20 // SAFETY: `pfw` is a valid pointer to a NULL initialized `binding= s::firmware` pointer. // `name` and `dev` are valid as by their type invariants. - let ret =3D unsafe { func.0(pfw as _, name.as_char_ptr(), dev.as_r= aw()) }; + let ret =3D unsafe { func.0(pfw, name.as_char_ptr(), dev.as_raw())= }; if ret !=3D 0 { return Err(Error::from_errno(ret)); } diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index 72d84fb0e266..e9bfbad00755 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -366,7 +366,7 @@ fn deref(&self) -> &LocalFile { // // By the type invariants, there are no `fdget_pos` calls that did= not take the // `f_pos_lock` mutex. - unsafe { LocalFile::from_raw_file(self as *const File as *const bi= ndings::file) } + unsafe { LocalFile::from_raw_file((self as *const Self).cast()) } } } =20 diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs index 4b8cdcb21e77..6930e86d98a9 100644 --- a/rust/kernel/kunit.rs +++ b/rust/kernel/kunit.rs @@ -9,6 +9,9 @@ use crate::prelude::*; use core::{ffi::c_void, fmt}; =20 +#[cfg(CONFIG_PRINTK)] +use crate::c_str; + /// Prints a KUnit error-level message. /// /// Public but hidden since it should only be used from KUnit generated co= de. @@ -19,8 +22,8 @@ pub fn err(args: fmt::Arguments<'_>) { #[cfg(CONFIG_PRINTK)] unsafe { bindings::_printk( - c"\x013%pA".as_ptr() as _, - &args as *const _ as *const c_void, + c_str!("\x013%pA").as_char_ptr(), + core::ptr::from_ref(&args).cast::(), ); } } @@ -35,8 +38,8 @@ pub fn info(args: fmt::Arguments<'_>) { #[cfg(CONFIG_PRINTK)] unsafe { bindings::_printk( - c"\x016%pA".as_ptr() as _, - &args as *const _ as *const c_void, + c_str!("\x016%pA").as_char_ptr(), + core::ptr::from_ref(&args).cast::(), ); } } diff --git a/rust/kernel/list/impl_list_item_mod.rs b/rust/kernel/list/impl= _list_item_mod.rs index a0438537cee1..1f9498c1458f 100644 --- a/rust/kernel/list/impl_list_item_mod.rs +++ b/rust/kernel/list/impl_list_item_mod.rs @@ -34,7 +34,7 @@ pub unsafe trait HasListLinks { unsafe fn raw_get_list_links(ptr: *mut Self) -> *mut ListLinks { // SAFETY: The caller promises that the pointer is valid. The impl= ementer promises that the // `OFFSET` constant is correct. - unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut ListLinks } + unsafe { ptr.cast::().add(Self::OFFSET).cast() } } } =20 diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 8435f8132e38..33ae0bdc433d 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -78,7 +78,7 @@ extern "C" fn probe_callback( // Let the `struct pci_dev` own a reference of the driver'= s private data. // SAFETY: By the type invariant `pdev.as_raw` returns a v= alid pointer to a // `struct pci_dev`. - unsafe { bindings::pci_set_drvdata(pdev.as_raw(), data.int= o_foreign() as _) }; + unsafe { bindings::pci_set_drvdata(pdev.as_raw(), data.int= o_foreign().cast()) }; } Err(err) =3D> return Error::to_errno(err), } diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 5b21fa517e55..4b06f9fbc172 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -69,7 +69,9 @@ extern "C" fn probe_callback(pdev: *mut bindings::platfor= m_device) -> kernel::ff // Let the `struct platform_device` own a reference of the= driver's private data. // SAFETY: By the type invariant `pdev.as_raw` returns a v= alid pointer to a // `struct platform_device`. - unsafe { bindings::platform_set_drvdata(pdev.as_raw(), dat= a.into_foreign() as _) }; + unsafe { + bindings::platform_set_drvdata(pdev.as_raw(), data.int= o_foreign().cast()) + }; } Err(err) =3D> return Error::to_errno(err), } diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs index 9783d960a97a..ecdcee43e5a5 100644 --- a/rust/kernel/print.rs +++ b/rust/kernel/print.rs @@ -25,7 +25,7 @@ // SAFETY: The C contract guarantees that `buf` is valid if it's less = than `end`. let mut w =3D unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast())= }; // SAFETY: TODO. - let _ =3D w.write_fmt(unsafe { *(ptr as *const fmt::Arguments<'_>) }); + let _ =3D w.write_fmt(unsafe { *ptr.cast::>() }); w.pos().cast() } =20 @@ -109,7 +109,7 @@ pub unsafe fn call_printk( bindings::_printk( format_string.as_ptr(), module_name.as_ptr(), - &args as *const _ as *const c_void, + core::ptr::from_ref(&args).cast::(), ); } } @@ -129,7 +129,7 @@ pub fn call_printk_cont(args: fmt::Arguments<'_>) { unsafe { bindings::_printk( format_strings::CONT.as_ptr(), - &args as *const _ as *const c_void, + core::ptr::from_ref(&args).cast::(), ); } } diff --git a/rust/kernel/seq_file.rs b/rust/kernel/seq_file.rs index 7a9403eb6e5b..8f199b1a3bb1 100644 --- a/rust/kernel/seq_file.rs +++ b/rust/kernel/seq_file.rs @@ -37,7 +37,7 @@ pub fn call_printf(&self, args: core::fmt::Arguments<'_>)= { bindings::seq_printf( self.inner.get(), c_str!("%pA").as_char_ptr(), - &args as *const _ as *const crate::ffi::c_void, + core::ptr::from_ref(&args).cast::(), ); } } diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index a927db8e079c..6a3cb607b332 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -237,7 +237,7 @@ pub unsafe fn from_char_ptr<'a>(ptr: *const crate::ffi:= :c_char) -> &'a Self { // to a `NUL`-terminated C string. let len =3D unsafe { bindings::strlen(ptr) } + 1; // SAFETY: Lifetime guaranteed by the safety precondition. - let bytes =3D unsafe { core::slice::from_raw_parts(ptr as _, len) = }; + let bytes =3D unsafe { core::slice::from_raw_parts(ptr.cast(), len= ) }; // SAFETY: As `len` is returned by `strlen`, `bytes` does not cont= ain 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) } diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs index d7e6e59e124b..339ab6097be7 100644 --- a/rust/kernel/sync/poll.rs +++ b/rust/kernel/sync/poll.rs @@ -73,7 +73,7 @@ pub fn register_wait(&mut self, file: &File, cv: &PollCon= dVar) { // be destroyed, the destructor must run. That destructor firs= t removes all waiters, // and then waits for an rcu grace period. Therefore, `cv.wait= _queue_head` is valid for // long enough. - unsafe { qproc(file.as_ptr() as _, cv.wait_queue_head.get(), s= elf.0.get()) }; + unsafe { qproc(file.as_ptr().cast(), cv.wait_queue_head.get(),= self.0.get()) }; } } } diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin= .rs index 293ca9cf058c..2f29fd75d63a 100644 --- a/rust/kernel/time/hrtimer/pin.rs +++ b/rust/kernel/time/hrtimer/pin.rs @@ -79,7 +79,7 @@ impl<'a, T> RawHrTimerCallback for Pin<&'a T> =20 unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { // `HrTimer` is `repr(C)` - let timer_ptr =3D ptr as *mut HrTimer; + let timer_ptr =3D ptr.cast::>(); =20 // SAFETY: By the safety requirement of this function, `timer_ptr` // points to a `HrTimer` contained in an `T`. diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer= /pin_mut.rs index 6033572d35ad..d05d68be55e9 100644 --- a/rust/kernel/time/hrtimer/pin_mut.rs +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -83,7 +83,7 @@ impl<'a, T> RawHrTimerCallback for Pin<&'a mut T> =20 unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrt= imer_restart { // `HrTimer` is `repr(C)` - let timer_ptr =3D ptr as *mut HrTimer; + let timer_ptr =3D ptr.cast::>(); =20 // SAFETY: By the safety requirement of this function, `timer_ptr` // points to a `HrTimer` contained in an `T`. diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index d092112d843f..de61374e36bd 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -170,7 +170,7 @@ impl Queue { pub unsafe fn from_raw<'a>(ptr: *const bindings::workqueue_struct) -> = &'a Queue { // SAFETY: The `Queue` type is `#[repr(transparent)]`, so the poin= ter cast is valid. The // caller promises that the pointer is not dangling. - unsafe { &*(ptr as *const Queue) } + unsafe { &*ptr.cast::() } } =20 /// Enqueues a work item. @@ -522,7 +522,7 @@ unsafe impl WorkItemPointer for A= rc { unsafe extern "C" fn run(ptr: *mut bindings::work_struct) { // The `__enqueue` method always uses a `work_struct` stored in a = `Work`. - let ptr =3D ptr as *mut Work; + let ptr =3D ptr.cast::>(); // SAFETY: This computes the pointer that `__enqueue` got from `Ar= c::into_raw`. let ptr =3D unsafe { T::work_container_of(ptr) }; // SAFETY: This pointer comes from `Arc::into_raw` and we've been = given back ownership. @@ -575,7 +575,7 @@ unsafe impl WorkItemPointer for P= in> { unsafe extern "C" fn run(ptr: *mut bindings::work_struct) { // The `__enqueue` method always uses a `work_struct` stored in a = `Work`. - let ptr =3D ptr as *mut Work; + let ptr =3D ptr.cast::>(); // SAFETY: This computes the pointer that `__enqueue` got from `Ar= c::into_raw`. let ptr =3D unsafe { T::work_container_of(ptr) }; // SAFETY: This pointer comes from `Arc::into_raw` and we've been = given back ownership. diff --git a/rust/uapi/lib.rs b/rust/uapi/lib.rs index c98d7a8cde77..e79a1f49f055 100644 --- a/rust/uapi/lib.rs +++ b/rust/uapi/lib.rs @@ -14,6 +14,7 @@ #![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))] #![allow( clippy::all, + clippy::ptr_as_ptr, clippy::undocumented_unsafe_blocks, dead_code, missing_docs, --=20 2.49.0 From nobody Sat Oct 11 04:07:54 2025 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A65972638A2; Wed, 11 Jun 2025 10:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637423; cv=none; b=f1KA0Vi55qH/AaiKbiTR3uuBDE9O0qIUo6Eb5y0uElUJNDF0ZTzvthrnI1HR2rIQJzB+LmnEzr/tT2yRq0NgtxViehGqDGu8c3aSKBSM/tNUEeu4G7UgQbE7xPG5xhEZoo7xFKUUq71J8gqmTp/gyMVBb97/Q7pfapscf/9cLwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637423; c=relaxed/simple; bh=iMyHvs/bU8dY+E8Cxnt2IYFYvKollBBgl5WN+ddYXVA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ykh6RsNMtjlDYt8PSidAXRbUzSCMCJkpd0Mz+k5hugDQn8j4ASI6ioCLELapg1gVfFqrQ3NEli2fbl8NZKkltOpdhRKPC+zPkr7Ds9GRXCdViw62sDRYW2CTm/D6+Q+vW7lymtW+NpZUQEXYYbK2c79k1+sy0ovbyRLsyCMFmcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KhCR7hqR; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KhCR7hqR" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4a442a3a2bfso114616361cf.1; Wed, 11 Jun 2025 03:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749637420; x=1750242220; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3zUYH66sAi4M6SnRnDRUP9N7P8+78tvCpZpLM0hP8f0=; b=KhCR7hqRBM9fM9e0QDfnUoYv8MvHmISPCRUQ2PZclhHz6u10iShE8mOSy6cypaEeF3 riEmRRmjIawDoZq8Dos28zN5gJ8xRxOGfM6jwAN9xltJnxeKnyl8BKkDuoIvYqzO9JGd T6CvFDTxds3eKvyYtwWH5J5ShFX30L/F2c7hH8VTTo+UPPLBa8b72oxYk/uhZ6KOB+u6 AWHzyKESnLHIcTynf0U8yddj4SfcZKSap51lZgWinCsbpLeI8NGJxFdwSphs5TCvqZkz p/R2j6f/vZ3dwhrNuIw3irDHOdLZDVO8gQH+VD/1dfK9PMq7AwZj2Q3AubJf+1R77PET 2V6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749637420; x=1750242220; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3zUYH66sAi4M6SnRnDRUP9N7P8+78tvCpZpLM0hP8f0=; b=sia66U0O9hK2ufl3ibnsZEH+uVFeNFAaNfTEBHLvir5BTNjn2IPfRye1TGxKc5a5O7 gn/J3q5vCXlIjTH2vGJiFprtvjuuKJglo98Es9P0hMMQ9xW2ere1abtmBbf3yUPkYJq2 F3hOd8YNTKDAZNX7y4JUI4CoeI0+csyhrgN6p6Fefsg6lag1wmR6jQtD+qitbp3Ms/kE O3KCY2rsegrFwETeUFcZbH+zR4jp+ghXgrUfv1b3aGf78Yj5Oz6jwNlsz+kahuAX5Y++ UK73ZYKHDP6i2Sin4s4wq7LRsw/ScsciFhX2EGZi++7pRQzF+CXlEoKCp9GPrad5FfeZ SNhg== X-Forwarded-Encrypted: i=1; AJvYcCUnnRrEc/f6PocK+Pzz8U8AAWfl5jms83j58FO/+XBx+dT0w3NpIv0MM9fghuGG9QAJuiHOIWwupu0bdas6@vger.kernel.org, AJvYcCVUQSd9qkaTiwbB9RtfHfXAyoYn4XaPM2zSlXr+Et977WQp3pGIK/IVVk83kHyjRcExGTSZlp9Qj1ZqnzrkQAM=@vger.kernel.org, AJvYcCVX3782oC9h/10WG6FkTPdRiKW34vt2sE5Fn3xf5Ff/U9G1m66z8ctobk3LD18jh7m/o8K7eFPnZkIB@vger.kernel.org, AJvYcCVaahPHimCYW6xI/qF79WYKdd/ShUtUa9HLsZZEev0Wo/rKuXnqwNzJ1FWdMtSUqClXbTP1iL2FlyFvkAQ=@vger.kernel.org, AJvYcCWGHn5iaNnjZygG59lr0xZRX5Qy2eRt4MIvJu+i5H5iESqXaH20zu4OLWZJ7zpIji4Vl8OzwCR6wEj5@vger.kernel.org, AJvYcCWUXEbXhMXo/LyTrvNhgfV3AxmqaTTl/ATgn955m51bAKs+Ob3D9sUiR6xcDGc7YlaRzuCzkMHjezdvW7aKretE@vger.kernel.org, AJvYcCXaORW1ppXdoCOMpq9FFnJbtFp/jWBPemzy3U4H1x7V/X5hPcTvNNK8Mp6UhKyGF3FPuxiiJhst@vger.kernel.org X-Gm-Message-State: AOJu0Yz1x9RdySZ7zG6C6/haZj4KRO0uQAW7LExs8HbfJ7Q9HkV7wWR4 rEgjc9zR1POF5MJ5zBtnoU0k21o6DHqkDLOQ4oGY7KlSdKEGOYE4JEH6 X-Gm-Gg: ASbGncvRkzANlR8lgWxsfokTNHfclFu/MpLWFy5vuILGGkFwK7SwT92eP8o7NAJk2Ig aiHqUUdhLnVcikIjnbZQVFH3pBekd9KAOP3pAIsqE825NI20Pl+NJpUme8bfiG8P6Tl2fZyVbPh WI4r29mPur1bw75tiZbekZs046KlaqSP4RomgKtO61HBRyd3+8WOcEuTOCMc1VXOQOU4RBQZ9+A a7g2tJySbhVwZ4sCsxs3gzOG531G8ctQBfzSumiHyi0Yak4SJT8Nhi0HymItnA/8zGxCE4pvd98 r3SvOKhncOf5JOeZnIOgX2CH4TVa5uZfksLYvcbEkUC2uunfxqptreNyRU+1/FBnlvo= X-Google-Smtp-Source: AGHT+IGodjTiDzYzaYbdpnH5N4FiwK0k6INV5kLplUVd33gCvZuYk755vGupfng1qLMMcQ+unK6ODg== X-Received: by 2002:a05:622a:1929:b0:476:b7cf:4d42 with SMTP id d75a77b69052e-4a714c5a834mr32371381cf.27.1749637420294; Wed, 11 Jun 2025 03:23:40 -0700 (PDT) Received: from 1.0.0.127.in-addr.arpa ([204.93.149.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a61114ff18sm85664341cf.6.2025.06.11.03.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 03:23:39 -0700 (PDT) From: Tamir Duberstein Date: Wed, 11 Jun 2025 06:23:26 -0400 Subject: [PATCH v11 2/6] rust: enable `clippy::ptr_cast_constness` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-ptr-as-ptr-v11-2-ce5b41c6e9c6@gmail.com> References: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> In-Reply-To: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori , Nicolas Schier , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Benno Lossin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , John Stultz , Stephen Boyd , Lorenzo Stoakes , "Liam R. Howlett" , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-mm@kvack.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev In Rust 1.72.0, Clippy introduced the `ptr_cast_constness` lint [1]: > Though `as` casts between raw pointers are not terrible, > `pointer::cast_mut` and `pointer::cast_const` are safer because they > cannot accidentally cast the pointer to another type. There are only 3 affected sites: - `*mut T as *const U as *mut U` becomes `(*mut T).cast()`. - `&self as *const Self as *mut Self` becomes `core::ptr::from_ref(self).cast_mut()`. - `*const T as *mut _` becommes `(*const T).cast_mut()`. Apply these changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_co= nstness [1] Reviewed-by: Benno Lossin Reviewed-by: Boqun Feng Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/kernel/block/mq/request.rs | 4 ++-- rust/kernel/drm/device.rs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 21cc6e312ec9..5eeddfbf5900 100644 --- a/Makefile +++ b/Makefile @@ -485,6 +485,7 @@ export rust_common_flags :=3D --edition=3D2021 \ -Aclippy::needless_lifetimes \ -Wclippy::no_mangle_with_rust_abi \ -Wclippy::ptr_as_ptr \ + -Wclippy::ptr_cast_constness \ -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request= .rs index 4a5b7ec914ef..af5c9ac94f36 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -69,7 +69,7 @@ pub(crate) unsafe fn aref_from_raw(ptr: *mut bindings::re= quest) -> ARef { // INVARIANT: By the safety requirements of this function, invaria= nts are upheld. // SAFETY: By the safety requirement of this function, we own a // reference count that we can pass to `ARef`. - unsafe { ARef::from_raw(NonNull::new_unchecked(ptr as *const Self = as *mut Self)) } + unsafe { ARef::from_raw(NonNull::new_unchecked(ptr.cast())) } } =20 /// Notify the block layer that a request is going to be processed now. @@ -155,7 +155,7 @@ pub(crate) fn wrapper_ref(&self) -> &RequestDataWrapper= { // the private data associated with this request is initialized and // valid. The existence of `&self` guarantees that the private dat= a is // valid as a shared reference. - unsafe { Self::wrapper_ptr(self as *const Self as *mut Self).as_re= f() } + unsafe { Self::wrapper_ptr(core::ptr::from_ref(self).cast_mut()).a= s_ref() } } } =20 diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 624d7a4c83ea..ef66deb7ce23 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -83,8 +83,8 @@ impl Device { major: T::INFO.major, minor: T::INFO.minor, patchlevel: T::INFO.patchlevel, - name: T::INFO.name.as_char_ptr() as *mut _, - desc: T::INFO.desc.as_char_ptr() as *mut _, + name: T::INFO.name.as_char_ptr().cast_mut(), + desc: T::INFO.desc.as_char_ptr().cast_mut(), =20 driver_features: drm::driver::FEAT_GEM, ioctls: T::IOCTLS.as_ptr(), --=20 2.49.0 From nobody Sat Oct 11 04:07:54 2025 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE4A9266B5C; Wed, 11 Jun 2025 10:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637425; cv=none; b=fB1UxxBAuncuTvAF8HW2lJgNuDdf4LlgV+SowiSSGfvNuQSxlLXmSOKG4MjcNsOP5SojX5oDe1eWlJNvYmBtAoEJciiMrpbODPco4WxOhfTr+jE+gyyWlv39zxN37xxJb5yoABI+cXQSXrn0Uazgk2i2yQ3JY23HsAr8w5F0wcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637425; c=relaxed/simple; bh=yF5Gv8tK9X1wroVzoAbelwVn5+WfGFCL8D9RidNzyJg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XLvg1475Zi+cjU6ZMNIvSWwVwXwsafnEFMIboZuFusFfSldC0UnNU1uTZlWz2IFrfZFuw3QUgYMvbJYk9OuD2fwyp1LM/8lvEsqR4pXKQONsOfF3A9U5ZtuNuRdGkP9rpu5pqdYkvVRfdoFu4SJK1mp9dQIVXh2jS1AZFfOTBSw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WecFJdaz; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WecFJdaz" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4a44b0ed780so84900551cf.3; Wed, 11 Jun 2025 03:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749637423; x=1750242223; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BwuzOkwr2WXLbNIqZ4PjxHxYIhjL5EaV2fkU8tqfaYg=; b=WecFJdazz8I5JCI5jpmhrJE/576FIGiu5LgZ1R5fU7Us/NS/FYQ5O++E66mMKmQq5u 4c40u6H6zqNzCnTCi+q415T9SkcIYto4CKL9BbaRo+nVmOgdkA+6k1tCE/wUTp4ZMEMR 59UwMOMtBjeVjaQqBkzvvSStK5KpbYZVCJbklaZ+JozODTT2M1VVNIGm0dsXnAOsTIrB j2JUOJBghYcGL+n5UUayrZ630mCKHFfVNMHaxZ4MuCHNlP+Fd7h5f99TKvTiSfJB724d 6jpKWw1UY8tmEStGs7vrsXFCttA23+MWrHG6kJehNZ0/J1D2Q3rgrVB8DHY8ENeA4Q2p ZjWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749637423; x=1750242223; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BwuzOkwr2WXLbNIqZ4PjxHxYIhjL5EaV2fkU8tqfaYg=; b=vRFXZWrjYDql0Y81Su41t5gvuJeBSUUdSrrxrKh6C7XUgWignRj8P4aOQlKeQAp/J3 uhxFpSLkJc9aG/xIVA6Z9bihmPuzldF2XhsZBf4nP5c1yhr3fvERu19S32Yx4bfk5xlk suLewZ+5+dA2PyZGAjhDfJfkmiru8DS3Poigfe3KWXCtlpG+bcYz3GjA1fC4R9K7VwHy XJZXFyy76WdTJ0J2E4PYsAHyjioeMPQTmGFn7fAdfaCX0wrkvRJhwpA7ogFMJYcXJSnq xW+z8Ec1HilqaFco4NhTE5WEW96u3xYBYnmAB7FL9Dim9wFzlgrwQjRTBHaqG5MrVq+M JXcA== X-Forwarded-Encrypted: i=1; AJvYcCUTL7NhC6RwqMi8q7PJlO+iMDaLyoGS9qddBDQd1DxLD9tJHZOB0aSwvtsPufVdRxuS1zyV7Nt+AGo/Nvw=@vger.kernel.org, AJvYcCUueEdVZazwFe5uYrSnhgcI4OrOB4aBxHIQ3dwV8W7rVDKaKti+mSV/JrXyY+sHPj7mO4VBoV9jNSfH@vger.kernel.org, AJvYcCVKJJFffpyfzuwg+V3Vg8rkJLvLrxqFwhuDefb8gmtobdOLhG/YDU/ZqzzOtS2J+vPyCEelaDKf@vger.kernel.org, AJvYcCW3lj6XMTr3EimY0jbuLUMVaCPPPE5GLs6DZvkCz5dcgWHWgbvkG8IG2sPIAYZ0qtwy20K6Tm+I5oMEzykanWBu@vger.kernel.org, AJvYcCWJ0mNd1xSAIU7As//NybCXLhTRINBnmGN24f4Zjy2vFgVMIPG+XetjlfWvxOkhDnuAhRQhHk2nizqPCNp6@vger.kernel.org, AJvYcCWokf7esMH1dPSAL8IbI0Qb+gQae/0Ur2hsE7I0Wf09Mb19kmQ1UO7YtlkEGysi8Nw8rEG3xuiqV2KlUCK3Il4=@vger.kernel.org, AJvYcCXo+bSvBx4cOVwfWKOR0u0DZPGGTkZW6N1AIIHkYnD1S/JgqLVG6DS7UvbhI93S15Gh494gk18dOKf2@vger.kernel.org X-Gm-Message-State: AOJu0YwkZH5y7RKhyCv9evzyO2nLZY3ppnJMZamF8zUYQwaywr1OWQZK k1OU47DJi5g3bcf/mv1uUxfZHCZz0GwZj5xYNiO5AoqPj5V3Wt84nrQ4 X-Gm-Gg: ASbGncuY2rYATUzVEAnHfdyGLcmgSpHfPeMfPPWaDcN3owHUiE//aIlWOL17ekp+9RS FgsHnVj7SQw8f3FRKkKZBHPvd+nMyPIFky2JIEFkCQPvu+FMqJuyHzQIbGxu7MmNEHRtDRt1dhc MiI0n4Mb5/GNhkWUs39shWd3YcgoYtbB/7ifb4tzyk9OvcHbx7s0RagO7rycM565H2B211ejl5e Ox2bxxoJKmqOKpTUsZwepL4FWlizjIkfD68sOpM1v54sRhMNCuamCqrSIKos9FgBwQDkuOOitCO 0pB84yn7VH4Fvyd7fgpznJ8/UBuHhQhn+DY/dCrMRmNcm4dOFhavjzfST3PNQ+rxkoifLikJMtm 3xg== X-Google-Smtp-Source: AGHT+IHtIidebIfTt2jkkrOO6cFXeDxcrBR6iqFW0QLdbmEyB32yNlITHUCKNzRDp0DfY2l6KJd6Hg== X-Received: by 2002:a05:622a:1b29:b0:4a6:f774:dec5 with SMTP id d75a77b69052e-4a714bd9ceemr41400951cf.31.1749637422582; Wed, 11 Jun 2025 03:23:42 -0700 (PDT) Received: from 1.0.0.127.in-addr.arpa ([204.93.149.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a61114ff18sm85664341cf.6.2025.06.11.03.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 03:23:42 -0700 (PDT) From: Tamir Duberstein Date: Wed, 11 Jun 2025 06:23:27 -0400 Subject: [PATCH v11 3/6] rust: enable `clippy::as_ptr_cast_mut` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-ptr-as-ptr-v11-3-ce5b41c6e9c6@gmail.com> References: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> In-Reply-To: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori , Nicolas Schier , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Benno Lossin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , John Stultz , Stephen Boyd , Lorenzo Stoakes , "Liam R. Howlett" , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-mm@kvack.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev In Rust 1.66.0, Clippy introduced the `as_ptr_cast_mut` lint [1]: > Since `as_ptr` takes a `&self`, the pointer won=E2=80=99t have write > permissions unless interior mutability is used, making it unlikely > that having it as a mutable pointer is correct. There is only one affected callsite, and the change amounts to replacing `as _` with `.cast_mut().cast()`. This doesn't change the semantics, but is more descriptive of what's going on. Apply this change and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#as_ptr_cast= _mut [1] Reviewed-by: Benno Lossin Reviewed-by: Boqun Feng Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/kernel/devres.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5eeddfbf5900..bb33023f87c3 100644 --- a/Makefile +++ b/Makefile @@ -479,6 +479,7 @@ export rust_common_flags :=3D --edition=3D2021 \ -Wrust_2018_idioms \ -Wunreachable_pub \ -Wclippy::all \ + -Wclippy::as_ptr_cast_mut \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index e5475ff62da3..237182446db3 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -140,7 +140,7 @@ fn remove_action(this: &Arc) { bindings::devm_remove_action_nowarn( this.dev.as_raw(), Some(this.callback), - this.as_ptr() as _, + this.as_ptr().cast_mut().cast(), ) }; =20 --=20 2.49.0 From nobody Sat Oct 11 04:07:54 2025 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 618B3269818; Wed, 11 Jun 2025 10:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637428; cv=none; b=hYx2gq1/vTvRxz0ZI5x672ndS8hMRYv1mCW0QICbSw8M2TV1wuiSUaIacL0jQPAPDUmOZIwMLerFeYvb3AjT5E4hkBnVMOz3wNfMdXobPbpnMiHqPEKuvJIx1rnqsC2J1A8cJg06gy79OSumdVqX/dMGg4kmBKrCVWeSQ+MJZe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637428; c=relaxed/simple; bh=yg4n93C/NcLVnyCNYAyOa3gVfJ7ax8Oxoy2vIug88RM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eWtHKU8QugGYCCsgjB3kE8yi/OtwouJbDAls6un+J/8iGtFh+j+Da294WOL9Z9sqNlooMncvVTvsWZ7GPznD26P/ahYCBIwvKAdqT5x5AU61gGyOkUF04re1BrI/K9GOPCTL+bbFKlWSyjD8k52AILw1AmgM3hHNdsOu1cc2blU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W/IAEhNi; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W/IAEhNi" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7d21cecc11fso1025943985a.3; Wed, 11 Jun 2025 03:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749637425; x=1750242225; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fr3i50efmTTUye4giWnOXoWKuuW3PYZZNhP4YMB6XXY=; b=W/IAEhNiDxk9TW6W0N0uyy+4T3HBVcnTAeI7PTguZPVDpnQJzMTN6Hozat7gtYQgay fFwxhOZQOhXAMZDjWBkg4CekuzmfyoPL9GcFny5BMCHZvb32sXaJ5BR1IBjRPPIcqGVz kVVckATmivH2nj6efgoMgKLbR4RFZscH9cXpNO3xhOshRi6bfJ4QweUQIKxMQFmmTN4Y J+8ysmOG+BD8eUeW2dvqGh41atzCDKG4Cob8PcqGLufJEO9mOI//iwQXwVEk9oMJ5mwi lrRkVN/Stwyj4CfUs+1VG/k8EsEz7f+LUB0iBR92HpsUbzCOaQQNZ0R2EU/2p2r1OBLp MOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749637425; x=1750242225; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fr3i50efmTTUye4giWnOXoWKuuW3PYZZNhP4YMB6XXY=; b=xRxstNDxMDvYfnnjwN9yC8/zsduVU95WmFB6DX2mj84xh8ydeuA0DojNl9MGEpZnKh B9LjlELBnkO6TTEv6/MspfTdZ5EWXJkNYOM0P2elFN4bpnSiLB5bXHedDqSS07cW4M60 dd8Def3n+yugFKmcoBnQo3iDH54cdoxtrrnwkCFPgoi9VC6fy4jT0fgQ2cWD7CkRhql7 iWu9M+8hC7QUGf2kDMYBUIqQnKGEZUhaydtcpJY08l19nUK9YbGMjHiKyVSuKDhQm9ny FBG42O3cG4XCso6bsiFRf91EFi46iGW4fZYpPla8PhhN+vRZHSswFOUgFH3CGiq4kENo Je0Q== X-Forwarded-Encrypted: i=1; AJvYcCU/PRXuc2Bs033mFj2tEdoIK1HyjtzQIvl4LF40qm/kSIi7vbG3S0PBsDmf1C/lZIFD+8TXdx6a1+ho@vger.kernel.org, AJvYcCU5dgb7Yp1RRpAqA+2RZMhQXPZJ39yu2T1byZu/LVzhwiNQzKdDj2ZIMCd+OAk3o9TbzSVhdjWJn5Xg76nBMGqZ@vger.kernel.org, AJvYcCU9UHkvSn2vFkeWNHe/knVFDksuN7BYb10g+ry0OD30OrAgeoEHmTIxqBCmOEK/yssSHhnmD3O2@vger.kernel.org, AJvYcCUFMHkFugL+TapxLRzuDRQYkHNSegI0wGleutzfHD1Sw0nPTyYM+Sa6aG+z3KW14t95Ykk+A00vNZvN0Vs=@vger.kernel.org, AJvYcCV7DdB9mSTUUQXyfSS0y8Z4fKZO9wgNGEjuHEXM99acN8Wi57/4q+Pc7Js5mnkgHEEIMm2o/hHEmrobCF1iFcw=@vger.kernel.org, AJvYcCXNqnJ9e63frQ2vSU98e3ObIP/jFqbkud8TubfGjr8EzzfdFluukU2LXmQF4S76DhvVipOCSLHvXZS2D8kp@vger.kernel.org, AJvYcCXubDrxXRn9aRZKIT8P36x69LUYUHUXtFM0/Ph0vmyKR9rc/oWO9NcfmTo8RBA4pi77/sgfTuX82Wvx@vger.kernel.org X-Gm-Message-State: AOJu0YzXJJufZnEGiFZ/+q/6E8NiK9vVjCKYa2ZNH6lUQvOpA4pGsQDb Nv1cJOTsmBndDuFQi57jqEoo4gNG3PesQI1avVt6MMESv4Agv4tHcWHZ X-Gm-Gg: ASbGncsY0/i2CjHzXP3B0GL8xRoNNzKfKKSYU7ESohVv/GPhN/2Dp4lBo5Dr2sydGQK B1VZsR+As/5xmQxQEJNEbrWe/sm+mvKDQlLEWvduUdHCuMQuF7YuOScZpOki9TtZ+dpydaTC9Pz qwz5iJNTSZCt/a9K/3XFo8zUAuLdj3i1e0hXTmYHcN4qrz26Kkuq7ZsFDHmXLrAKkurxdkhkLx4 sq+PXuXV3fNgy+OIdy8ObWP7DEQ/53TGUo5FyrFc6/nSoFqVUR96UKapNJSQRmdGQGU4a2bQM7w dGAy0F7qaaq7LMdnSerQ5NDtpqFJSEVzRW5agIINQ2pdFgKdS9pRydVTlddxrFCb1Mc= X-Google-Smtp-Source: AGHT+IEKufG0rU5d1ir/pVOs5UUKkZrBCx8l5vMj0+HOOpWxeviY6dHXCb0Rs/HSAPGL/F8lgS/wlQ== X-Received: by 2002:a05:620a:2b8a:b0:7d0:a1d2:436 with SMTP id af79cd13be357-7d3a95d9624mr328743485a.33.1749637424941; Wed, 11 Jun 2025 03:23:44 -0700 (PDT) Received: from 1.0.0.127.in-addr.arpa ([204.93.149.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a61114ff18sm85664341cf.6.2025.06.11.03.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 03:23:44 -0700 (PDT) From: Tamir Duberstein Date: Wed, 11 Jun 2025 06:23:28 -0400 Subject: [PATCH v11 4/6] rust: enable `clippy::as_underscore` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-ptr-as-ptr-v11-4-ce5b41c6e9c6@gmail.com> References: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> In-Reply-To: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori , Nicolas Schier , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Benno Lossin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , John Stultz , Stephen Boyd , Lorenzo Stoakes , "Liam R. Howlett" , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-mm@kvack.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev In Rust 1.63.0, Clippy introduced the `as_underscore` lint [1]: > The conversion might include lossy conversion or a dangerous cast that > might go undetected due to the type being inferred. > > The lint is allowed by default as using `_` is less wordy than always > specifying the type. Always specifying the type is especially helpful in function call contexts where the inferred type may change at a distance. Specifying the type also allows Clippy to spot more cases of `useless_conversion`. The primary downside is the need to specify the type in trivial getters. There are 4 such functions: 3 have become slightly less ergonomic, 1 was revealed to be a `useless_conversion`. While this doesn't eliminate unchecked `as` conversions, it makes such conversions easier to scrutinize. It also has the slight benefit of removing a degree of freedom on which to bikeshed. Thus apply the changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#as_undersco= re [1] Reviewed-by: Benno Lossin Reviewed-by: Boqun Feng Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/kernel/block/mq/operations.rs | 2 +- rust/kernel/block/mq/request.rs | 7 ++++- rust/kernel/device_id.rs | 2 +- rust/kernel/devres.rs | 13 +++++----- rust/kernel/dma.rs | 2 +- rust/kernel/drm/device.rs | 2 +- rust/kernel/error.rs | 2 +- rust/kernel/io.rs | 18 ++++++------- rust/kernel/miscdevice.rs | 2 +- rust/kernel/mm/virt.rs | 52 +++++++++++++++++++---------------= ---- rust/kernel/of.rs | 6 ++--- rust/kernel/pci.rs | 9 ++++--- rust/kernel/str.rs | 8 +++--- rust/kernel/workqueue.rs | 2 +- 15 files changed, 69 insertions(+), 59 deletions(-) diff --git a/Makefile b/Makefile index bb33023f87c3..0ba22c361de8 100644 --- a/Makefile +++ b/Makefile @@ -480,6 +480,7 @@ export rust_common_flags :=3D --edition=3D2021 \ -Wunreachable_pub \ -Wclippy::all \ -Wclippy::as_ptr_cast_mut \ + -Wclippy::as_underscore \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/oper= ations.rs index 864ff379dc91..c2b98f507bcb 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -101,7 +101,7 @@ impl OperationsVTable { if let Err(e) =3D ret { e.to_blk_status() } else { - bindings::BLK_STS_OK as _ + bindings::BLK_STS_OK as bindings::blk_status_t } } =20 diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request= .rs index af5c9ac94f36..fefd394f064a 100644 --- a/rust/kernel/block/mq/request.rs +++ b/rust/kernel/block/mq/request.rs @@ -125,7 +125,12 @@ pub fn end_ok(this: ARef) -> Result<(), ARef> { // success of the call to `try_set_end` guarantees that there are = no // `ARef`s pointing to this request. Therefore it is safe to hand = it // back to the block layer. - unsafe { bindings::blk_mq_end_request(request_ptr, bindings::BLK_S= TS_OK as _) }; + unsafe { + bindings::blk_mq_end_request( + request_ptr, + bindings::BLK_STS_OK as bindings::blk_status_t, + ) + }; =20 Ok(()) } diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs index 0a4eb56d98f2..f9d55ac7b9e6 100644 --- a/rust/kernel/device_id.rs +++ b/rust/kernel/device_id.rs @@ -82,7 +82,7 @@ impl IdArray { unsafe { raw_ids[i] .as_mut_ptr() - .byte_offset(T::DRIVER_DATA_OFFSET as _) + .byte_add(T::DRIVER_DATA_OFFSET) .cast::() .write(i); } diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 237182446db3..1e44d70687a8 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -59,19 +59,19 @@ struct DevresInner { /// unsafe fn new(paddr: usize) -> Result{ /// // SAFETY: By the safety requirements of this function [`paddr= `, `paddr` + `SIZE`) is /// // valid for `ioremap`. -/// let addr =3D unsafe { bindings::ioremap(paddr as _, SIZE as _)= }; +/// let addr =3D unsafe { bindings::ioremap(paddr as bindings::phy= s_addr_t, SIZE) }; /// if addr.is_null() { /// return Err(ENOMEM); /// } /// -/// Ok(IoMem(IoRaw::new(addr as _, SIZE)?)) +/// Ok(IoMem(IoRaw::new(addr as usize, SIZE)?)) /// } /// } /// /// impl Drop for IoMem { /// fn drop(&mut self) { /// // SAFETY: `self.0.addr()` is guaranteed to be properly mapped= by `Self::new`. -/// unsafe { bindings::iounmap(self.0.addr() as _); }; +/// unsafe { bindings::iounmap(self.0.addr() as *mut c_void); }; /// } /// } /// @@ -112,8 +112,9 @@ fn new(dev: &Device, data: T, flags: Flags) -> R= esult> =20 // SAFETY: `devm_add_action` guarantees to call `Self::devres_call= back` once `dev` is // detached. - let ret =3D - unsafe { bindings::devm_add_action(dev.as_raw(), Some(inner.ca= llback), data as _) }; + let ret =3D unsafe { + bindings::devm_add_action(dev.as_raw(), Some(inner.callback), = data.cast_mut().cast()) + }; =20 if ret !=3D 0 { // SAFETY: We just created another reference to `inner` in ord= er to pass it to @@ -127,7 +128,7 @@ fn new(dev: &Device, data: T, flags: Flags) -> R= esult> } =20 fn as_ptr(&self) -> *const Self { - self as _ + self } =20 fn remove_action(this: &Arc) { diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 666bf2d64f9a..8e317005decd 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -38,7 +38,7 @@ impl Attrs { /// Get the raw representation of this attribute. pub(crate) fn as_raw(self) -> crate::ffi::c_ulong { - self.0 as _ + self.0 as crate::ffi::c_ulong } =20 /// Check whether `flags` is contained in `self`. diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index ef66deb7ce23..b7ee3c464a12 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -89,7 +89,7 @@ impl Device { driver_features: drm::driver::FEAT_GEM, ioctls: T::IOCTLS.as_ptr(), num_ioctls: T::IOCTLS.len() as i32, - fops: &Self::GEM_FOPS as _, + fops: &Self::GEM_FOPS, }; =20 const GEM_FOPS: bindings::file_operations =3D drm::gem::create_fops(); diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index afcb00cb6a75..fd7a8b759437 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -153,7 +153,7 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_stat= us_t { /// Returns the error encoded as a pointer. pub fn to_ptr(self) -> *mut T { // SAFETY: `self.0` is a valid error due to its invariant. - unsafe { bindings::ERR_PTR(self.0.get() as _).cast() } + unsafe { bindings::ERR_PTR(self.0.get() as isize).cast() } } =20 /// Returns a string representing the error, if one exists. diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index 72d80a6f131e..c08de4121637 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -5,7 +5,7 @@ //! C header: [`include/asm-generic/io.h`](srctree/include/asm-generic/io.= h) =20 use crate::error::{code::EINVAL, Result}; -use crate::{bindings, build_assert}; +use crate::{bindings, build_assert, ffi::c_void}; =20 /// Raw representation of an MMIO region. /// @@ -56,7 +56,7 @@ pub fn maxsize(&self) -> usize { /// # Examples /// /// ```no_run -/// # use kernel::{bindings, io::{Io, IoRaw}}; +/// # use kernel::{bindings, ffi::c_void, io::{Io, IoRaw}}; /// # use core::ops::Deref; /// /// // See also [`pci::Bar`] for a real example. @@ -70,19 +70,19 @@ pub fn maxsize(&self) -> usize { /// unsafe fn new(paddr: usize) -> Result{ /// // SAFETY: By the safety requirements of this function [`paddr= `, `paddr` + `SIZE`) is /// // valid for `ioremap`. -/// let addr =3D unsafe { bindings::ioremap(paddr as _, SIZE as _)= }; +/// let addr =3D unsafe { bindings::ioremap(paddr as bindings::phy= s_addr_t, SIZE) }; /// if addr.is_null() { /// return Err(ENOMEM); /// } /// -/// Ok(IoMem(IoRaw::new(addr as _, SIZE)?)) +/// Ok(IoMem(IoRaw::new(addr as usize, SIZE)?)) /// } /// } /// /// impl Drop for IoMem { /// fn drop(&mut self) { /// // SAFETY: `self.0.addr()` is guaranteed to be properly mapped= by `Self::new`. -/// unsafe { bindings::iounmap(self.0.addr() as _); }; +/// unsafe { bindings::iounmap(self.0.addr() as *mut c_void); }; /// } /// } /// @@ -119,7 +119,7 @@ pub fn $name(&self, offset: usize) -> $type_name { let addr =3D self.io_addr_assert::<$type_name>(offset); =20 // SAFETY: By the type invariant `addr` is a valid address for= MMIO operations. - unsafe { bindings::$c_fn(addr as _) } + unsafe { bindings::$c_fn(addr as *const c_void) } } =20 /// Read IO data from a given offset. @@ -131,7 +131,7 @@ pub fn $try_name(&self, offset: usize) -> Result<$type_= name> { let addr =3D self.io_addr::<$type_name>(offset)?; =20 // SAFETY: By the type invariant `addr` is a valid address for= MMIO operations. - Ok(unsafe { bindings::$c_fn(addr as _) }) + Ok(unsafe { bindings::$c_fn(addr as *const c_void) }) } }; } @@ -148,7 +148,7 @@ pub fn $name(&self, value: $type_name, offset: usize) { let addr =3D self.io_addr_assert::<$type_name>(offset); =20 // SAFETY: By the type invariant `addr` is a valid address for= MMIO operations. - unsafe { bindings::$c_fn(value, addr as _, ) } + unsafe { bindings::$c_fn(value, addr as *mut c_void) } } =20 /// Write IO data from a given offset. @@ -160,7 +160,7 @@ pub fn $try_name(&self, value: $type_name, offset: usiz= e) -> Result { let addr =3D self.io_addr::<$type_name>(offset)?; =20 // SAFETY: By the type invariant `addr` is a valid address for= MMIO operations. - unsafe { bindings::$c_fn(value, addr as _) } + unsafe { bindings::$c_fn(value, addr as *mut c_void) } Ok(()) } }; diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index 939278bc7b03..288f40e79906 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -34,7 +34,7 @@ impl MiscDeviceOptions { pub const fn into_raw(self) -> bindings::miscdevice { // SAFETY: All zeros is valid for this C type. let mut result: bindings::miscdevice =3D unsafe { MaybeUninit::zer= oed().assume_init() }; - result.minor =3D bindings::MISC_DYNAMIC_MINOR as _; + result.minor =3D bindings::MISC_DYNAMIC_MINOR as ffi::c_int; result.name =3D self.name.as_char_ptr(); result.fops =3D MiscdeviceVTable::::build(); result diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs index 31803674aecc..6086ca981b06 100644 --- a/rust/kernel/mm/virt.rs +++ b/rust/kernel/mm/virt.rs @@ -392,80 +392,80 @@ pub mod flags { use crate::bindings; =20 /// No flags are set. - pub const NONE: vm_flags_t =3D bindings::VM_NONE as _; + pub const NONE: vm_flags_t =3D bindings::VM_NONE as vm_flags_t; =20 /// Mapping allows reads. - pub const READ: vm_flags_t =3D bindings::VM_READ as _; + pub const READ: vm_flags_t =3D bindings::VM_READ as vm_flags_t; =20 /// Mapping allows writes. - pub const WRITE: vm_flags_t =3D bindings::VM_WRITE as _; + pub const WRITE: vm_flags_t =3D bindings::VM_WRITE as vm_flags_t; =20 /// Mapping allows execution. - pub const EXEC: vm_flags_t =3D bindings::VM_EXEC as _; + pub const EXEC: vm_flags_t =3D bindings::VM_EXEC as vm_flags_t; =20 /// Mapping is shared. - pub const SHARED: vm_flags_t =3D bindings::VM_SHARED as _; + pub const SHARED: vm_flags_t =3D bindings::VM_SHARED as vm_flags_t; =20 /// Mapping may be updated to allow reads. - pub const MAYREAD: vm_flags_t =3D bindings::VM_MAYREAD as _; + pub const MAYREAD: vm_flags_t =3D bindings::VM_MAYREAD as vm_flags_t; =20 /// Mapping may be updated to allow writes. - pub const MAYWRITE: vm_flags_t =3D bindings::VM_MAYWRITE as _; + pub const MAYWRITE: vm_flags_t =3D bindings::VM_MAYWRITE as vm_flags_t; =20 /// Mapping may be updated to allow execution. - pub const MAYEXEC: vm_flags_t =3D bindings::VM_MAYEXEC as _; + pub const MAYEXEC: vm_flags_t =3D bindings::VM_MAYEXEC as vm_flags_t; =20 /// Mapping may be updated to be shared. - pub const MAYSHARE: vm_flags_t =3D bindings::VM_MAYSHARE as _; + pub const MAYSHARE: vm_flags_t =3D bindings::VM_MAYSHARE as vm_flags_t; =20 /// Page-ranges managed without `struct page`, just pure PFN. - pub const PFNMAP: vm_flags_t =3D bindings::VM_PFNMAP as _; + pub const PFNMAP: vm_flags_t =3D bindings::VM_PFNMAP as vm_flags_t; =20 /// Memory mapped I/O or similar. - pub const IO: vm_flags_t =3D bindings::VM_IO as _; + pub const IO: vm_flags_t =3D bindings::VM_IO as vm_flags_t; =20 /// Do not copy this vma on fork. - pub const DONTCOPY: vm_flags_t =3D bindings::VM_DONTCOPY as _; + pub const DONTCOPY: vm_flags_t =3D bindings::VM_DONTCOPY as vm_flags_t; =20 /// Cannot expand with mremap(). - pub const DONTEXPAND: vm_flags_t =3D bindings::VM_DONTEXPAND as _; + pub const DONTEXPAND: vm_flags_t =3D bindings::VM_DONTEXPAND as vm_fla= gs_t; =20 /// Lock the pages covered when they are faulted in. - pub const LOCKONFAULT: vm_flags_t =3D bindings::VM_LOCKONFAULT as _; + pub const LOCKONFAULT: vm_flags_t =3D bindings::VM_LOCKONFAULT as vm_f= lags_t; =20 /// Is a VM accounted object. - pub const ACCOUNT: vm_flags_t =3D bindings::VM_ACCOUNT as _; + pub const ACCOUNT: vm_flags_t =3D bindings::VM_ACCOUNT as vm_flags_t; =20 /// Should the VM suppress accounting. - pub const NORESERVE: vm_flags_t =3D bindings::VM_NORESERVE as _; + pub const NORESERVE: vm_flags_t =3D bindings::VM_NORESERVE as vm_flags= _t; =20 /// Huge TLB Page VM. - pub const HUGETLB: vm_flags_t =3D bindings::VM_HUGETLB as _; + pub const HUGETLB: vm_flags_t =3D bindings::VM_HUGETLB as vm_flags_t; =20 /// Synchronous page faults. (DAX-specific) - pub const SYNC: vm_flags_t =3D bindings::VM_SYNC as _; + pub const SYNC: vm_flags_t =3D bindings::VM_SYNC as vm_flags_t; =20 /// Architecture-specific flag. - pub const ARCH_1: vm_flags_t =3D bindings::VM_ARCH_1 as _; + pub const ARCH_1: vm_flags_t =3D bindings::VM_ARCH_1 as vm_flags_t; =20 /// Wipe VMA contents in child on fork. - pub const WIPEONFORK: vm_flags_t =3D bindings::VM_WIPEONFORK as _; + pub const WIPEONFORK: vm_flags_t =3D bindings::VM_WIPEONFORK as vm_fla= gs_t; =20 /// Do not include in the core dump. - pub const DONTDUMP: vm_flags_t =3D bindings::VM_DONTDUMP as _; + pub const DONTDUMP: vm_flags_t =3D bindings::VM_DONTDUMP as vm_flags_t; =20 /// Not soft dirty clean area. - pub const SOFTDIRTY: vm_flags_t =3D bindings::VM_SOFTDIRTY as _; + pub const SOFTDIRTY: vm_flags_t =3D bindings::VM_SOFTDIRTY as vm_flags= _t; =20 /// Can contain `struct page` and pure PFN pages. - pub const MIXEDMAP: vm_flags_t =3D bindings::VM_MIXEDMAP as _; + pub const MIXEDMAP: vm_flags_t =3D bindings::VM_MIXEDMAP as vm_flags_t; =20 /// MADV_HUGEPAGE marked this vma. - pub const HUGEPAGE: vm_flags_t =3D bindings::VM_HUGEPAGE as _; + pub const HUGEPAGE: vm_flags_t =3D bindings::VM_HUGEPAGE as vm_flags_t; =20 /// MADV_NOHUGEPAGE marked this vma. - pub const NOHUGEPAGE: vm_flags_t =3D bindings::VM_NOHUGEPAGE as _; + pub const NOHUGEPAGE: vm_flags_t =3D bindings::VM_NOHUGEPAGE as vm_fla= gs_t; =20 /// KSM may merge identical pages. - pub const MERGEABLE: vm_flags_t =3D bindings::VM_MERGEABLE as _; + pub const MERGEABLE: vm_flags_t =3D bindings::VM_MERGEABLE as vm_flags= _t; } diff --git a/rust/kernel/of.rs b/rust/kernel/of.rs index 04f2d8ef29cb..40d1bd13682c 100644 --- a/rust/kernel/of.rs +++ b/rust/kernel/of.rs @@ -22,7 +22,7 @@ unsafe impl RawDeviceId for DeviceId { const DRIVER_DATA_OFFSET: usize =3D core::mem::offset_of!(bindings::of= _device_id, data); =20 fn index(&self) -> usize { - self.0.data as _ + self.0.data as usize } } =20 @@ -34,10 +34,10 @@ pub const fn new(compatible: &'static CStr) -> Self { // SAFETY: FFI type is valid to be zero-initialized. let mut of: bindings::of_device_id =3D unsafe { core::mem::zeroed(= ) }; =20 - // TODO: Use `clone_from_slice` once the corresponding types do ma= tch. + // TODO: Use `copy_from_slice` once stabilized for `const`. let mut i =3D 0; while i < src.len() { - of.compatible[i] =3D src[i] as _; + of.compatible[i] =3D src[i]; i +=3D 1; } =20 diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 33ae0bdc433d..f6b19764ad17 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -171,7 +171,7 @@ unsafe impl RawDeviceId for DeviceId { const DRIVER_DATA_OFFSET: usize =3D core::mem::offset_of!(bindings::pc= i_device_id, driver_data); =20 fn index(&self) -> usize { - self.0.driver_data as _ + self.0.driver_data } } =20 @@ -206,7 +206,10 @@ macro_rules! pci_device_table { /// MODULE_PCI_TABLE, /// ::IdInfo, /// [ -/// (pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, bindin= gs::PCI_ANY_ID as _), ()) +/// ( +/// pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_REDHAT, bin= dings::PCI_ANY_ID as u32), +/// (), +/// ) /// ] /// ); /// @@ -330,7 +333,7 @@ unsafe fn do_release(pdev: &Device, ioptr: usize, num: = i32) { // `ioptr` is valid by the safety requirements. // `num` is valid by the safety requirements. unsafe { - bindings::pci_iounmap(pdev.as_raw(), ioptr as _); + bindings::pci_iounmap(pdev.as_raw(), ioptr as *mut kernel::ffi= ::c_void); bindings::pci_release_region(pdev.as_raw(), num); } } diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 6a3cb607b332..43597eb7c5c1 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -728,9 +728,9 @@ fn new() -> Self { pub(crate) unsafe fn from_ptrs(pos: *mut u8, end: *mut u8) -> Self { // INVARIANT: The safety requirements guarantee the type invariant= s. Self { - beg: pos as _, - pos: pos as _, - end: end as _, + beg: pos as usize, + pos: pos as usize, + end: end as usize, } } =20 @@ -755,7 +755,7 @@ pub(crate) unsafe fn from_buffer(buf: *mut u8, len: usi= ze) -> Self { /// /// N.B. It may point to invalid memory. pub(crate) fn pos(&self) -> *mut u8 { - self.pos as _ + self.pos as *mut u8 } =20 /// Returns the number of bytes written to the formatter. diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index de61374e36bd..89e5c2560eec 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -198,7 +198,7 @@ pub fn enqueue(&self, w: W) -> W::Enq= ueueOutput unsafe { w.__enqueue(move |work_ptr| { bindings::queue_work_on( - bindings::wq_misc_consts_WORK_CPU_UNBOUND as _, + bindings::wq_misc_consts_WORK_CPU_UNBOUND as ffi::c_in= t, queue_ptr, work_ptr, ) --=20 2.49.0 From nobody Sat Oct 11 04:07:54 2025 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8643626280F; Wed, 11 Jun 2025 10:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637433; cv=none; b=RMHmBKYRmXEX1+UjcnjFJxZnRcUaWUUy4Kt+5jzHdkU3k7Q2PGqucAq6U0R8xMSmTME/AJDRrV8Lzzxge/ZPzWQJR6nNSc42D/NQ0UT97RwS3Fp1d8prdK/IXoVoZOJ3vJcrJuv+zVeLTX6dIL7syN7SVyBIQqW7rT3pdKdP4N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637433; c=relaxed/simple; bh=Wu6Ky3QsPEjSwzFSxA1XY4RVknq1x4i+6mONM0XFn+I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GuybEe5MJdO/abtq/bN6OGSbX1QlxKeb4mmks4bvWGztNZ0QYVb/Ud7J8Z8FjdFm0YU29ByOfD9YYcClIPdUUJYA9N2SPLpH+QapefipwKQ9fbNGKbD/AdXxEPVjC2z0emkBTGR8McC2tdbRccEOtKTWo3XBlQLdt8c+lFw/dGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LjpzQKZh; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LjpzQKZh" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-4a5840ec53dso77507711cf.0; Wed, 11 Jun 2025 03:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749637427; x=1750242227; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Q9qhOcOtFQhfffMpoMualzwb4BvJ35IoO/XhbMyL5dA=; b=LjpzQKZhdBx48RWMlLsc+n71kEGG4xbKQ9xRcVUYAuHnu+DTh7YlcpIj2Bfeyb/ke/ MR9lkUvOHXm180T+MF6nnmoCs+4X7/Jxeae2VhmKMjutWwZz+hZUDqX63Z1xWgjdLjfd QsRF1sDRdvrLPDE7TEL/IJC/ev1ZI+gKrJrRZ729WaXk2MTTYXMURod+N/AdC07zkcYU blrn4kDb/zqfNjrWC2iFINqsqXs2Yah2WbAi6Sde+Xbx3T856sIJpbxOkrW9ky15mXLj K6wBUO0WHvwbs1965D9w2UUO6wZEHq6mviZzX79vofLI47MV5yH8K2p8MuR9dU/Om9A1 l+6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749637427; x=1750242227; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q9qhOcOtFQhfffMpoMualzwb4BvJ35IoO/XhbMyL5dA=; b=EqgyLhN8OQCAFNgVj3WwR4zmDWpWDO2COHVb/OQCpZyh8fbet25xrCs+U3I6tJSgjl /XJdLACRzByQjpZt7zq2Me7r21H+KlP+QyDHunlsRtko34g7CcQx3E8PAqTq6Hfqfg01 WIE2X9l6SSDjq/NdRzs3sxNEB3rTRDndPwhWyooHiKce9w0bnNB83wJmIvsQJW3gT/zy AChjbCCi/87j1v3Oaq1oIOqm4fHDRmJzVBd0AZ27onbLJ+33i9y5FZZ59+qsNySyzyF+ mhm+2eMu6Puk8SPfeBD71fJmy4qhbazNYt5F+ZeKh+8mioUY0x8YZi7vYgSWCs5cmMR9 3rJw== X-Forwarded-Encrypted: i=1; AJvYcCUNNwCfvizQYGUyNoViuKGEqFl4r4lW6eyFL+ILA7OEwFvVkE6Anx/cXTciUjsp77QqIEF8tlxhPlF7@vger.kernel.org, AJvYcCV0UkF/bIrOrfuNQaHIJ+g0ANa3AZfVc1zitTyOJlJ7ZCGAEwCU8FlWHY3Tgo4zsOx809ySmI/ySX+y@vger.kernel.org, AJvYcCVKs/+0tWNGPwpJR1a4D1B5cSVNrqJjkaqLrwy9vdJ4xvcu3yJtOtd2rX40rKwLvg1Rqw51qAMwxkPKYWw=@vger.kernel.org, AJvYcCVoiTS7FrbymgBwSMstiB+dv30LLsVOD2jHYZBeOGUCerehzofAudinepKENQtWxY/raZdMPCwa@vger.kernel.org, AJvYcCWc528CbgR5T/GBijgXd0sA6XBDVt9hgn5Q3e8Qn+qFtlpCcLEV/bXPYWpJrjiRES9uA8JYmzS89CYB2D4zSyk=@vger.kernel.org, AJvYcCWi3hDovk8XwD+Kxl3+MLsWidGy9tHY1yxiwdPqe0gRiLiF59IkpstIuRUCHTbbG+9+17jDnKBeJsY+o4KSWrPF@vger.kernel.org, AJvYcCXJaLc+3Ao+L5q87zyh5oJEOqcHsVovasa1Bw8KDqrPhs52FYNf4Yj7m15bAO8g5HomExhP5CIYR7F1PFd9@vger.kernel.org X-Gm-Message-State: AOJu0Yw3xKFMAH7LoZyTUDYx2Jr45yE1YJdIhvZdBT/+5a0MnhJOJV2c LN3n2H1BNLf1cBNF/4iayzYWQKVmNionPHRAfootF47JcNrc3fnaD3xv X-Gm-Gg: ASbGncvJEUh4D6VilvAIbqXMLgxkQ91e+yfMouC1pAN1tK89cNd+5FdAtOZHHRTgP45 PkTt3+tcnCPYI1wNITPtRZ9sHyBYscnA8F07JWMMtYg9ctCHPyKs8YCnTdR0tIoVtw41YcccOeo tlVecrCIH2N/wNymFgPSGgcUmeCiQkzYYbRrVguQ7ScPh5f9TtFUxUIM+3LofezzlQBfiewL/EA UY44K4UilLLIgaaek+1FhbldgSrcXv20O5771DID7tJhybRicoNqRLKZuNQU19alpCOdHrpuMAZ PAIhxRaEJHbKLlB3s26RfOJaUcnFmylKrRg5zs/fv85ocwcge+oxw0P2zsfrZY0menI= X-Google-Smtp-Source: AGHT+IEE+UdMzaOchvhdv2iTiBaMPk9Je4GKo5cGJfflzkUjSPeeVlANuY0LrkSRHqmvIwKc1ILAag== X-Received: by 2002:a05:622a:5c87:b0:4a1:3c6c:cda2 with SMTP id d75a77b69052e-4a713b9527fmr54652301cf.1.1749637427330; Wed, 11 Jun 2025 03:23:47 -0700 (PDT) Received: from 1.0.0.127.in-addr.arpa ([204.93.149.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a61114ff18sm85664341cf.6.2025.06.11.03.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 03:23:46 -0700 (PDT) From: Tamir Duberstein Date: Wed, 11 Jun 2025 06:23:29 -0400 Subject: [PATCH v11 5/6] rust: enable `clippy::cast_lossless` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-ptr-as-ptr-v11-5-ce5b41c6e9c6@gmail.com> References: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> In-Reply-To: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori , Nicolas Schier , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Benno Lossin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , John Stultz , Stephen Boyd , Lorenzo Stoakes , "Liam R. Howlett" , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-mm@kvack.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]: > Rust=E2=80=99s `as` keyword will perform many kinds of conversions, inclu= ding > silently lossy conversions. Conversion functions such as `i32::from` > will only perform lossless conversions. Using the conversion functions > prevents conversions from becoming silently lossy if the input types > ever change, and makes it clear for people reading the code that the > conversion is lossless. While this doesn't eliminate unchecked `as` conversions, it makes such conversions easier to scrutinize. It also has the slight benefit of removing a degree of freedom on which to bikeshed. Thus apply the changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossle= ss [1] Suggested-by: Benno Lossin Link: https://lore.kernel.org/all/D8ORTXSUTKGL.1KOJAGBM8F8TN@proton.me/ Reviewed-by: Benno Lossin Reviewed-by: Boqun Feng Signed-off-by: Tamir Duberstein --- Makefile | 1 + drivers/gpu/drm/drm_panic_qr.rs | 4 ++-- rust/bindings/lib.rs | 1 + rust/kernel/net/phy.rs | 4 ++-- rust/uapi/lib.rs | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0ba22c361de8..29cf39be14de 100644 --- a/Makefile +++ b/Makefile @@ -481,6 +481,7 @@ export rust_common_flags :=3D --edition=3D2021 \ -Wclippy::all \ -Wclippy::as_ptr_cast_mut \ -Wclippy::as_underscore \ + -Wclippy::cast_lossless \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ diff --git a/drivers/gpu/drm/drm_panic_qr.rs b/drivers/gpu/drm/drm_panic_qr= .rs index dd55b1cb764d..6b59d19ab631 100644 --- a/drivers/gpu/drm/drm_panic_qr.rs +++ b/drivers/gpu/drm/drm_panic_qr.rs @@ -404,7 +404,7 @@ fn pop3(&mut self) -> Option<(u16, usize)> { let mut out =3D 0; let mut exp =3D 1; for i in 0..poplen { - out +=3D self.decimals[self.len + i] as u16 * exp; + out +=3D u16::from(self.decimals[self.len + i]) * exp; exp *=3D 10; } Some((out, NUM_CHARS_BITS[poplen])) @@ -425,7 +425,7 @@ fn next(&mut self) -> Option { match self.segment { Segment::Binary(data) =3D> { if self.offset < data.len() { - let byte =3D data[self.offset] as u16; + let byte =3D u16::from(data[self.offset]); self.offset +=3D 1; Some((byte, 8)) } else { diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs index 81b6c7aa4916..7631c9f6708d 100644 --- a/rust/bindings/lib.rs +++ b/rust/bindings/lib.rs @@ -25,6 +25,7 @@ )] =20 #[allow(dead_code)] +#[allow(clippy::cast_lossless)] #[allow(clippy::ptr_as_ptr)] #[allow(clippy::undocumented_unsafe_blocks)] #[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_tran= smutes))] diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 32ea43ece646..65ac4d59ad77 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -142,7 +142,7 @@ pub fn is_autoneg_enabled(&self) -> bool { // SAFETY: The struct invariant ensures that we may access // this field without additional synchronization. let bit_field =3D unsafe { &(*self.0.get())._bitfield_1 }; - bit_field.get(13, 1) =3D=3D bindings::AUTONEG_ENABLE as u64 + bit_field.get(13, 1) =3D=3D u64::from(bindings::AUTONEG_ENABLE) } =20 /// Gets the current auto-negotiation state. @@ -427,7 +427,7 @@ impl Adapter { // where we hold `phy_device->lock`, so the accessors on // `Device` are okay to call. let dev =3D unsafe { Device::from_raw(phydev) }; - T::match_phy_device(dev) as i32 + T::match_phy_device(dev).into() } =20 /// # Safety diff --git a/rust/uapi/lib.rs b/rust/uapi/lib.rs index e79a1f49f055..08e68ebef606 100644 --- a/rust/uapi/lib.rs +++ b/rust/uapi/lib.rs @@ -14,6 +14,7 @@ #![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))] #![allow( clippy::all, + clippy::cast_lossless, clippy::ptr_as_ptr, clippy::undocumented_unsafe_blocks, dead_code, --=20 2.49.0 From nobody Sat Oct 11 04:07:54 2025 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 352F72609C6; Wed, 11 Jun 2025 10:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637433; cv=none; b=VjZbOmky3DVXxlNWhzhX13gwG5R/3ecn3NCFqZc+6T/EMkVV4WYbGJuQtq3coJuMaUpc3JY7TaVCUV4oYyH+Jq5Sppw7HeWxNrgZ4Okzsmp+Vvo1hWYW+CJdmy8dVYvKR2NMCRZhnu2FMTD2KAY5/I+sw2TMeXRR31duEqujePk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749637433; c=relaxed/simple; bh=zE7akQ9I/itqlcJaWHyvSN6SxMbWvWntxwwUGa4zOrw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RoBh4Xo/4k1n6vw/r5CfhyPAbU7K0pcLqCQhojTufR3nYp5BLA+5UI1pnxtDRCpkoRHfzl14lCCMScWtGo/Z2KQUuAd4m/oNUYTBVzTnUjJRosdRFG7F2jGPA8dIkiAruPVv1hC8wMuenGfajL7roPYG1VT5FJNlIw8BWv8eBe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SeGV9yVk; arc=none smtp.client-ip=209.85.160.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SeGV9yVk" Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-4a58b120bedso83445991cf.2; Wed, 11 Jun 2025 03:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749637430; x=1750242230; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=b2miWcRt7MptMpkkpbvEAaiGbbGDGe5gQtbWu3GJa1w=; b=SeGV9yVkAA88uERIY5vSDKF6APT18YweXGNQa1DafSZuP4NcXWHB6XLVG96KNaNzVg +HwqWWFqW2wiEMAjtkbzi4ULIcrdyfTJxLHFlzAJCKDbQRpj4VTXNhdYjYW4I6sCUx9G GSWAQqf1RhlR0P9cmji3CrFEIVvCcm35WSx7fFqiTR9fwjYp534muQmlivXjaykQ3D/p N0BW2ZJLX3QdOgYYs0yrUvcc18FgUtnyJZUWad9+19seCP0ag26jbKrddhfzDSspes6f g8ejm8AS4/vuDs5f5DLpjgIfY49+rgk3WcoVMG0QFn4Cp0FNI79PR2FpJzBaa5mw6Pvw KBNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749637430; x=1750242230; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b2miWcRt7MptMpkkpbvEAaiGbbGDGe5gQtbWu3GJa1w=; b=rAn4K/jsLiIGbX9kvtonoB6XgeBgY4FmZMpjM3cLhZzRH5dVnbHH0Xg13+uhIg7r4j bSMofUYNiLNz6a8cPr5zopi/Cmwbw8HSflsszHhcA2V1LzkIaI212KkjmemTaOdwXXhl oKAIKq+ABzc4yBtwBxA7CZXk30liKOzs+7L5CMRgErAIKWuqwYyD9riBCynxhqYNARMO YSuEf5fjAu9+IaDaykzLKJTrr50oeLV0KuUTjxc3nM4nkzNSNF5u2Uz64nn93/s94rlo J+xvxy3t3X/PuCiLDEMBnL5rlZQNVmKOrUteMVa2MWJTeQEIWC+YR8nWy2U1eS+Xk6u2 yXEw== X-Forwarded-Encrypted: i=1; AJvYcCV13042mt5Lrd+2+pYJALLDX1Z7byNCuJUZK7ZWwiWtCKBv5sbMFz1GIYbQsbP/wfic7E0UccDl0dE8kDqUMyc=@vger.kernel.org, AJvYcCV43LfHFiZ4kLHD+nqDt7qGfDAyWrfagmJy5mb7JE3DS4xJGN4RJjHlpIEhScPcA3yrothsGqQ0Buet@vger.kernel.org, AJvYcCVI07HhEfJCtill7FlX1W8cF97bAYYATW18f1qPIkP6Gi5YAEj6OrAX6D+FOkTaQKpHoNVCpBNM@vger.kernel.org, AJvYcCVjXZgMSYiE1XvJnz0Zy0dmOKAlaojAcPQk4VhH9g1VypYjuqKJxvbA+NqVK+mavLjuIxYF4ikWnCUA@vger.kernel.org, AJvYcCWPDNYEUywWB8nZxN5Q2upF7wOjZRGdYWIy4oQZUcGinLc95i4IVuQETHw3nGRUGeIsWgDkK7ephAR2XU22@vger.kernel.org, AJvYcCXZE4mf4YbZv06BSoTqp0N4h6GOS9MOqKWJxVYxzp+y7Xv3CAHnWd6lbh8JLZGkUgHBIGWWwSEteOHY57PwbEBt@vger.kernel.org, AJvYcCXzMyGmJAQ1vzMzQUD2fycMIWyruo7uY+huaZm6cdYvfJjEZZPEAat/0eklT0cPq7VOWopfwQTpeOmqEyM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywwjv1ioY57pXMQb5ebMpk/3bWhXr/0YpxWW7uEb2sawjo1JHMX thvyhog5dGPj1ComY0dP0pAlvIdQV4l0rmLT8ISayOlxACJSwVfxxH/o X-Gm-Gg: ASbGncu8VxblY+gvenqS5onW2GLT/cVxDqX05zlxrDiktw6hq7hzcDhfC345s5glylw nHQniFLLdYXOVZU5Xvr4bRTXbUvZlWnSVn3B0dOCtpNqEoYHTYC9NjJhyr/vDmtIayHN5DdfK1V YlRDeehjsZ5ftVY/0GlnEhgcstYy/bN4eSFoRJWMEwPoZCyt6LrgOrr4kiczHj36Qa+RjomyIkb geCrHeUkleVlZCW+lbS94FbbSK1wa9Nqle6oZnRM0m9KZiKMLygMTBkmaUm4V2Rp+besnxYmVZr 34cnMqG+UXJm63p2WIrSUlNl2tw+AAYsaFT6iSKUGcwAewdm0GwfQ10D49RtO6leO7Y= X-Google-Smtp-Source: AGHT+IF1XN3p+FQVDqgsmvti47aZkI6r5GH+zjxKG5ndYXkmsax9t4EzbKDR8hTM8xrA7++NbyrCMw== X-Received: by 2002:a05:622a:4288:b0:494:7e91:eb4d with SMTP id d75a77b69052e-4a713c65d30mr41371881cf.51.1749637430010; Wed, 11 Jun 2025 03:23:50 -0700 (PDT) Received: from 1.0.0.127.in-addr.arpa ([204.93.149.208]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a61114ff18sm85664341cf.6.2025.06.11.03.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 03:23:49 -0700 (PDT) From: Tamir Duberstein Date: Wed, 11 Jun 2025 06:23:30 -0400 Subject: [PATCH v11 6/6] rust: enable `clippy::ref_as_ptr` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-ptr-as-ptr-v11-6-ce5b41c6e9c6@gmail.com> References: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> In-Reply-To: <20250611-ptr-as-ptr-v11-0-ce5b41c6e9c6@gmail.com> To: Masahiro Yamada , Nathan Chancellor , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Brendan Higgins , David Gow , Rae Moar , Bjorn Helgaas , Luis Chamberlain , Russ Weight , Rob Herring , Saravana Kannan , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , FUJITA Tomonori , Nicolas Schier , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , Benno Lossin , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , John Stultz , Stephen Boyd , Lorenzo Stoakes , "Liam R. Howlett" , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, linux-mm@kvack.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev In Rust 1.78.0, Clippy introduced the `ref_as_ptr` lint [1]: > Using `as` casts may result in silently changing mutability or type. While this doesn't eliminate unchecked `as` conversions, it makes such conversions easier to scrutinize. It also has the slight benefit of removing a degree of freedom on which to bikeshed. Thus apply the changes and enable the lint -- no functional change intended. Link: https://rust-lang.github.io/rust-clippy/master/index.html#ref_as_ptr = [1] Suggested-by: Benno Lossin Link: https://lore.kernel.org/all/D8PGG7NTWB6U.3SS3A5LN4XWMN@proton.me/ Reviewed-by: Benno Lossin Reviewed-by: Boqun Feng Signed-off-by: Tamir Duberstein --- Makefile | 1 + rust/bindings/lib.rs | 1 + rust/kernel/device_id.rs | 2 +- rust/kernel/fs/file.rs | 2 +- rust/kernel/str.rs | 4 ++-- rust/kernel/uaccess.rs | 4 ++-- rust/uapi/lib.rs | 1 + 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 29cf39be14de..1a855f42a34a 100644 --- a/Makefile +++ b/Makefile @@ -489,6 +489,7 @@ export rust_common_flags :=3D --edition=3D2021 \ -Wclippy::no_mangle_with_rust_abi \ -Wclippy::ptr_as_ptr \ -Wclippy::ptr_cast_constness \ + -Wclippy::ref_as_ptr \ -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs index 7631c9f6708d..474cc98c48a3 100644 --- a/rust/bindings/lib.rs +++ b/rust/bindings/lib.rs @@ -27,6 +27,7 @@ #[allow(dead_code)] #[allow(clippy::cast_lossless)] #[allow(clippy::ptr_as_ptr)] +#[allow(clippy::ref_as_ptr)] #[allow(clippy::undocumented_unsafe_blocks)] #[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_tran= smutes))] mod bindings_raw { diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs index f9d55ac7b9e6..3dc72ca8cfc2 100644 --- a/rust/kernel/device_id.rs +++ b/rust/kernel/device_id.rs @@ -136,7 +136,7 @@ impl IdTable f= or IdArray { fn as_ptr(&self) -> *const T::RawType { // This cannot be `self.ids.as_ptr()`, as the return pointer must = have correct provenance // to access the sentinel. - (self as *const Self).cast() + core::ptr::from_ref(self).cast() } =20 fn id(&self, index: usize) -> &T::RawType { diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index e9bfbad00755..35fd5db35c46 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -366,7 +366,7 @@ fn deref(&self) -> &LocalFile { // // By the type invariants, there are no `fdget_pos` calls that did= not take the // `f_pos_lock` mutex. - unsafe { LocalFile::from_raw_file((self as *const Self).cast()) } + unsafe { LocalFile::from_raw_file(core::ptr::from_ref(self).cast()= ) } } } =20 diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 43597eb7c5c1..cbc8b459ed41 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -29,7 +29,7 @@ pub const fn is_empty(&self) -> bool { #[inline] pub const fn from_bytes(bytes: &[u8]) -> &Self { // SAFETY: `BStr` is transparent to `[u8]`. - unsafe { &*(bytes as *const [u8] as *const BStr) } + unsafe { &*(core::ptr::from_ref(bytes) as *const BStr) } } =20 /// Strip a prefix from `self`. Delegates to [`slice::strip_prefix`]. @@ -290,7 +290,7 @@ pub const fn from_bytes_with_nul(bytes: &[u8]) -> Resul= t<&Self, CStrConvertError #[inline] pub unsafe fn from_bytes_with_nul_unchecked_mut(bytes: &mut [u8]) -> &= mut CStr { // SAFETY: Properties of `bytes` guaranteed by the safety precondi= tion. - unsafe { &mut *(bytes as *mut [u8] as *mut CStr) } + unsafe { &mut *(core::ptr::from_mut(bytes) as *mut CStr) } } =20 /// Returns a C pointer to the string. diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs index 6d70edd8086a..4ef13cf13a78 100644 --- a/rust/kernel/uaccess.rs +++ b/rust/kernel/uaccess.rs @@ -240,7 +240,7 @@ pub fn read_raw(&mut self, out: &mut [MaybeUninit])= -> Result { pub fn read_slice(&mut self, out: &mut [u8]) -> Result { // SAFETY: The types are compatible and `read_raw` doesn't write u= ninitialized bytes to // `out`. - let out =3D unsafe { &mut *(out as *mut [u8] as *mut [MaybeUninit<= u8>]) }; + let out =3D unsafe { &mut *(core::ptr::from_mut(out) as *mut [Mayb= eUninit]) }; self.read_raw(out) } =20 @@ -355,7 +355,7 @@ pub fn write(&mut self, value: &T) -> Resul= t { let res =3D unsafe { bindings::_copy_to_user( self.ptr as *mut c_void, - (value as *const T).cast::(), + core::ptr::from_ref(value).cast::(), len, ) }; diff --git a/rust/uapi/lib.rs b/rust/uapi/lib.rs index 08e68ebef606..31c2f713313f 100644 --- a/rust/uapi/lib.rs +++ b/rust/uapi/lib.rs @@ -16,6 +16,7 @@ clippy::all, clippy::cast_lossless, clippy::ptr_as_ptr, + clippy::ref_as_ptr, clippy::undocumented_unsafe_blocks, dead_code, missing_docs, --=20 2.49.0