[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250618091442.29104-1-work@onurozkan.dev>
Date: Wed, 18 Jun 2025 12:14:42 +0300
From: Onur Özkan <work@...rozkan.dev>
To: rust-for-linux@...r.kernel.org,
linux-clk@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: mturquette@...libre.com,
sboyd@...nel.org,
ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
lossin@...nel.org,
a.hindborg@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu,
dakr@...nel.org,
Onur Özkan <work@...rozkan.dev>
Subject: [PATCH] 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.
Signed-off-by: Onur Özkan <work@...rozkan.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
Powered by blists - more mailing lists