When upgrading from Fedora 41 to Fedora 43 for CI tests, clippy begins
complaining about not using checked_div instead of manually checking
divisors. Make clippy happy and use checked_div() instead.

Signed-off-by: John Snow <[email protected]>
---
 rust/hw/core/src/qdev.rs | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/rust/hw/core/src/qdev.rs b/rust/hw/core/src/qdev.rs
index 145e20a984f..b2e5441079d 100644
--- a/rust/hw/core/src/qdev.rs
+++ b/rust/hw/core/src/qdev.rs
@@ -425,18 +425,16 @@ pub const fn period_from_ns(ns: u64) -> u64 {
     }
 
     pub const fn period_from_hz(hz: u64) -> u64 {
-        if hz == 0 {
-            0
-        } else {
-            Self::PERIOD_1SEC / hz
+        match Self::PERIOD_1SEC.checked_div(hz) {
+            Some(value) => value,
+            None => 0,
         }
     }
 
     pub const fn period_to_hz(period: u64) -> u64 {
-        if period == 0 {
-            0
-        } else {
-            Self::PERIOD_1SEC / period
+        match Self::PERIOD_1SEC.checked_div(period) {
+            Some(value) => value,
+            None => 0,
         }
     }
 
-- 
2.53.0


Reply via email to