Re: [PATCH v4 5/7] rust: io: add `register!` macro

From: Danilo Krummrich

Date: Thu Jan 29 2026 - 07:48:41 EST


On Wed Jan 28, 2026 at 5:16 PM CET, Gary Guo wrote:
> On Wed Jan 28, 2026 at 2:37 AM GMT, Alexandre Courbot wrote:
>> + /// Read the register from its address in `io` and run `f` on its value to obtain a new
>> + /// value to write back.
>> + ///
>> + /// Note that this operation is not atomic. In concurrent contexts, external
>> + /// synchronization may be required to prevent race conditions.
>
> Given the non-atomicity, how much value does it provide compared to having the
> user write read and write themselves? I feel that people reading the code may
> assume the atomicity without reading docs if they see `FOO::update`, while it's
> less likely that they do so if they read
> `FOO::read(io).with_bar(baz).write(io)`.

I think update() is fine, there are no promises about atomicity for any of the
I/O functions, also not for read() and write(). I.e. whether an operation is
atomic or not depends on the architecture, bus and device.

We should probably document this clearly to not raise wrong expectations.

>> + #[inline(always)]
>> + pub fn update<T, I, F>(
>> + io: &T,
>> + f: F,
>> + ) where
>> + T: ::core::ops::Deref<Target = I>,
>> + I: ::kernel::io::IoKnownSize + ::kernel::io::IoCapable<$storage>,
>> + F: ::core::ops::FnOnce(Self) -> Self,
>> + {
>> + let reg = f(Self::read(io));
>> + reg.write(io);
>> + }
>> + }
>> + };