linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"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>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	rust-for-linux@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3 2/3] rust: Use CpuId in place of raw CPU numbers
Date: Fri, 13 Jun 2025 08:40:01 -0700	[thread overview]
Message-ID: <aExGUZ3H5mZ7Drqd@Mac.home> (raw)
In-Reply-To: <20250612050117.3oi6belkf5lrreoh@vireshk-i7>

On Thu, Jun 12, 2025 at 10:31:17AM +0530, Viresh Kumar wrote:
> On 11-06-25, 09:12, Boqun Feng wrote:
> > I generally found that `u32::from(cpu)` is more clear than `cpu.into()`,
> > but it's up to you. Same for the rest of `cpu.into()` cases.
> 
> Updated as:
> 
> diff --git a/rust/kernel/cpu.rs b/rust/kernel/cpu.rs
> index 7549594fad7f..abc780d7a8ec 100644
> --- a/rust/kernel/cpu.rs
> +++ b/rust/kernel/cpu.rs
> @@ -129,7 +129,7 @@ fn from(id: CpuId) -> Self {
>  /// any references to the CPU device within the notifier's callback.
>  pub unsafe fn from_cpu(cpu: CpuId) -> Result<&'static Device> {
>      // SAFETY: It is safe to call `get_cpu_device()` for any CPU.
> -    let ptr = unsafe { bindings::get_cpu_device(cpu.into()) };
> +    let ptr = unsafe { bindings::get_cpu_device(u32::from(cpu)) };
>      if ptr.is_null() {
>          return Err(ENODEV);
>      }
> diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
> index ea6106db5c29..11b03e9d7e89 100644
> --- a/rust/kernel/cpufreq.rs
> +++ b/rust/kernel/cpufreq.rs
> @@ -527,7 +527,7 @@ pub fn generic_suspend(&mut self) -> Result {
>      #[inline]
>      pub fn generic_get(&self) -> Result<u32> {
>          // SAFETY: By the type invariant, the pointer stored in `self` is valid.
> -        Ok(unsafe { bindings::cpufreq_generic_get(self.cpu().into()) })
> +        Ok(unsafe { bindings::cpufreq_generic_get(u32::from(self.cpu())) })
>      }
>  
>      /// Provides a wrapper to the register with energy model using the OPP core.
> @@ -682,7 +682,7 @@ fn clear_data<T: ForeignOwnable>(&mut self) -> Option<T> {
>  impl<'a> PolicyCpu<'a> {
>      fn from_cpu(cpu: CpuId) -> Result<Self> {
>          // SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
> -        let ptr = from_err_ptr(unsafe { bindings::cpufreq_cpu_get(cpu.into()) })?;
> +        let ptr = from_err_ptr(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) })?;
>  
>          Ok(Self(
>              // SAFETY: The `ptr` is guaranteed to be valid and remains valid for the lifetime of
> diff --git a/rust/kernel/cpumask.rs b/rust/kernel/cpumask.rs
> index 11ddd43edcb5..19c607709b5f 100644
> --- a/rust/kernel/cpumask.rs
> +++ b/rust/kernel/cpumask.rs
> @@ -94,7 +94,7 @@ pub fn as_raw(&self) -> *mut bindings::cpumask {
>      #[inline]
>      pub fn set(&mut self, cpu: CpuId) {
>          // SAFETY: By the type invariant, `self.as_raw` is a valid argument to `__cpumask_set_cpu`.
> -        unsafe { bindings::__cpumask_set_cpu(cpu.into(), self.as_raw()) };
> +        unsafe { bindings::__cpumask_set_cpu(u32::from(cpu), self.as_raw()) };
>      }
>  
>      /// Clear `cpu` in the cpumask.
> @@ -106,7 +106,7 @@ pub fn set(&mut self, cpu: CpuId) {
>      pub fn clear(&mut self, cpu: CpuId) {
>          // SAFETY: By the type invariant, `self.as_raw` is a valid argument to
>          // `__cpumask_clear_cpu`.
> -        unsafe { bindings::__cpumask_clear_cpu(cpu.into(), self.as_raw()) };
> +        unsafe { bindings::__cpumask_clear_cpu(i32::from(cpu), self.as_raw()) };
>      }
>  
>      /// Test `cpu` in the cpumask.
> @@ -115,7 +115,7 @@ pub fn clear(&mut self, cpu: CpuId) {
>      #[inline]
>      pub fn test(&self, cpu: CpuId) -> bool {
>          // SAFETY: By the type invariant, `self.as_raw` is a valid argument to `cpumask_test_cpu`.
> -        unsafe { bindings::cpumask_test_cpu(cpu.into(), self.as_raw()) }
> +        unsafe { bindings::cpumask_test_cpu(i32::from(cpu), self.as_raw()) }
>      }
>  

LGTM,thanks!

Regards,
Boqun

>      /// Set all CPUs in the cpumask.
> 
> -- 
> viresh

  reply	other threads:[~2025-06-13 15:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 13:21 [PATCH V3 0/3] rust: Introduce CpuId and fix cpumask doctest Viresh Kumar
2025-06-10 13:21 ` [PATCH V3 1/3] rust: cpu: Introduce CpuId abstraction Viresh Kumar
2025-06-11 16:07   ` Boqun Feng
2025-06-10 13:21 ` [PATCH V3 2/3] rust: Use CpuId in place of raw CPU numbers Viresh Kumar
2025-06-11 16:12   ` Boqun Feng
2025-06-12  5:01     ` Viresh Kumar
2025-06-13 15:40       ` Boqun Feng [this message]
2025-06-10 13:21 ` [PATCH V3 3/3] rust: cpu: Add CpuId::current() to retrieve current CPU ID Viresh Kumar
2025-06-10 21:23   ` Boqun Feng
2025-06-11  2:28     ` Viresh Kumar
2025-06-10 17:10 ` [PATCH V3 0/3] rust: Introduce CpuId and fix cpumask doctest Miguel Ojeda
2025-06-11  2:18   ` Viresh Kumar

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=aExGUZ3H5mZ7Drqd@Mac.home \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tmgross@umich.edu \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --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;
as well as URLs for NNTP newsgroup(s).