[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZTwWse0COE3w6_US@boqun-archlinux>
Date: Fri, 27 Oct 2023 12:59:45 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: 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
Subject: Re: [PATCH net-next v7 1/5] rust: core abstractions for network PHY
drivers
On Thu, Oct 26, 2023 at 09:10:46AM +0900, FUJITA Tomonori wrote:
[...]
> + /// Gets the current link state.
> + ///
> + /// It returns true if the link is up.
> + pub fn is_link_up(&self) -> bool {
> + const LINK_IS_UP: u32 = 1;
> + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> + let phydev = unsafe { *self.0.get() };
Tomo, FWIW, the above line means *copying* the content pointed by
`self.0.get()` into `phydev`, i.e. `phydev` is the semantically a copy
of the `phy_device` instead of an alias. In C code, it means you did:
struct phy_device phydev = *ptr;
Sure, both compilers can figure this out, therefore no extra copy is
done, but still it's better to avoid this copy semantics by doing:
let phydev = unsafe { &*self.0.get() };
it's equal to C code:
struct phy_device *phydev = ptr;
Ditto for is_autoneg_enabled() and is_autoneg_completed().
Regards,
Boqun
> + phydev.link() == LINK_IS_UP
> + }
> +
> + /// Gets the current auto-negotiation configuration.
> + ///
> + /// It returns true if auto-negotiation is enabled.
> + pub fn is_autoneg_enabled(&self) -> bool {
> + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> + let phydev = unsafe { *self.0.get() };
> + phydev.autoneg() == bindings::AUTONEG_ENABLE
> + }
> +
> + /// Gets the current auto-negotiation state.
> + ///
> + /// It returns true if auto-negotiation is completed.
> + pub fn is_autoneg_completed(&self) -> bool {
> + const AUTONEG_COMPLETED: u32 = 1;
> + // SAFETY: `phydev` is pointing to a valid object by the type invariant of `Self`.
> + let phydev = unsafe { *self.0.get() };
> + phydev.autoneg_complete() == AUTONEG_COMPLETED
> + }
[...]
Powered by blists - more mailing lists