netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
	andrew@lunn.ch, tmgross@umich.edu,
	miguel.ojeda.sandonis@gmail.com, benno.lossin@proton.me,
	wedsonaf@gmail.com, aliceryhl@google.com
Subject: Re: [PATCH net-next v9 1/4] rust: core abstractions for network PHY drivers
Date: Mon, 4 Dec 2023 19:40:53 -0800	[thread overview]
Message-ID: <ZW6bxfB-iuD9cjm_@Boquns-Mac-mini.home> (raw)
In-Reply-To: <20231205.122320.1887043941025150953.fujita.tomonori@gmail.com>

On Tue, Dec 05, 2023 at 12:23:20PM +0900, FUJITA Tomonori wrote:
> On Mon, 4 Dec 2023 18:00:15 -0800
> Boqun Feng <boqun.feng@gmail.com> wrote:
> 
> > On Tue, Dec 05, 2023 at 10:14:17AM +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: u64 = 1;
> >> +        // TODO: the code to access to the bit field will be replaced with automatically
> >> +        // generated code by bindgen when it becomes possible.
> >> +        // SAFETY: The struct invariant ensures that we may access
> >> +        // this field without additional synchronization.
> >> +        let bit_field = unsafe { &(*self.0.get())._bitfield_1 };
> >> +        bit_field.get(14, 1) == LINK_IS_UP
> > 
> > I made a mistake here [1], this should be:
> > 
> >     let bit_field = unsafe { &*(core::ptr::addr_of!((*self.0.get())._bitfield_1)) };
> >     bit_field.get(14, 1) == LINK_IS_UP
> > 
> > without `core::ptr::add_of!`, `*(self.0.get())` would still create a
> > temporary `&` to the underlying object I believe. `addr_of!` is the way
> > to avoid create the temporary reference. Same for the other functions.
> 
> If so, how about functions to access to non bit field like phy_id()?
> 
> pub fn phy_id(&self) -> u32 {
>     let phydev = self.0.get();
>     unsafe { (*phydev).phy_id }
> }

Good point, so cancel the above comment. I had a misunderstanding that a
place expression would create temporary references, but I was wrong.

Regards,
Boqun

  reply	other threads:[~2023-12-05  3:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  1:14 [PATCH net-next v9 0/4] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-12-05  1:14 ` [PATCH net-next v9 1/4] rust: core " FUJITA Tomonori
2023-12-05  1:43   ` Jarkko Sakkinen
2023-12-05  2:06     ` FUJITA Tomonori
2023-12-05  2:00   ` Boqun Feng
2023-12-05  3:23     ` FUJITA Tomonori
2023-12-05  3:40       ` Boqun Feng [this message]
2023-12-07 17:25   ` Benno Lossin
2023-12-08  1:28     ` FUJITA Tomonori
2023-12-05  1:14 ` [PATCH net-next v9 2/4] rust: net::phy add module_phy_driver macro FUJITA Tomonori
2023-12-05  1:48   ` Jarkko Sakkinen
2023-12-05  3:44     ` FUJITA Tomonori
2023-12-08 14:42       ` Miguel Ojeda
2023-12-08 18:11   ` Benno Lossin
2023-12-05  1:14 ` [PATCH net-next v9 3/4] MAINTAINERS: add Rust PHY abstractions for ETHERNET PHY LIBRARY FUJITA Tomonori
2023-12-05  1:49   ` Jarkko Sakkinen
2023-12-05  1:53     ` Trevor Gross
2023-12-05  1:57       ` Jarkko Sakkinen
2023-12-05  1:53   ` Trevor Gross
2023-12-05  3:45     ` FUJITA Tomonori
2023-12-05  1:14 ` [PATCH net-next v9 4/4] net: phy: add Rust Asix PHY driver FUJITA Tomonori
2023-12-05  1:54   ` Jarkko Sakkinen
2023-12-05  2:24     ` Andrew Lunn
2023-12-05  1:35 ` [PATCH net-next v9 0/4] Rust abstractions for network PHY drivers Jarkko Sakkinen
2023-12-05  1:42   ` FUJITA Tomonori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZW6bxfB-iuD9cjm_@Boquns-Mac-mini.home \
    --to=boqun.feng@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=andrew@lunn.ch \
    --cc=benno.lossin@proton.me \
    --cc=fujita.tomonori@gmail.com \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).