[PATCH] pwm: th1520: fix `CLIPPY=1` warning
Benno Lossin
lossin at kernel.org
Wed Mar 18 01:41:33 PDT 2026
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 at 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 at kernel.org>
>
> drivers/pwm/pwm_th1520.rs | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
More information about the linux-riscv
mailing list