[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231212.081505.1423250811446494582.fujita.tomonori@gmail.com>
Date: Tue, 12 Dec 2023 08:15:05 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: alice@...l.io
Cc: fujita.tomonori@...il.com, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, andrew@...n.ch, tmgross@...ch.edu,
miguel.ojeda.sandonis@...il.com, benno.lossin@...ton.me,
wedsonaf@...il.com, aliceryhl@...gle.com, boqun.feng@...il.com
Subject: Re: [PATCH net-next v10 1/4] rust: core abstractions for network
PHY drivers
On Mon, 11 Dec 2023 22:46:01 +0100
Alice Ryhl <alice@...l.io> wrote:
> On 12/11/23 00:49, FUJITA Tomonori wrote:
>> This patch adds abstractions to implement network PHY drivers; the
>> driver registration and bindings for some of callback functions in
>> struct phy_driver and many genphy_ functions.
>> This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y.
>> This patch enables unstable const_maybe_uninit_zeroed feature for
>> kernel crate to enable unsafe code to handle a constant value with
>> uninitialized data. With the feature, the abstractions can initialize
>> a phy_driver structure with zero easily; instead of initializing all
>> the members by hand. It's supposed to be stable in the not so distant
>> future.
>> Link: https://github.com/rust-lang/rust/pull/116218
>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
>
> Overall looks fine to me. Just a few comments below that confuse me:
Thanks.
>> + /// Gets the state of PHY state machine states.
>> + pub fn state(&self) -> DeviceState {
>> + let phydev = self.0.get();
>> + // SAFETY: The struct invariant ensures that we may access
>> + // this field without additional synchronization.
>> + let state = unsafe { (*phydev).state };
>> + // TODO: this conversion code will be replaced with automatically
>> generated code by bindgen
>> + // when it becomes possible.
>> + // better to call WARN_ONCE() when the state is out-of-range.
>
> Did you mix up two comments here? This doesn't parse in my brain.
I'll remove the second comment because all we have to do here is using
bindgen.
>> + /// Reads a given C22 PHY register.
>> + // This function reads a hardware register and updates the stats so
>> takes `&mut self`.
>> + pub fn read(&mut self, regnum: u16) -> Result<u16> {
>> + let phydev = self.0.get();
>> + // SAFETY: `phydev` is pointing to a valid object by the type
>> invariant of `Self`.
>> + // So an FFI call with a valid pointer.
>
> This sentence also doesn't parse in my brain. Perhaps "So it's just an
> FFI call" or similar?
"So it's just an FFI call" looks good. I'll fix all the places that
use the same comment.
Powered by blists - more mailing lists