From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org,
Manos Pitsidianakis <manos.pitsidianakis@linaro.org>,
John Snow <jsnow@redhat.com>
Subject: [PATCH 1/1] rust: use checked_div to make clippy happy
Date: Wed, 18 Feb 2026 14:24:44 -0500 [thread overview]
Message-ID: <20260218192444.658046-2-jsnow@redhat.com> (raw)
In-Reply-To: <20260218192444.658046-1-jsnow@redhat.com>
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 <jsnow@redhat.com>
---
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..c4a7312168f 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 period.checked_div(Self::PERIOD_1SEC) {
+ Some(value) => value,
+ None => 0,
}
}
--
2.53.0
next prev parent reply other threads:[~2026-02-18 19:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-18 19:24 [PATCH 0/1] rust: use checked_div() John Snow
2026-02-18 19:24 ` John Snow [this message]
2026-02-18 22:18 ` [PATCH 1/1] rust: use checked_div to make clippy happy Manos Pitsidianakis
2026-02-19 3:38 ` Richard Henderson
2026-02-19 17:05 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260218192444.658046-2-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox