[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ccf2b9af-1c8c-44c4-bb93-51dd9ea1cccf@ryhl.io>
Date: Mon, 11 Dec 2023 22:46:01 +0100
From: Alice Ryhl <alice@...l.io>
To: FUJITA Tomonori <fujita.tomonori@...il.com>, netdev@...r.kernel.org
Cc: 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 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:
> + /// 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.
> + /// 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?
Alice
Powered by blists - more mailing lists