rust: make `clk::Hertz` methods const
authorOnur Özkan <work@onurozkan.dev>
Wed, 18 Jun 2025 09:14:42 +0000 (12:14 +0300)
committerStephen Boyd <sboyd@kernel.org>
Thu, 19 Jun 2025 19:42:26 +0000 (12:42 -0700)
Marks `Hertz` methods as `const` to make them available
for `const` contexts. This can be useful when defining
static/compile-time frequency parameters in drivers/subsystems.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
Link: https://lore.kernel.org/r/20250618091442.29104-1-work@onurozkan.dev
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
rust/kernel/clk.rs

index 6041c6d0752701a4ffb2eea7d14f9325efeaa6b9..ef0a2edd52c35a4c4094db40bdeea95bb4bc0a1f 100644 (file)
@@ -31,37 +31,37 @@ pub struct Hertz(pub c_ulong);
 
 impl Hertz {
     /// Create a new instance from kilohertz (kHz)
-    pub fn from_khz(khz: c_ulong) -> Self {
+    pub const fn from_khz(khz: c_ulong) -> Self {
         Self(khz * 1_000)
     }
 
     /// Create a new instance from megahertz (MHz)
-    pub fn from_mhz(mhz: c_ulong) -> Self {
+    pub const fn from_mhz(mhz: c_ulong) -> Self {
         Self(mhz * 1_000_000)
     }
 
     /// Create a new instance from gigahertz (GHz)
-    pub fn from_ghz(ghz: c_ulong) -> Self {
+    pub const fn from_ghz(ghz: c_ulong) -> Self {
         Self(ghz * 1_000_000_000)
     }
 
     /// Get the frequency in hertz
-    pub fn as_hz(&self) -> c_ulong {
+    pub const fn as_hz(&self) -> c_ulong {
         self.0
     }
 
     /// Get the frequency in kilohertz
-    pub fn as_khz(&self) -> c_ulong {
+    pub const fn as_khz(&self) -> c_ulong {
         self.0 / 1_000
     }
 
     /// Get the frequency in megahertz
-    pub fn as_mhz(&self) -> c_ulong {
+    pub const fn as_mhz(&self) -> c_ulong {
         self.0 / 1_000_000
     }
 
     /// Get the frequency in gigahertz
-    pub fn as_ghz(&self) -> c_ulong {
+    pub const fn as_ghz(&self) -> c_ulong {
         self.0 / 1_000_000_000
     }
 }