Re: [PATCH v7 05/10] rust: io: add IoLoc and IoWrite types
From: "Danilo Krummrich" <dakr@kernel.org>
Date: 2026-03-04 16:18:12
Also in:
rust-for-linux
On Tue Mar 3, 2026 at 3:55 PM CET, Alexandre Courbot wrote:
So, to get a better idea of these two options I have converted this patchset to use the 2-arguments `write_with` method. Here is the difference between the two - it is particularly interesting to see how nova-core changes: https://github.com/Gnurou/linux/compare/register_1arg..Gnurou:linux:register_2args
This looks good to me, but the fact that this turns out nicely has nothing to do with write() now taking two arguments. I.e. there is no reason why we couldn't have the exact same write_with() method together with the single argument write() method. The contention point for me with a two arguments write() method still remains that the arguments are redundant. I.e. you first have the location in form of an object instance of a ZST (which in the end is just a "trick" to pass in the type itself) and then we have the object that actually represents the entire register, describing both the location *and* the value. So, let's say a driver creates a register object with a custom constructor let reset = regs::MyReg::reset(); then the two argument approach would be (1) bar.write(regs::MyReg, regs::MyReg::reset()); whereas the single argument approach would just be (2) bar.write(regs::MyReg::reset()); So, if I would have to write (1), I'd probably be tempted to implement a reset() function that takes the bar as argument to hide this, i.e. regs::MyReg::reset(bar); I also can't agree with the argument that the notation of write(loc, val) - or write(val, loc) as the C side does it - is common and we should stick to it. This notation is only common because it is necessary when operating on primitives or when the two representing types are discrete. But this isn't the case here, a register object is already distinct in terms of its location and value. So, unless there is a strong argument why this improves anything on the user side of the API, I still feel like we should keep write() as is with a single argument; having an additional write_with() method seems fine though.