Linux Modules
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: gary@garyguo.net, linux-modules@vger.kernel.org,
	"Petr Pavlu" <petr.pavlu@suse.com>,
	ojeda@kernel.org
Subject: Re: [PATCH RFC 02/11] rust: sync: atomic: Add Atomic<u{8,16}>
Date: Sun, 11 Oct 2026 13:00:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-167236@kernel.org> (raw)
In-Reply-To: <20261011-rust-dyndbg-v1-2-832e4039b71f@weissschuh.net>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] rust: test coverage regression: u32 dropped from atomic_arithmetic_tests
- [Low] rust: dead code: unusable AtomicAdd implementations for u8 and u16
--

commit bff46a0936305602d6b5e98e2a29f7e77f8ccefc
Author: Thomas Weißschuh <linux@weissschuh.net>

rust: sync: atomic: Add Atomic<u{8,16}>
    
Add generic atomic support for small unsigned integers that have an
AtomicImpl with the same size and alignment. Also extend the unit tests.

> diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
> index 3d63f40791fa2..4c1fb5e08dc26 100644
> --- a/rust/kernel/sync/atomic/predefine.rs
> +++ b/rust/kernel/sync/atomic/predefine.rs
> @@ -113,6 +113,32 @@ fn rhs_into_delta(rhs: isize) -> isize_atomic_repr {
>      }
>  }
>  
> +// SAFETY: `u8` and `i8` has the same size and alignment, and `u8` is round-trip transmutable to
> +// `i8`.
> +unsafe impl super::AtomicType for u8 {
> +    type Repr = i8;
> +}
> +
> +// SAFETY: The wrapping add result of two `i8`s is a valid `u8`.
> +unsafe impl super::AtomicAdd<u8> for u8 {
> +    fn rhs_into_delta(rhs: u8) -> i8 {
> +        rhs as i8
> +    }
> +}

[Severity: Low]
Does this implementation for u8 result in unusable dead code?

Since the Repr type for u8 is i8, and i8 lacks an AtomicArithmeticOps
implementation, it seems impossible to call arithmetic methods like fetch_add
or add on Atomic<u8>.

> +// SAFETY: `u16` and `i16` has the same size and alignment, and `u16` is round-trip transmutable to
> +// `i16`.
> +unsafe impl super::AtomicType for u16 {
> +    type Repr = i16;
> +}
> +
> +// SAFETY: The wrapping add result of two `i16`s is a valid `u16`.
> +unsafe impl super::AtomicAdd<u16> for u16 {
> +    fn rhs_into_delta(rhs: u16) -> i16 {
> +        rhs as i16
> +    }
> +}

[Severity: Low]
Does this implementation for u16 also result in unusable dead code?

Similar to u8, the Repr type i16 lacks an AtomicArithmeticOps implementation,
preventing the use of atomic arithmetic methods on Atomic<u16>.

[ ... ]

> @@ -263,7 +289,7 @@ fn atomic_cmpxchg_tests() {
>  
>      #[test]
>      fn atomic_arithmetic_tests() {
> -        for_each_type!(42 in [i32, i64, u32, u64, isize, usize] |v| {
> +        for_each_type!(42 in [i32, i64, u64, isize, usize] |v| {

[Severity: Low]
Is u32 intentionally dropped from the list of types tested here?

This appears to cause a regression in test coverage for 32-bit unsigned atomic
arithmetic operations.

>              let x = Atomic::new(v);
>  
>              assert_eq!(v, x.fetch_add(12, Full));

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011-rust-dyndbg-v1-0-832e4039b71f@weissschuh.net?part=2

  reply	other threads:[~2026-10-11 13:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 12:52 [PATCH RFC 00/11] rust: add support for dynamic debug Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 01/11] rust: print: use CStr for __LOG_PREFIX Thomas Weißschuh
2026-10-11 13:01   ` Gary Guo
2026-10-11 14:43     ` Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 02/11] rust: sync: atomic: Add Atomic<u{8,16}> Thomas Weißschuh
2026-10-11 13:00   ` sashiko-bot [this message]
2026-10-11 13:04   ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 03/11] rust: num: Add Bounded::USABLE_BITS Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 04/11] samples: rust_print: add debug messages Thomas Weißschuh
2026-10-11 13:53   ` Miguel Ojeda
2026-10-11 14:48     ` Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 05/11] dyndbg: use u32 for struct _ddebug bitfields Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 06/11] dyndbg: make _ddebug::flags its own field Thomas Weißschuh
2026-10-11 13:23   ` Gary Guo
2026-10-11 14:47     ` Thomas Weißschuh
2026-10-11 15:44       ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 07/11] dyndbg: use READ_ONCE()/WRITE_ONCE() to access descriptor flags Thomas Weißschuh
2026-10-11 13:16   ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 08/11] rust: add support for dynamic debug Thomas Weißschuh
2026-10-11 13:08   ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 09/11] rust: print: enable dynamic debug for pr_debug!() Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 10/11] rust: device: remove logging methods Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 11/11] rust: device: enable dynamic debug for dev_dbg!() Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot

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=sashiko-outbox-167236@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=ojeda@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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