[PATCH] pwm: th1520: fix `CLIPPY=1` warning
Michal Wilczynski
m.wilczynski at samsung.com
Mon Feb 9 01:24:37 PST 2026
On 2/9/26 09:56, Uwe Kleine-König wrote:
> Hello Miguel,
>
> On Wed, Jan 21, 2026 at 07:37:19PM +0100, 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://protect2.fireeye.com/v1/url?k=4a8755d5-151b7cff-4a86de9a-000babe598f7-51498316c06f2766&q=1&e=b527c3ac-a0b8-4074-9bc4-c3497f7913a5&u=https%3A%2F%2Frust-lang.github.io%2Frust-clippy%2Frust-1.92.0%2Findex.html%23manual_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://protect2.fireeye.com/v1/url?k=7fd7ef65-204bc64f-7fd6642a-000babe598f7-c6165289323e3bed&q=1&e=b527c3ac-a0b8-4074-9bc4-c3497f7913a5&u=https%3A%2F%2Frust-lang.github.io%2Frust-clippy%2Frust-1.92.0%2Findex.html%23manual_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://protect2.fireeye.com/v1/url?k=3f9f72c4-60035bee-3f9ef98b-000babe598f7-ce3556202281f48e&q=1&e=b527c3ac-a0b8-4074-9bc4-c3497f7913a5&u=https%3A%2F%2Frust-for-linux.com%2Fcontributing%23submit-checklist-addendum [1]
>> Fixes: e03724aac758 ("pwm: Add Rust driver for T-HEAD TH1520 SoC")
>> Signed-off-by: Miguel Ojeda <ojeda at kernel.org>
>> ---
>
> Looks good to me. I'll wait for Michal to add his blessing and then when
> picking it up tend to drop the Fixes line. Or do we also care about
> CLIPPY-cleanness in stable?
Hmm I'm pretty sure at the time of the writing building with CLIPPY
didn't trigger this warning, so I guess it's either a newer version of
CLIPPY that I used or in the meantime CLIPPY was updated.
Anyway
Reviewed-by: Michal Wilczynski <m.wilczynski at samsung.com>
>
> Best regards
> Uwe
Best regards,
--
Michal Wilczynski <m.wilczynski at samsung.com>
More information about the linux-riscv
mailing list