Skip to contentSkip to conversation

rust: make `clk::Hertz` methods const

PATCH Applied Onur Özkan 5 participants 5 messages Jun 18, 2025 – Jun 19, 2025

Subsystems (2)
lore
Share & tools
lore

Onur Özkan

author reviewer
#0 lore raw

PATCH 1/1 rust: make `clk::Hertz` methods const

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.

---
 rust/kernel/clk.rs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
rust/kernel/clk.rs +7 -7
index 6041c6d07527..ef0a2edd52c3 100644
@@ -31,37 +31,37 @@
 
 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
     }
 }

2.49.0

maintainer Applied
#4 lore raw
In reply to Onur Özkan

Quoting Onur Özkan (2025-06-18 02:14:42)

Quoted 6 lines

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.

---

Applied to clk-next