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 5F20FC71157 for ; Wed, 18 Jun 2025 13:52:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0385E6B0089; Wed, 18 Jun 2025 09:52:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F284F6B0093; Wed, 18 Jun 2025 09:52:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E17636B0095; Wed, 18 Jun 2025 09:52:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D05DE6B0092 for ; Wed, 18 Jun 2025 09:52:13 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 79CC7C1C0A for ; Wed, 18 Jun 2025 13:52:13 +0000 (UTC) X-FDA: 83568660546.20.B7BEA65 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf24.hostedemail.com (Postfix) with ESMTP id 7CCCE18000A for ; Wed, 18 Jun 2025 13:52:11 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bYsC5UpM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of tamird@gmail.com designates 209.85.208.169 as permitted sender) smtp.mailfrom=tamird@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750254731; a=rsa-sha256; cv=none; b=TncUt5mtsORMJz8AjXelvTea4glTdH3gt/CCTqc9hJLAqpMUFYeFE5XqZCPAOcDctrGCb8 murAQNgFj8jLHw3LORrNiyo1R5TDfZA50+QhJNKsTU6YAqhVWdjbGmMLQIwCvPEs9yA/nd +sKSHTEOK82wOeO2PdaM9FyvQ8VYKSw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bYsC5UpM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of tamird@gmail.com designates 209.85.208.169 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=1750254731; 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=yHetTVGjM9N9vKhqDfTQfQXf30L+g0MXCJcXiaNoNyE=; b=35TCbc2Jetx+KjKPQlpMFts8RTbO1UAzmjwbpY7A0us8tv1tpw8vKhAhs+1LfbNgOl7HKu Qcbl0NeQx2xyQzS81XKEsrI3i3nap5rOeJupQb13nQwmpVtCX4W+v1y9o/e8I/LbCb/mDb Tq1bdk/vdM2yV7cvDwGzkeyBEF4VeCI= Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-3105ef2a071so71757411fa.1 for ; Wed, 18 Jun 2025 06:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750254730; x=1750859530; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yHetTVGjM9N9vKhqDfTQfQXf30L+g0MXCJcXiaNoNyE=; b=bYsC5UpMhe7p+BwuNqU6o/LSgr4ATLViQfvqrAWLeUmsfhsvKXKxc8Cvk2TJKqxAjt q0r1dycbVHIlpQuQOfkVZ0ren/nQzCzYwAuwmwmCZOOpsAgOS2nzgNd8Bb6ZhnUwiVCW BXKLTLX6gaTHckeuW+3vJkMvYekVksay2EhBo45AfgimX0I4gAEJzhnFetHZubmOU8C+ UwkmedFqRMdN9k7+Zf5L5X2ew4n5Ki5NYezN+PsjT3F8KzgZ1zLCk8SfoJIrpLY/LMPR VGmN3Vd7N2Afy+O8oogB+ZZy9t06jgYz4b9FL9StOqXBYtcY8fmhsTjRxGSoi0pBggrF DGBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750254730; x=1750859530; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yHetTVGjM9N9vKhqDfTQfQXf30L+g0MXCJcXiaNoNyE=; b=VasSqajW4Tv2/+MiDzYW+3EEXfF3o1dil7q6vfKig/f+SDZzSSJfztYsrAt6bcEBrh XM+7UyyMzpYTN9IilOBi/1eNjd0loCZsn42SPNFtDfH8tGjBL4TQjedUH0ZowrxAHvdr /NI9R1153jbvTVUGsnhPuTPtlsk40GL8IHLyuhQ9riGsyYmxVYh2be3W6vTC6oJJdW8c fifNY05YdSS7r2r1SGhDVPybGi6usK4MzWeBx5kguGGueyOyz4RB9ycmHbYyBdy9+cV9 TNMN0D/jboa8tCtEbOcrtL4zxDMLq1jjlemEsl4LIGuDpxwLLrPysybei2CdVMbwyFLy P7Ew== X-Forwarded-Encrypted: i=1; AJvYcCWF3LFgTyVdDMjAC7yt78uHKkpC1cUoFg10VU6F75yILyjE942PTP0kAP6a6IFMt+n6m7snLnGvGA==@kvack.org X-Gm-Message-State: AOJu0YwXev/RyOfy3tBvH0WuGzWdPz+tA6ApBpbQsFMP1qvFog8KYw1G wgw9BV206D0WFSz4kGdOzJlxqSEMwjtARBM+WEmDPDuGV/7hSJ/vvVpGZWeHQFx6IjxSM970UNm z8L+Z6KeERDdiPlG6o9HFxGNHx20xlbg= X-Gm-Gg: ASbGncuuB3K8bbHCb3TPNaMjLDbjic5gBTxQouqAZ3eBW4BBabHKWuTieksr/rwviLM 1sV7Fo5Y9kqKjkRBoEGXo5WUjbNTl1L2eLEveZ+zabtT2eG/jlIpZoMnuGKLg/soqwbd6fnCAxC pryzAy1ELWzf+Ff0kU0Au5mXLJ8MlFhKW5VbmQzgksyrmkg9rkg5jIvQVx/Ik= X-Google-Smtp-Source: AGHT+IHjpP0oUsGl8bs9dihRSaXuYuFr91sSYke6woCI9t3nFqjg18OJME02qGfpZHIEHpORU6xHL6DoZtudcacLwZI= X-Received: by 2002:a05:651c:2203:b0:30b:edfc:5d8a with SMTP id 38308e7fff4ca-32b4a0131c3mr43917741fa.0.1750254729384; Wed, 18 Jun 2025 06:52:09 -0700 (PDT) MIME-Version: 1.0 References: <20250615-ptr-as-ptr-v12-0-f43b024581e8@gmail.com> <20250615-ptr-as-ptr-v12-5-f43b024581e8@gmail.com> In-Reply-To: <20250615-ptr-as-ptr-v12-5-f43b024581e8@gmail.com> From: Tamir Duberstein Date: Wed, 18 Jun 2025 09:51:33 -0400 X-Gm-Features: AX0GCFugcq7xsGtJtMG4-YlwkWLR_JC0Fxzt1KWhWAbz9DyagkQH0rU9bmUM3y8 Message-ID: Subject: Re: [PATCH v12 5/6] rust: enable `clippy::cast_lossless` lint 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 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 7CCCE18000A X-Rspamd-Server: rspam02 X-Stat-Signature: a9xkk18cdbqsftkkedb9gab58rk4fdn3 X-HE-Tag: 1750254731-167635 X-HE-Meta: U2FsdGVkX19zw2HX/TiqjDu6Xf+MaaJQ6YT+6XyivJdRdV1l6tovOc8SrLfzBt8UtzqfcY9tRBwff+Whz4bKTkkMKRyvhJjLZAFy7NF2TvOyfJ7GtrLqI2D2aeZhvEGk0githwMYtRnfisSAIQt3eNq/5lLMDSFgRZ2O+I8s8m2wO6/lueCJBKkWnkSwJhRj2132q5RtXI8P3LmGzFLEV38TvbYIm13waMjq8pHLbZ9/HHQ1h5rjQUs4uz9bXT42woHCPybv8UYR6JvQujcS26RtyU90YMQjfNYi8L2xLtWgfmXh4qOetVaWXddvzcKwWGE9bgQZuHBk2nJASyEperjivOduG6zhfTStEaVzPI0ZULu4dpxQMojoR4blzazlBtAIKw7jE8ADou6CMbElWhXhpZiDST1otH+vGVRRcND6THfe8XSnCZu9f/Q2bgMYbuDkdjhyxG7X0JmJnRiZ+qbbXQ4rw3zahBnGLguO2kaV0lGlHk7BTKrvD/vw0HP/J+wuxCet6ZKeNcscdFU8fd7bktnYOLI0XXClTxw/NN62fHmwj6GDllk4xn9iGGmqCx1L1dhGwvL8FpVF2+5+ps0XiMiUzbSk+uK1KAvBDPuYkJvSJTqi6cxZFCCMkvAdhM7Y0echznb0bT2BSWnb/EHHFjxZYBd+sbzXfA8ly7UZy4lc95zZUs91JI3D5Y3a0LBG7YE/207KfisRR6O5WpICU1mv6FSf8OOWojn+aASyOPNqQUT8cs7Hn8lLEiAcSrsEauN1LWXzPJWmuCYLYgzIzhjQzrbBIz4a54T2in1Jn+a2F3KAUZYUBRqU8LjgjdqkBOLFSPWAJe6pEP/y6t50gJbQbJN5M7iIVG+vjvRvoW++uX+m9sIbwgtP25TYbCOz9vKAPzzX20yOvfV2Zg9nEZv4QGxKgnvrzDMwf5ztzIh1pZ6TuoUvRfaalzrGAfPWJ6PZMFLGWJb7WpK r60cttk8 WxO3vn7E0gUDDafI91V3GBshqKdEqGffTdX88hV+ZHjTOBmPetiTPlGjzc5EaI8U1brAHezUDZPqd5AWhxaX3BSDWAOFjwZvkCDZQIr6ayJSbd906+Z60XNPFHeoZVOUsWOeJEgicK4DgVhp4U0oO2ww7QG/AqWxmt0cy1+vZTW3Whw1ZG0S6uQpud4WdqltjeIMLnnza7fwpYCMkvw4CGqn4vPCirODJmYmvzyM0jj/DZgaxUAu4tmJc/Ai26cXDd0nKX55TeEsQZUtRkVE/th6vqLj208H86lD+wr24JxlamS+YhnE5ugp6p4Vv0ljWpVSSvuWR42E+Kg8fM6hubf1tDeZg+uuUg0shjrgcABIDhLsGBKBRAF2VvGTELnpAsk6tWVzwgwIepNtpLR0GB/WbMuQxDjDIc4UYVQHz4IB5kWJspac96sL7TCR0w4oiesJD26WXw39YZ42X7TOo452dLBRajvzlDmXzGc63FBX5TBmzxALl7EapG452XTsdPtgmkBdKayycAKVws7Btj+wPE4HUd3Y7f/Z4 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: On Sun, Jun 15, 2025 at 4:55=E2=80=AFPM Tamir Duberstein = wrote: > > Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]: > > > Rust=E2=80=99s `as` keyword will perform many kinds of conversions, inc= luding > > 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_loss= less [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 @Danilo Krummrich could you please have a look for drm and nova? > --- > 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 :=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/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.r= s > 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.imp= lementation() as u32 > + ((arch as u32) << Self::IMPLEMENTATION.len()) | u32::fro= m(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 =3D $name::[<$field:upper _MASK>]; > const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; > - let value =3D ((value as u32) << SHIFT) & MASK; > + let value =3D (u32::from(value) << SHIFT) & MASK; > self.0 =3D (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_tr= ansmutes))] > 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) > } > > /// 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() > } > > /// # 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 >