public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: th1520: fix `CLIPPY=1` warning
@ 2026-01-21 18:37 Miguel Ojeda
  2026-01-25 16:24 ` Danilo Krummrich
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-01-21 18:37 UTC (permalink / raw)
  To: Drew Fustini, Guo Ren, Fu Wei, Miguel Ojeda
  Cc: linux-riscv, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, Mark Brown

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>
---
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(-)

diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs
index 21b4bdaf0607..fb95f994f963 100644
--- a/drivers/pwm/pwm_th1520.rs
+++ b/drivers/pwm/pwm_th1520.rs
@@ -61,10 +61,7 @@ const fn th1520_pwm_fp(n: u32) -> usize {
 fn ns_to_cycles(ns: u64, rate_hz: u64) -> u64 {
     const NSEC_PER_SEC_U64: u64 = time::NSEC_PER_SEC as u64;

-    (match ns.checked_mul(rate_hz) {
-        Some(product) => product,
-        None => u64::MAX,
-    }) / NSEC_PER_SEC_U64
+    ns.saturating_mul(rate_hz) / NSEC_PER_SEC_U64
 }

 fn cycles_to_ns(cycles: u64, rate_hz: u64) -> u64 {

base-commit: e3b32dcb9f23e3c3927ef3eec6a5842a988fb574
--
2.52.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Danilo Krummrich @ 2026-01-25 16:24 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Drew Fustini, Guo Ren, Fu Wei, linux-riscv, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, rust-for-linux, Mark Brown

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>
> ---
> It would be nice to clean this up, so that Mark may start enforcing it
> in linux-next -- thanks!

Indeed, the patch itself LGTM.

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  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-03-18  8:41 ` Benno Lossin
  3 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-02-08 11:13 UTC (permalink / raw)
  To: Miguel Ojeda, Michal Wilczynski, Uwe Kleine-König
  Cc: Drew Fustini, Guo Ren, Fu Wei, linux-riscv, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, rust-for-linux, Mark Brown,
	linux-pwm

On Wed, Jan 21, 2026 at 7:37 PM Miguel Ojeda <ojeda@kernel.org> 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>

Pinging about this...

Adding Michal and Uwe to Cc in case it helps (the driver is under
"RISC-V THEAD SoC SUPPORT" so they don't get paged).

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  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
                     ` (3 more replies)
  2026-03-18  8:41 ` Benno Lossin
  3 siblings, 4 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2026-02-09  8:56 UTC (permalink / raw)
  To: Miguel Ojeda, Michal Wilczynski
  Cc: Drew Fustini, Guo Ren, Fu Wei, linux-riscv, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, rust-for-linux, Mark Brown,
	linux-pwm

[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]

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://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>
> ---

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?

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  2026-02-09  8:56 ` Uwe Kleine-König
@ 2026-02-09  8:58   ` Alice Ryhl
  2026-02-09  9:24   ` Michal Wilczynski
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Alice Ryhl @ 2026-02-09  8:58 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Miguel Ojeda, Michal Wilczynski, Drew Fustini, Guo Ren, Fu Wei,
	linux-riscv, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	rust-for-linux, Mark Brown, linux-pwm

On Mon, Feb 9, 2026 at 9:56 AM Uwe Kleine-König
<u.kleine-koenig@baylibre.com> 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://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>
> > ---
>
> 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?

I think we do care about that.

Alice

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  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
  3 siblings, 0 replies; 9+ messages in thread
From: Michal Wilczynski @ 2026-02-09  9:24 UTC (permalink / raw)
  To: Uwe Kleine-König, Miguel Ojeda
  Cc: Drew Fustini, Guo Ren, Fu Wei, linux-riscv, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, rust-for-linux, Mark Brown,
	linux-pwm



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@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@samsung.com>

> 
> Best regards
> Uwe

Best regards,
-- 
Michal Wilczynski <m.wilczynski@samsung.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  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
  3 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-02-09 13:02 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Miguel Ojeda, Michal Wilczynski, Drew Fustini, Guo Ren, Fu Wei,
	linux-riscv, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, Mark Brown, linux-pwm

On Mon, Feb 9, 2026 at 9:56 AM Uwe Kleine-König
<u.kleine-koenig@baylibre.com> wrote:
>
> 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?

Yeah, so far we do. At least, back then we decided we would try our
best to keep them clean, and I build the stable and LTS kernels with
Clippy enabled (and I think some downstream users may do development
based on those, so I hope that effort helps).

Worst case, we can always drop that requirement.

In any case, some of these patches, even if not considered Fixes (e.g.
a new lint), sometimes they may need to go "urgently" into `-fixes`
branches rather than `-next` ones, i.e. even without such a tag; and
we can also still send them to stable -- what I usually give the
stable team is a line like:

    Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is
pinned in older LTSs).

I hope that helps!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  2026-01-21 18:37 [PATCH] pwm: th1520: fix `CLIPPY=1` warning Miguel Ojeda
                   ` (2 preceding siblings ...)
  2026-02-09  8:56 ` Uwe Kleine-König
@ 2026-03-18  8:41 ` Benno Lossin
  3 siblings, 0 replies; 9+ messages in thread
From: Benno Lossin @ 2026-03-18  8:41 UTC (permalink / raw)
  To: Miguel Ojeda, Drew Fustini, Guo Ren, Fu Wei
  Cc: linux-riscv, Boqun Feng, Gary Guo, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	rust-for-linux, Mark Brown

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(-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] pwm: th1520: fix `CLIPPY=1` warning
  2026-02-09  8:56 ` Uwe Kleine-König
                     ` (2 preceding siblings ...)
  2026-02-09 13:02   ` Miguel Ojeda
@ 2026-03-28 13:53   ` Miguel Ojeda
  3 siblings, 0 replies; 9+ messages in thread
From: Miguel Ojeda @ 2026-03-28 13:53 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Miguel Ojeda, Michal Wilczynski, Drew Fustini, Guo Ren, Fu Wei,
	linux-riscv, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, Mark Brown, linux-pwm

On Mon, Feb 9, 2026 at 9:56 AM Uwe Kleine-König
<u.kleine-koenig@baylibre.com> wrote:
>
> 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?

Do you plan on picking this one up? Michal already reviewed it.

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-28 13:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-18  8:41 ` Benno Lossin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox