Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Gary Guo <gary@kernel.org>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-pci@vger.kernel.org,
	"Gary Guo" <gary@garyguo.net>
Subject: Re: [PATCH] rust: num: remove narrowing `uX_into_uY` functions
Date: Wed, 2 Dec 2026 21:36:51 -0500	[thread overview]
Message-ID: <axDVw_aHGbI1p8Ha@yury> (raw)
In-Reply-To: <20261130-dev-num-v1-1-a1b907bfd440@garyguo.net>

On Mon, Nov 30, 2026 at 02:18:27PM +0000, Gary Guo wrote:
> From: Gary Guo <gary@garyguo.net>
> 
> Their functionality has been superseded by the `cv!` macro. Thus remove
> them.
> 
> Signed-off-by: Gary Guo <gary@garyguo.net>

Acked-by: Yury Norov <ynorov@nvidia.com>

> ---
>  rust/kernel/num/casts.rs | 56 ------------------------------------------------
>  rust/kernel/pci/cap.rs   |  2 +-
>  2 files changed, 1 insertion(+), 57 deletions(-)
> 
> diff --git a/rust/kernel/num/casts.rs b/rust/kernel/num/casts.rs
> index 7e6c7dec747d..85966c570dcb 100644
> --- a/rust/kernel/num/casts.rs
> +++ b/rust/kernel/num/casts.rs
> @@ -20,10 +20,6 @@
>  //! - Two extension traits, [`FromSafeCast`] and [`IntoSafeCast`], providing conversion methods
>  //!   similar to [`From`] and [`Into`] for conversions that are safe to perform in the kernel, but
>  //!   not supported by the standard library.
> -//! - Another series of const functions (e.g. [`u64_into_u8`]) supporting the conversion of a const
> -//!   value from a larger type into a smaller one, provided the value fits into the destination
> -//!   type. This is useful if a constant is defined as a larger type, but needs to be used as a
> -//!   smaller one.
>  //! - An [`arch`] sub-module, defining more conversion functions that are only guaranteed to be
>  //!   lossless for a given pointer size. These can only be used in code that is specific to a
>  //!   given pointer size.
> @@ -182,58 +178,6 @@ fn into_safe_cast(self) -> T {
>      }
>  }
>  
> -/// Implements lossless conversion of a constant from a larger type into a smaller one.
> -macro_rules! impl_const_into {
> -    ($from:ty => { $($into:ty),* }) => {
> -        $(
> -        $crate::macros::paste! {
> -            #[doc = ::core::concat!(
> -                "Performs a build-time safe conversion of a [`",
> -                ::core::stringify!($from),
> -                "`] constant value into a [`",
> -                ::core::stringify!($into),
> -                "`].")]
> -            ///
> -            /// This checks at compile-time that the conversion is lossless, and triggers a build
> -            /// error if it isn't.
> -            ///
> -            /// # Examples
> -            ///
> -            /// ```
> -            /// use kernel::num::casts;
> -            ///
> -            /// // Succeeds because the value of the source fits into the destination's type.
> -            #[doc = ::core::concat!(
> -                "assert_eq!(casts::",
> -                ::core::stringify!($from),
> -                "_into_",
> -                ::core::stringify!($into),
> -                "::<1",
> -                ::core::stringify!($from),
> -                ">(), 1",
> -                ::core::stringify!($into),
> -                ");")]
> -            /// ```
> -            #[inline]
> -            pub const fn [<$from _into_ $into>]<const N: $from>() -> $into {
> -                // Make sure that the target type is smaller than the source one.
> -                $crate::static_assert!($from::BITS >= $into::BITS);
> -                // CAST: we statically enforced above that `$from` is larger than `$into`, so the
> -                // `as` conversion will be lossless.
> -                $crate::const_assert!(N >= $into::MIN as $from && N <= $into::MAX as $from);
> -
> -                N as $into
> -            }
> -        }
> -        )*
> -    };
> -}
> -
> -impl_const_into!(usize => { u8, u16, u32 });
> -impl_const_into!(u64 => { u8, u16, u32 });
> -impl_const_into!(u32 => { u8, u16 });
> -impl_const_into!(u16 => { u8 });
> -
>  /// Conversions that are only lossless for the current architecture.
>  ///
>  /// # Portability
> diff --git a/rust/kernel/pci/cap.rs b/rust/kernel/pci/cap.rs
> index 62f263ada1b3..803b18862bb5 100644
> --- a/rust/kernel/pci/cap.rs
> +++ b/rust/kernel/pci/cap.rs
> @@ -28,7 +28,7 @@
>  
>  impl ExtCapId {
>      /// Single Root I/O Virtualization.
> -    pub const SRIOV: Self = Self(casts::u32_into_u16::<{ bindings::PCI_EXT_CAP_ID_SRIOV }>());
> +    pub const SRIOV: Self = Self(cv!(bindings::PCI_EXT_CAP_ID_SRIOV));
>  
>      /// Returns the raw PCIe extended capability ID.
>      #[inline]
> 
> ---
> base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
> change-id: 20261130-dev-num-01ef4d69fb1a
> 
> Best regards,
> --  
> Gary Guo <gary@garyguo.net>

      parent reply	other threads:[~2026-12-03  2:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:18 [PATCH] rust: num: remove narrowing `uX_into_uY` functions Gary Guo
2026-11-30 14:21 ` sashiko-bot
2026-11-30 16:44 ` Danilo Krummrich
2026-11-30 23:04 ` Alexandre Courbot
2026-12-03  2:36 ` Yury Norov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axDVw_aHGbI1p8Ha@yury \
    --to=ynorov@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=gary@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox