rust: replace literals with constants in `clk::Hertz`
Subsystems (2)
Onur Özkan
reviewerPATCH 1/1 rust: replace literals with constants in `clk::Hertz`
Replaces repeated numeric literals in Hertz conversions with named constants.
Signed-off-by Onur Özkan <[email protected]>
--- rust/kernel/clk.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
rust/kernel/clk.rs +10 -6
@@ -30,19 +30,23 @@pub struct Hertz (pub c_ulong );impl Hertz { +const KHZ_TO_HZ :c_ulong =1_000 ; +const MHZ_TO_HZ :c_ulong =1_000_000 ; +const GHZ_TO_HZ :c_ulong =1_000_000_000 ; +/// Create a new instance from kilohertz (kHz) pub fn from_khz (khz:c_ulong ) ->Self { -Self (khz *1_000 ) +Self (khz *Self ::KHZ_TO_HZ ) }/// Create a new instance from megahertz (MHz) pub fn from_mhz (mhz:c_ulong ) ->Self { -Self (mhz *1_000_000 ) +Self (mhz *Self ::MHZ_TO_HZ ) }/// Create a new instance from gigahertz (GHz) pub fn from_ghz (ghz:c_ulong ) ->Self { -Self (ghz *1_000_000_000 ) +Self (ghz *Self ::GHZ_TO_HZ ) }/// Get the frequency in hertz
@@ -52,17 +56,17 @@ pub fn as_hz(&self) -> c_ulong {/// Get the frequency in kilohertz pub fn as_khz (&self) ->c_ulong { - self.0 /1_000 + self.0 /Self ::KHZ_TO_HZ }/// Get the frequency in megahertz pub fn as_mhz (&self) ->c_ulong { - self.0 /1_000_000 + self.0 /Self ::MHZ_TO_HZ }/// Get the frequency in gigahertz pub fn as_ghz (&self) ->c_ulong { - self.0 /1_000_000_000 + self.0 /Self ::GHZ_TO_HZ } }
2.49.0
Quoted 8 lines · Onur Özkan
Replaces repeated numeric literals in
Hertzconversions with named constants.Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/clk.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
Acked-by Viresh Kumar <[email protected]>
Quoted 4 lines · Onur Özkan
Replaces repeated numeric literals in
Hertzconversions with named constants.Signed-off-by Onur Özkan <[email protected]>
FWIW,
Reviewed-by Alexandre Courbot <[email protected]>
Quoting Onur Özkan (2025-06-18 02:28:10)
Quoted 5 lines
Replaces repeated numeric literals in
Hertzconversions with named constants.Signed-off-by Onur Özkan <[email protected]>---
Applied to clk-next