Skip to content

Commit bbbaea8

Browse files
onur-ozkanbebarino
authored andcommitted
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@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>
1 parent 19272b3 commit bbbaea8

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

rust/kernel/clk.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,37 @@ pub struct Hertz(pub c_ulong);
3131

3232
impl Hertz {
3333
/// Create a new instance from kilohertz (kHz)
34-
pub fn from_khz(khz: c_ulong) -> Self {
34+
pub const fn from_khz(khz: c_ulong) -> Self {
3535
Self(khz * 1_000)
3636
}
3737

3838
/// Create a new instance from megahertz (MHz)
39-
pub fn from_mhz(mhz: c_ulong) -> Self {
39+
pub const fn from_mhz(mhz: c_ulong) -> Self {
4040
Self(mhz * 1_000_000)
4141
}
4242

4343
/// Create a new instance from gigahertz (GHz)
44-
pub fn from_ghz(ghz: c_ulong) -> Self {
44+
pub const fn from_ghz(ghz: c_ulong) -> Self {
4545
Self(ghz * 1_000_000_000)
4646
}
4747

4848
/// Get the frequency in hertz
49-
pub fn as_hz(&self) -> c_ulong {
49+
pub const fn as_hz(&self) -> c_ulong {
5050
self.0
5151
}
5252

5353
/// Get the frequency in kilohertz
54-
pub fn as_khz(&self) -> c_ulong {
54+
pub const fn as_khz(&self) -> c_ulong {
5555
self.0 / 1_000
5656
}
5757

5858
/// Get the frequency in megahertz
59-
pub fn as_mhz(&self) -> c_ulong {
59+
pub const fn as_mhz(&self) -> c_ulong {
6060
self.0 / 1_000_000
6161
}
6262

6363
/// Get the frequency in gigahertz
64-
pub fn as_ghz(&self) -> c_ulong {
64+
pub const fn as_ghz(&self) -> c_ulong {
6565
self.0 / 1_000_000_000
6666
}
6767
}

0 commit comments

Comments
 (0)