public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Drew Fustini" <fustini@kernel.org>,
	"Guo Ren" <guoren@kernel.org>, "Fu Wei" <wefu@redhat.com>
Cc: linux-riscv@lists.infradead.org,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	rust-for-linux@vger.kernel.org, "Mark Brown" <broonie@kernel.org>
Subject: Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
Date: Wed, 18 Mar 2026 09:41:33 +0100	[thread overview]
Message-ID: <DH5RVNK0TCQG.3E2K1WC03CBXM@kernel.org> (raw)
In-Reply-To: <20260121183719.71659-1-ojeda@kernel.org>

On Wed Jan 21, 2026 at 7:37 PM CET, Miguel Ojeda wrote:
> The Rust kernel code should be kept `CLIPPY=1`-clean [1].
>
> Clippy reports:
>
>     error: this pattern reimplements `Option::unwrap_or`
>       --> drivers/pwm/pwm_th1520.rs:64:5
>        |
>     64 | /     (match ns.checked_mul(rate_hz) {
>     65 | |         Some(product) => product,
>     66 | |         None => u64::MAX,
>     67 | |     }) / NSEC_PER_SEC_U64
>        | |______^ help: replace with: `ns.checked_mul(rate_hz).unwrap_or(u64::MAX)`
>        |
>        = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#manual_unwrap_or
>        = note: `-D clippy::manual-unwrap-or` implied by `-D warnings`
>        = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]`
>
> Applying the suggestion then triggers:
>
>     error: manual saturating arithmetic
>       --> drivers/pwm/pwm_th1520.rs:64:5
>        |
>     64 |     ns.checked_mul(rate_hz).unwrap_or(u64::MAX) / NSEC_PER_SEC_U64
>        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_mul`: `ns.saturating_mul(rate_hz)`
>        |
>        = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#manual_saturating_arithmetic
>        = note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings`
>        = help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]`
>
> Thus fix it by using saturating arithmatic, which simplifies the code
> as well.
>
> Link: https://rust-for-linux.com/contributing#submit-checklist-addendum [1]
> Fixes: e03724aac758 ("pwm: Add Rust driver for T-HEAD TH1520 SoC")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Just encountered this during my testing, could we get this picked up please?

Cheers,
Benno

> ---
> It would be nice to clean this up, so that Mark may start enforcing it
> in linux-next -- thanks!
>
> Completely untested, so please beware. Also, I am not sure if I am
> missing something here, since saturation arithmetic is already used
> a few lines below already.
>
> Cc: Mark Brown <broonie@kernel.org>
>
>  drivers/pwm/pwm_th1520.rs | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

      parent reply	other threads:[~2026-03-18  8:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-21 18:37 [PATCH] pwm: th1520: fix `CLIPPY=1` warning Miguel Ojeda
2026-01-25 16:24 ` Danilo Krummrich
2026-02-08 11:13 ` Miguel Ojeda
2026-02-09  8:56 ` Uwe Kleine-König
2026-02-09  8:58   ` Alice Ryhl
2026-02-09  9:24   ` Michal Wilczynski
2026-02-09 13:02   ` Miguel Ojeda
2026-03-28 13:53   ` Miguel Ojeda
2026-03-29  7:36     ` Uwe Kleine-König
2026-03-29 12:01       ` Miguel Ojeda
2026-03-18  8:41 ` Benno Lossin [this message]

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=DH5RVNK0TCQG.3E2K1WC03CBXM@kernel.org \
    --to=lossin@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --cc=fustini@kernel.org \
    --cc=gary@garyguo.net \
    --cc=guoren@kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=wefu@redhat.com \
    /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