rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: replace literals with constants in `clk::Hertz`
@ 2025-06-18  9:28 Onur Özkan
  2025-06-19 10:34 ` Viresh Kumar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Onur Özkan @ 2025-06-18  9:28 UTC (permalink / raw)
  To: rust-for-linux, linux-clk, linux-kernel
  Cc: mturquette, sboyd, ojeda, alex.gaynor, boqun.feng, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
	Onur Özkan

Replaces repeated numeric literals in `Hertz` conversions
with named constants.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
 rust/kernel/clk.rs | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index 6041c6d07527..b8c5dafdc29c 100644
--- a/rust/kernel/clk.rs
+++ b/rust/kernel/clk.rs
@@ -30,19 +30,23 @@
 pub struct Hertz(pub c_ulong);

 impl Hertz {
+    const KHZ_TO_HZ: c_ulong = 1_000;
+    const MHZ_TO_HZ: c_ulong = 1_000_000;
+    const GHZ_TO_HZ: c_ulong = 1_000_000_000;
+
     /// Create a new instance from kilohertz (kHz)
     pub fn from_khz(khz: c_ulong) -> Self {
-        Self(khz * 1_000)
+        Self(khz * Self::KHZ_TO_HZ)
     }

     /// Create a new instance from megahertz (MHz)
     pub fn from_mhz(mhz: c_ulong) -> Self {
-        Self(mhz * 1_000_000)
+        Self(mhz * Self::MHZ_TO_HZ)
     }

     /// Create a new instance from gigahertz (GHz)
     pub fn from_ghz(ghz: c_ulong) -> Self {
-        Self(ghz * 1_000_000_000)
+        Self(ghz * Self::GHZ_TO_HZ)
     }

     /// Get the frequency in hertz
@@ -52,17 +56,17 @@ pub fn as_hz(&self) -> c_ulong {

     /// Get the frequency in kilohertz
     pub fn as_khz(&self) -> c_ulong {
-        self.0 / 1_000
+        self.0 / Self::KHZ_TO_HZ
     }

     /// Get the frequency in megahertz
     pub fn as_mhz(&self) -> c_ulong {
-        self.0 / 1_000_000
+        self.0 / Self::MHZ_TO_HZ
     }

     /// Get the frequency in gigahertz
     pub fn as_ghz(&self) -> c_ulong {
-        self.0 / 1_000_000_000
+        self.0 / Self::GHZ_TO_HZ
     }
 }
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: replace literals with constants in `clk::Hertz`
  2025-06-18  9:28 [PATCH] rust: replace literals with constants in `clk::Hertz` Onur Özkan
@ 2025-06-19 10:34 ` Viresh Kumar
  2025-06-19 13:43 ` Alexandre Courbot
  2025-06-19 19:50 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2025-06-19 10:34 UTC (permalink / raw)
  To: Onur Özkan
  Cc: rust-for-linux, linux-clk, linux-kernel, mturquette, sboyd, ojeda,
	alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg,
	aliceryhl, tmgross, dakr

On Wed, Jun 18, 2025 at 3:07 PM Onur Özkan <work@onurozkan.dev> wrote:
>
> Replaces repeated numeric literals in `Hertz` conversions
> with named constants.
>
> Signed-off-by: Onur Özkan <work@onurozkan.dev>
> ---
>  rust/kernel/clk.rs | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: replace literals with constants in `clk::Hertz`
  2025-06-18  9:28 [PATCH] rust: replace literals with constants in `clk::Hertz` Onur Özkan
  2025-06-19 10:34 ` Viresh Kumar
@ 2025-06-19 13:43 ` Alexandre Courbot
  2025-06-19 19:50 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2025-06-19 13:43 UTC (permalink / raw)
  To: Onur Özkan, rust-for-linux, linux-clk, linux-kernel
  Cc: mturquette, sboyd, ojeda, alex.gaynor, boqun.feng, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr

On Wed Jun 18, 2025 at 6:28 PM JST, Onur Özkan wrote:
> Replaces repeated numeric literals in `Hertz` conversions
> with named constants.
>
> Signed-off-by: Onur Özkan <work@onurozkan.dev>

FWIW,

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] rust: replace literals with constants in `clk::Hertz`
  2025-06-18  9:28 [PATCH] rust: replace literals with constants in `clk::Hertz` Onur Özkan
  2025-06-19 10:34 ` Viresh Kumar
  2025-06-19 13:43 ` Alexandre Courbot
@ 2025-06-19 19:50 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2025-06-19 19:50 UTC (permalink / raw)
  To: Onur Özkan, linux-clk, linux-kernel, rust-for-linux
  Cc: mturquette, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, dakr, Onur Özkan

Quoting Onur Özkan (2025-06-18 02:28:10)
> Replaces repeated numeric literals in `Hertz` conversions
> with named constants.
> 
> Signed-off-by: Onur Özkan <work@onurozkan.dev>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-19 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18  9:28 [PATCH] rust: replace literals with constants in `clk::Hertz` Onur Özkan
2025-06-19 10:34 ` Viresh Kumar
2025-06-19 13:43 ` Alexandre Courbot
2025-06-19 19:50 ` Stephen Boyd

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).