All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: make `clk::Hertz` methods const
@ 2025-06-18  9:14 Onur Özkan
  2025-06-18  9:22 ` Alice Ryhl
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Onur Özkan @ 2025-06-18  9:14 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

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>
---
 rust/kernel/clk.rs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index 6041c6d07527..ef0a2edd52c3 100644
--- a/rust/kernel/clk.rs
+++ b/rust/kernel/clk.rs
@@ -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


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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18  9:14 [PATCH] rust: make `clk::Hertz` methods const Onur Özkan
2025-06-18  9:22 ` Alice Ryhl
2025-06-19 10:34 ` Viresh Kumar
2025-06-19 13:41 ` Alexandre Courbot
2025-06-19 19:42 ` Stephen Boyd

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.