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 8A68DC7115A for ; Sun, 15 Jun 2025 20:55:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F39F8D0003; Sun, 15 Jun 2025 16:55:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A3968D0001; Sun, 15 Jun 2025 16:55:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86BC58D0003; Sun, 15 Jun 2025 16:55:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 722028D0001 for ; Sun, 15 Jun 2025 16:55:25 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 35625C1BB3 for ; Sun, 15 Jun 2025 20:55:25 +0000 (UTC) X-FDA: 83558840610.28.A11859D Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf13.hostedemail.com (Postfix) with ESMTP id 444AA20006 for ; Sun, 15 Jun 2025 20:55:23 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SEFAofBv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of tamird@gmail.com designates 209.85.219.48 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=1750020923; 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=EzIO770K3BEzT6LTWkTmJxAe6XJ7JYWo5FVTqpGa1qI=; b=3D1M2S9rKQRSp6GGQWczBKZlzziBkhgkwFHfSetJRhDxpvXh5mpPMhF1pEAru850VULx8F 1oQFDDeS1Cue2JHLEnnl0tUCfxB4Pvf30Clm4NwAsn2c6wrztJXHQSXG0GK8GTd3+aggDz rO0zAmyZGPuzG/1vyFdNzjME+pq1emo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750020923; a=rsa-sha256; cv=none; b=PMypV/YfvqmDJbuDEpHFSubbxNboP773RUkX8j5ZOv3bGAcnalBYRT8U8BE22VqPRMxYba ePCnTrhoSeuToGBM1QaMCjiHchB8qh4m+/vMgZq0ylW4y4+pOJg7s8i8COv7h9HSAFPdNY qHRU+Tpa47r85sY+3KwRp03ig/eUl5k= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SEFAofBv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of tamird@gmail.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=tamird@gmail.com Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6fb3bba0730so36734916d6.0 for ; Sun, 15 Jun 2025 13:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750020921; x=1750625721; 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=EzIO770K3BEzT6LTWkTmJxAe6XJ7JYWo5FVTqpGa1qI=; b=SEFAofBv+tANWq2YfA8i2mX6MI4feOSlPIZu07+8QKEvS/u/497APPK9FxaXYeWyqu WrGpWQRe0MyHlBYy5f24xR2EsuKUrhOyN9ugQv1vTHCcdFj9Z1/VhlXMzW907ilN8IrN dQegdAgdAzfrRFFuGe82iEAr2mFShhHVHbECmP1z6jcSpbpyBUbPO2f5dHybvkdY+dBR M+1sF9+q8e+P1Ven0C3rQl18htcWvtg36DTEEzQBNC0F9wGS4U57wYSGGF3H0JbJJZG5 lz70F13wBMFgk8EGP+je1DHjzylgJT1CEGqdMEqrFHj7svB5+di0owInXylPaX0l1p5+ U4XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750020921; x=1750625721; 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=EzIO770K3BEzT6LTWkTmJxAe6XJ7JYWo5FVTqpGa1qI=; b=Li0hhFT6h1bk4UkaYeWnTVUi1ohrALfcTT3ZHck1fHcGQ2hVudVFWtkpiPv/Vb9yEF oPRQvkuz6kveOfU6D0XZt/fNv89qclv6Xdn8F8gfQszOAvXYGbOemtwI9fr0vVYV9xhJ bc2C/dvKBMOXHS3cWpIjQqyYq4bL4aUN39kyQvlFbclEG9S0EIyN+9gbt2oiyXQfHKPD dzyzcVSq9xWq+uXtwfXU2QKj63Lgv9FOdlyY2iWSN0z2oRdF/NgM2hrGUGAyP5s2hyHL DC9TwjChxKTAZqzV72Ancp88Wb0JOe5aUPObZccZGqQpIkaeRe7CLrpNWbSFKq0VOzj0 s+Ig== X-Forwarded-Encrypted: i=1; AJvYcCUolBnikkbbDZmwT4ABBW02L5tay4ogI7ZH2nHwwTgkCeJKA0lmZu+rS08GqMLhyRM+PNaVOVWS4A==@kvack.org X-Gm-Message-State: AOJu0YycN/odb6IX1Eu+CPwXKK4s+S+Y6YGmXtSZ2KS1uUtFx2581Lxh j8YvPfPb/5uSy3AyEhhTkmaAEwWpOAfbGvoN0RrlQzTuJP6gjM0wC5EQ1nMbWNG1 X-Gm-Gg: ASbGncvIPF6NKaCpeZ3YV7IC515pmVbbwU9erxhPKVjtBwUTsA1fcHjO/x2YNBenxq+ RwzeQELs59dlgxzbiuYUSXp0rO7x2IL/a7qjcxvK3b6o7sJeyIDuqh4kP3+QPfKfHjXRNYTRy5x +G6T7DReUWeSm4Dl7hQI5THw1+zkD32ew8Riv6pVMD+XSEuEcAB2Sgvo7UZ3A3EetoC/k3oyYoR ueyktjI6+wzFFBlJSXZ6jOnJ0WJ3cYhhsIbXt61+9NS5h8JSRnVDYlkSgv0YitvwO3cBGk1t4e3 isq1Atawd5/eX9M0C8YZkl3n90PP94bI5TdC4bVAH9/BxrrcF6pzPUqupC4zZLIuYgql2Q== X-Google-Smtp-Source: AGHT+IHuJ5ATyUdQgk4pt9BONn4x9zspwvV+2Gm1qDCe2qRdxVwp1sIbazWwdq/xR0732z5MemwTXw== X-Received: by 2002:a05:6214:2529:b0:6fa:b467:aa67 with SMTP id 6a1803df08f44-6fb45c26e75mr137361606d6.20.1750020921472; Sun, 15 Jun 2025 13:55:21 -0700 (PDT) Received: from tamird-mac.local ([2600:4041:5be7:7c00:b0c6:92db:d807:21a6]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6fb35c84148sm43468176d6.109.2025.06.15.13.55.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jun 2025 13:55:21 -0700 (PDT) From: Tamir Duberstein Date: Sun, 15 Jun 2025 16:55:09 -0400 Subject: [PATCH v12 5/6] rust: enable `clippy::cast_lossless` lint MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20250615-ptr-as-ptr-v12-5-f43b024581e8@gmail.com> References: <20250615-ptr-as-ptr-v12-0-f43b024581e8@gmail.com> In-Reply-To: <20250615-ptr-as-ptr-v12-0-f43b024581e8@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" , Breno Leitao , Viresh Kumar , 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, linux-pm@vger.kernel.org, nouveau@lists.freedesktop.org, Tamir Duberstein , Benno Lossin X-Mailer: b4 0.15-dev X-Stat-Signature: 1ox748wu57s375ccip94idcpruh5scdx X-Rspamd-Queue-Id: 444AA20006 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1750020923-500166 X-HE-Meta: U2FsdGVkX1+Drtisz3v5aB40Jj7rHXccSu7SfgbhDHjYKX4JqL+n9qeE66eoP0B1H5XiRHLRQ7EVQAGsk07dNqTGbBgvaLw7bGKuPtKM6+iU2esYFTJc7oqjR+iH10gMuYAewZkYvT/R0sXZqdhyE5pPoYc+YP9SbFekIENqizunUYOMhEL0Q2lc7PkzwzsdC8+/JcmJBgrmaJDzmWsP646g72eU/aI6J0nuWoGnMcJtDq8v1JhwHEegBrlyc/O0aAQc52KTQQ75w4VmU6gqrW5aFzLiM9Cwb063LtbBxJw7My0eUPwn8sytKhJCYcRvA8gJ++E3ZvLcPb6kGwPwIWHDgOXYUQ7JGiALevtYAkFhrohHpJ5rIy9DHbozJ2GH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h/zHbP73OUgKSLFwmU2BERo6vZ06jpCqJzoccCVOjKeLGNSWUXhdPdUsPMomcJTuv1WdSRVvVwIENERM4F9/pvsIgpyHXaoIDd/VE3QYe6tLn225KaZQ49QdyoM6Z3oStgSrrQMw8I6P0Ag7PgykklUXNoGhz8wu67YSg== 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: Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]: > Rust’s `as` keyword will perform many kinds of conversions, including > 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_lossless [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 ++-- drivers/gpu/nova-core/regs.rs | 2 +- drivers/gpu/nova-core/regs/macros.rs | 2 +- rust/bindings/lib.rs | 1 + rust/kernel/net/phy.rs | 4 ++-- rust/uapi/lib.rs | 1 + 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0ba22c361de8..29cf39be14de 100644 --- a/Makefile +++ b/Makefile @@ -481,6 +481,7 @@ export rust_common_flags := --edition=2021 \ -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 = 0; let mut exp = 1; for i in 0..poplen { - out += self.decimals[self.len + i] as u16 * exp; + out += u16::from(self.decimals[self.len + i]) * exp; exp *= 10; } Some((out, NUM_CHARS_BITS[poplen])) @@ -425,7 +425,7 @@ fn next(&mut self) -> Option { match self.segment { Segment::Binary(data) => { if self.offset < data.len() { - let byte = data[self.offset] as u16; + let byte = u16::from(data[self.offset]); self.offset += 1; Some((byte, 8)) } else { diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs index 5a1273230306..c1cb6d4c49ee 100644 --- a/drivers/gpu/nova-core/regs.rs +++ b/drivers/gpu/nova-core/regs.rs @@ -32,7 +32,7 @@ pub(crate) fn architecture(self) -> Result { pub(crate) fn chipset(self) -> Result { self.architecture() .map(|arch| { - ((arch as u32) << Self::IMPLEMENTATION.len()) | self.implementation() as u32 + ((arch as u32) << Self::IMPLEMENTATION.len()) | u32::from(self.implementation()) }) .and_then(Chipset::try_from) } diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/regs/macros.rs index 7ecc70efb3cd..6851af8b5885 100644 --- a/drivers/gpu/nova-core/regs/macros.rs +++ b/drivers/gpu/nova-core/regs/macros.rs @@ -264,7 +264,7 @@ pub(crate) fn $field(self) -> $res_type { pub(crate) fn [](mut self, value: $to_type) -> Self { const MASK: u32 = $name::[<$field:upper _MASK>]; const SHIFT: u32 = $name::[<$field:upper _SHIFT>]; - let value = ((value as u32) << SHIFT) & MASK; + let value = (u32::from(value) << SHIFT) & MASK; self.0 = (self.0 & !MASK) | value; self 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 @@ )] #[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_transmutes))] 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 = unsafe { &(*self.0.get())._bitfield_1 }; - bit_field.get(13, 1) == bindings::AUTONEG_ENABLE as u64 + bit_field.get(13, 1) == u64::from(bindings::AUTONEG_ENABLE) } /// 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 = unsafe { Device::from_raw(phydev) }; - T::match_phy_device(dev) as i32 + T::match_phy_device(dev).into() } /// # 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, -- 2.49.0