diff options
author | Onur Özkan <work@onurozkan.dev> | 2025-06-18 12:28:10 +0300 |
---|---|---|
committer | Stephen Boyd <sboyd@kernel.org> | 2025-06-19 12:48:41 -0700 |
commit | 2a7b4b228cbcebe273d9f4206ed8ee9cbba70ab0 (patch) | |
tree | 5628e1ad17f2292354ab4479c7ba83fb7e63836f /rust/kernel | |
parent | b112dfc74b2040721959935b317d784455c5f635 (diff) |
rust: replace literals with constants in `clk::Hertz`
Replaces repeated numeric literals in `Hertz` conversions
with named constants.
Signed-off-by: Onur Özkan <work@onurozkan.dev>
Link: https://lore.kernel.org/r/20250618092810.29370-1-work@onurozkan.dev
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/clk.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs index d5b1112102e1..fbcea31dbcca 100644 --- a/rust/kernel/clk.rs +++ b/rust/kernel/clk.rs @@ -30,19 +30,23 @@ use crate::ffi::c_ulong; 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 const 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 const 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 const 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 @@ impl Hertz { /// Get the frequency in kilohertz pub const fn as_khz(&self) -> c_ulong { - self.0 / 1_000 + self.0 / Self::KHZ_TO_HZ } /// Get the frequency in megahertz pub const fn as_mhz(&self) -> c_ulong { - self.0 / 1_000_000 + self.0 / Self::MHZ_TO_HZ } /// Get the frequency in gigahertz pub const fn as_ghz(&self) -> c_ulong { - self.0 / 1_000_000_000 + self.0 / Self::GHZ_TO_HZ } } |