From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4D15C677C4 for ; Wed, 11 Jun 2025 10:23:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 403A06B009B; Wed, 11 Jun 2025 06:23:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B46E6B009C; Wed, 11 Jun 2025 06:23:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 254BA6B009D; Wed, 11 Jun 2025 06:23:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 05D426B009B for ; Wed, 11 Jun 2025 06:23:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B525F1D52E4 for ; Wed, 11 Jun 2025 10:23:52 +0000 (UTC) X-FDA: 83542733904.15.91AB13D Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf26.hostedemail.com (Postfix) with ESMTP id EC5EE140012 for ; Wed, 11 Jun 2025 10:23:50 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ijLluZJ+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of tamird@gmail.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=tamird@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749637431; a=rsa-sha256; cv=none; b=e+foW6E9CpPrDimgCyz93eNiVG5XRoBqnrtqlK2nXA1dKJRROLrpc3KwtpkfWDTh+wiMFH grq39okjL5st6YLQK5Qy2xanEN8gIsSvl4F8oJQo1oE/hAQBUzG+eSvzlKrn3LfsPNHaUz u0iNqT34R7s86OWxacmt2ziFioJeHpg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ijLluZJ+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of tamird@gmail.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=tamird@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749637431; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=b2miWcRt7MptMpkkpbvEAaiGbbGDGe5gQtbWu3GJa1w=; b=ZEFkd/1bYrKB20Tw5LZk9TH9AEHjxU5nNwKS25j0tC8OSG6SIvWM1Ad2aewtCsaDjQRPGa EJEl8WRnCyRr9u2UefiZCZ6XIyfqKkR5mlyOKAXIWq0zUZBQThIJ5337fV6bNxnABP6LHi S+3GIyHS/r3R+X+kT7NH67hLfNt7bHM= Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-4a52d82adcaso95881281cf.0 for ; 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=kvack.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=ijLluZJ+YsPqYh9SJxqPvsGm8VCyuyMQr8eFVo7qN1Kj2jP3OshmYfNPZ+Q7ClT60M ChHxTcDaCOp/Ewx86QzX77YYuDytmx/rFZkk9muB4Bz4yVl337NgEfpmBhYV0cpmL+I8 uTiiAT2Ko0JrtzpAROJ2sWwkWHHFqBtUj3rPqAe2smTbH2QmjM03G0Znt/pMUT4VfMrR DSz+AslKT84FERPrRNTw4HEtyuNEJELcERrytNIOgaTIHo9hhW9fUgjrtuutYEAejYNZ MNNFdU/qJ9ezNQyi/OLHDPgOgyyKhaVq2pT7Voc/5gCcr7ztA9Nc+UvW9WK7kUwyEukl x9cg== 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=xUYB2vyadkveCZlBRoe5WXFTOg1t0dMV2rDHJlmuy7ZWiD0bmul9j7X/29qXInFuLy HUPu1ttVvGPxltP+jc4d/cCX7Uq/IvvcztQ6b4lw4J66h8ktCAMQWu/RZOCp3KPqGnOH r7E43S5xTNrezE1WjZzQXR5TKCX9I91ec5qbryGNeH4/hNps0jTgEOt8lQleqUvb8AuA wILsywcvpT4iWssvLyUHwIdCXdNsSQSM2YqyM8OEW4qGYZPlqYD4sOp5+iCoxTK3K/Lp OmQ6qAdstulyqXA/zWkfTMGFgw4+grx5l5MuvgQDSsXCeezyUHKyXJYc/yml8+KuRGDr +pnw== X-Forwarded-Encrypted: i=1; AJvYcCWBlDakjdAOnK8hlG/HXxmO0InfHtlup6N/BKKlHqxkMCHK/VkYjDV/STOFBtZJZLixuvQxlSvOVw==@kvack.org X-Gm-Message-State: AOJu0YwUOJly7xjAHVCZ/yOSWsjH+YZZFvnlNrfLyZTgiZiCsr/4Hm6k 9B+mLziucfOT2a/xBZtILB3PjwqddYWw9InHOlQ3u3OWMomIGM7yEsPH X-Gm-Gg: ASbGncuoEMwvxt5sd4WAn2NRI5sBLQ0W6kyKO6p4ulazDhasIz6OXEEZ6mgm+GIaXsa HhYHg1nYts4+ca3vYFkciv3k5c0CNtGlTVQ/vNU2EnIlMqG0DpM/unAShV4SUTONQT0f8yIYiAc Upbq2bEqxoLL0TkM998qHCKz99924QIi9ZDqt81iaHsqo1CVXhxlrhRQIC1mB8o7pChUxhFpP3p S3aVK4GiFBHhGkTclpWMmcWwLO5+PlDExgzs9QKhbYsfhxfJ7uy9qrPpG6sjDjOsP6WH2KgjFJP SDlNF8SJVc3oq6efnX91WThNRUH6OXpmqJVKKlK/ykfyNw5JopGYL3ysFmWDNp6cUwI= 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 X-Rspamd-Server: rspam01 X-Stat-Signature: zpwsa65ku1fb1jmcjs9dns45zwqqzfo6 X-Rspamd-Queue-Id: EC5EE140012 X-Rspam-User: X-HE-Tag: 1749637430-828344 X-HE-Meta: U2FsdGVkX1+TYeCSganGB004N9qZv0qg/NHoMwu3cjh2Kg4+OuDKVZGkVytyGRMogw5R7vi5NO/xkhnhgl2A9rYlj5v4TwWIsoiogBsWDZVFw43wcP3bAZW821k2N8V8F3koZvZFkDMM0OPLrVx09NJarUm7wnJdEA+FOb1d7PHch0BhK2yT89+ylh1/z5w+e2vsSG/2CDYqrJIg6s/Pt3pKexg6Py6liGeXqUv7FTHA/gPwdYbRYVTz2ykRTX8jqOj8rlsYcvXE1u1IKP31np4gsQiS5jGGZz29LHmev+1GBx5Y5pAm032oqsbiMtVxurzpGKjPbxq5gjEbALV3/BgWyf8SX9pzoDMFw7TpDu7ZhgjIT2pfeykBvJoOJRBbCIb0AEqVRqVkwxfiSbAUIhHnmbD+GXAFsrlVNyBTGlwSrFvES3jqPFAcI3cSXv4ur2BfIO4r+1nnP2KsCyBB9MdQTvml5h04mPJnD+7rMQLWSxV2dI4U7tF/78XLj9R/kdY64YfZ/oMpJSn4ZCS9SckunoH4fGfGyIOBFI/C/JhzdNw2+rNlLYLw8oq66wwF3HXDlneuZWj3/nPOQUJINGZbRMz3l11nsknx6plAR1AcJVcW8vRRCkNi+Xjk9OFQ5tJVpDZsH+bYrWHYp7iJo5UVveWJHzUkOewqFhxRwYH0ate+lC7ZJIVwk9wWwVTaXeWN0H1vjr4f6LTgNUqogMiWEcRnxfDHMcrylgHvfFgyocVeWhEy5qFHjagE8v077DVj/gQje1VZBF8OIrrz6WAmMlXG83pH4sBrqfz2NvvcCrXX7ZyRJhrY7uwv1ysClrOoma/bJg4VAKAcRIezO4B2wsx7NwMVpPkfgFBTuWxCyvYsvlkDqskB3k72okAM08m/qoc1fi72PdQR5nvdhjZCIuzI6HOrQ3N53iSTbPP4l5qbd9vUauZsi4y76L19qEJXof/6gieWIUGt01A 4tqfKQ5R LtXILW0foQcFjjmSWcykyL5SKe9h0fkDZigYNDnaQCBohGLvvujCgP3uP1JYU9gNaimSgogeFjw1a0QlAi8Um1ZE6YzuJGeNblSzW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 := --edition=2021 \ -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_transmutes))] 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 for 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() } 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()) } } } 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) } } /// Strip a prefix from `self`. Delegates to [`slice::strip_prefix`]. @@ -290,7 +290,7 @@ pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&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 precondition. - unsafe { &mut *(bytes as *mut [u8] as *mut CStr) } + unsafe { &mut *(core::ptr::from_mut(bytes) as *mut CStr) } } /// 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 uninitialized bytes to // `out`. - let out = unsafe { &mut *(out as *mut [u8] as *mut [MaybeUninit]) }; + let out = unsafe { &mut *(core::ptr::from_mut(out) as *mut [MaybeUninit]) }; self.read_raw(out) } @@ -355,7 +355,7 @@ pub fn write(&mut self, value: &T) -> Result { let res = 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, -- 2.49.0