mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Onur Özkan" <work@onurozkan.dev>
To: rust-for-linux@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: mturquette@baylibre.com, sboyd@kernel.org, ojeda@kernel.org,
	alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
	bjorn3_gh@protonmail.com, lossin@kernel.org,
	a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
	dakr@kernel.org, "Onur Özkan" <work@onurozkan.dev>
Subject: [PATCH] rust: replace literals with constants in `clk::Hertz`
Date: Wed, 18 Jun 2025 12:28:10 +0300	[thread overview]
Message-ID: <20250618092810.29370-1-work@onurozkan.dev> (raw)

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


             reply	other threads:[~2025-06-18  9:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  9:28 Onur Özkan [this message]
2025-06-19 10:34 ` Viresh Kumar
2025-06-19 13:43 ` Alexandre Courbot
2025-06-19 19:50 ` Stephen Boyd

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=20250618092810.29370-1-work@onurozkan.dev \
    --to=work@onurozkan.dev \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tmgross@umich.edu \
    /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

all inboxes | Powered by JetHome®