From: Benno Lossin <benno.lossin@proton.me>
To: Andrew Lunn <andrew@lunn.ch>
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>,
netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
miguel.ojeda.sandonis@gmail.com, tmgross@umich.edu,
boqun.feng@gmail.com, wedsonaf@gmail.com, greg@kroah.com
Subject: Re: [PATCH net-next v5 1/5] rust: core abstractions for network PHY drivers
Date: Sat, 21 Oct 2023 07:36:31 +0000 [thread overview]
Message-ID: <120631ca-3da3-441c-9536-43ee9dbe3b01@proton.me> (raw)
In-Reply-To: <4935f458-4719-4472-b937-0da8b16ebbaa@lunn.ch>
On 20.10.23 20:42, Andrew Lunn wrote:
>>> +//! All the PHYLIB helper functions for `phy_device` modify some members in `phy_device`. Except for
>>> +//! getter functions, [`Device`] methods take `&mut self`. This also applied to `read()`, which reads
>>> +//! a hardware register and updates the stats.
>>
>> I would use [`Device`] instead of `phy_device`, since the Rust reader
>> might not be aware what wraps `phy_device`.
>
> We don't want to hide phy_device too much, since at the moment, the
> abstraction is very minimal. Anybody writing a driver is going to need
> a good understanding of the C code in order to find the helpers they
> need, and then add them to the abstraction. So i would say we need to
> explain the relationship between the C structure and the Rust
> structure, to aid developers.
There is a comment on `Device` that explains that it wraps `phy_device`.
Since [`Device`] is a link, readers who do not know what it means can
immediately click the link and find out. This is not possible with
`phy_device`, since you have to search the web for it, so I would
prefer to use the link.
>>> + /// Returns true if the link is up.
>>> + pub fn get_link(&self) -> bool {
>>
>> I still think this name should be changed. My response at [1] has not yet
>> been replied to. This has already been discussed before:
>> - https://lore.kernel.org/rust-for-linux/2023100237-satirical-prance-bd57@gregkh/
>> - https://lore.kernel.org/rust-for-linux/20231004.084644.50784533959398755.fujita.tomonori@gmail.com/
>> - https://lore.kernel.org/rust-for-linux/CALNs47syMxiZBUwKLk3vKxzmCbX0FS5A37FjwUzZO9Fn-iPaoA@mail.gmail.com/
>>
>> And I want to suggest to change it to `is_link_up`.
>>
>> Reasons why I do not like the name:
>> - `get_`/`put_` are used for ref counting on the C side, I would like to
>> avoid confusion.
>> - `get` in Rust is often used to fetch a value from e.g. a datastructure
>> such as a hashmap, so I expect the call to do some computation.
>> - getters in Rust usually are not prefixed with `get_`, but rather are
>> just the name of the field.
>> - in this case I like the name `is_link_up` much better, since code becomes
>> a lot more readable with that.
>> - I do not want this pattern as an example for other drivers.
>>
>> [1]: https://lore.kernel.org/rust-for-linux/f5878806-5ba2-d932-858d-dda3f55ceb67@proton.me/
>>
>>> + 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() };
>>> + phydev.link() == LINK_IS_UP
>>> + }
>
> During the reviews we have had a lot of misunderstanding what this
> actually does, given its name. Some thought it poked around in
> registers to get the current state of the link. Some thought it
> triggered the PHY to establish a link. When in fact its just a dumb
> getter. And we have a few other dumb getters and setters.
IMO `is_link_up` would indicate that it is a dumb getter.
> So i would prefer something which indicates its a dumb getter. If the
> norm of Rust is just the field name, lets just use the field name. But
> we should do that for all the getters and setters. Is there a naming
> convention for things which take real actions?
For bool getters it would be the norm to use `is_` as the prefix, see
[1]. In this case I would say it is also natural to not use `is_link`,
but rather `is_link_up`, since the former sounds weird.
[1]: https://doc.rust-lang.org/std/?search=is_
> And maybe we need to add a comment: Get the current link state, as
> stored in the [`Device`]. Set the duplex value in [`Device`], etc.
Sure, we can document dumb getters explicitly, I would prefer to do:
Getter for the current link state. Setter for the duplex value.
I don't think that we need to link to `Device`, since the functions
are defined on that type.
--
Cheers,
Benno
next prev parent reply other threads:[~2023-10-21 7:36 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 11:30 [PATCH net-next v5 0/5] Rust abstractions for network PHY drivers FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 1/5] rust: core " FUJITA Tomonori
2023-10-18 15:07 ` Benno Lossin
2023-10-19 0:24 ` FUJITA Tomonori
2023-10-19 13:45 ` Benno Lossin
2023-10-19 14:42 ` FUJITA Tomonori
2023-10-19 15:20 ` Benno Lossin
2023-10-19 15:32 ` FUJITA Tomonori
2023-10-19 16:37 ` Benno Lossin
2023-10-19 21:51 ` FUJITA Tomonori
2023-10-21 7:21 ` Benno Lossin
2023-10-20 0:34 ` FUJITA Tomonori
2023-10-20 12:54 ` FUJITA Tomonori
2023-10-21 7:25 ` Benno Lossin
2023-10-21 7:30 ` FUJITA Tomonori
2023-10-21 8:37 ` Benno Lossin
2023-10-21 10:27 ` FUJITA Tomonori
2023-10-21 11:21 ` Benno Lossin
2023-10-21 11:36 ` FUJITA Tomonori
2023-10-21 12:13 ` Benno Lossin
2023-10-21 12:38 ` FUJITA Tomonori
2023-10-21 12:50 ` Benno Lossin
2023-10-21 13:00 ` FUJITA Tomonori
2023-10-21 13:05 ` Benno Lossin
2023-10-21 13:31 ` FUJITA Tomonori
2023-10-21 13:35 ` Benno Lossin
2023-10-21 21:45 ` FUJITA Tomonori
2023-10-23 6:35 ` Benno Lossin
2023-10-23 6:37 ` Benno Lossin
2023-10-21 15:57 ` Andrew Lunn
2023-10-21 16:31 ` Benno Lossin
2023-10-21 15:41 ` Andrew Lunn
2023-10-20 18:42 ` Andrew Lunn
2023-10-21 4:44 ` FUJITA Tomonori
2023-10-21 7:36 ` Benno Lossin [this message]
2023-10-21 12:47 ` Miguel Ojeda
2023-10-22 9:47 ` FUJITA Tomonori
2023-10-22 11:37 ` Miguel Ojeda
2023-10-22 15:34 ` Andrew Lunn
2023-10-24 1:37 ` FUJITA Tomonori
2023-10-24 8:48 ` Miguel Ojeda
2023-10-18 20:27 ` Andrew Lunn
2023-10-19 0:41 ` FUJITA Tomonori
2023-10-19 13:57 ` Benno Lossin
2023-10-20 19:50 ` Andrew Lunn
2023-10-21 8:01 ` Benno Lossin
2023-10-21 15:35 ` Andrew Lunn
2023-10-20 17:26 ` Andreas Hindborg (Samsung)
2023-10-20 17:56 ` Benno Lossin
2023-10-20 19:59 ` Andrew Lunn
2023-10-20 20:30 ` Andreas Hindborg (Samsung)
2023-10-21 3:49 ` FUJITA Tomonori
2023-10-21 4:01 ` FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 2/5] rust: net::phy add module_phy_driver macro FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 3/5] WIP rust: add second `bindgen` pass for enum exhaustiveness checking FUJITA Tomonori
2023-10-20 11:37 ` Andreas Hindborg (Samsung)
2023-10-20 12:34 ` Miguel Ojeda
2023-10-20 12:35 ` Miguel Ojeda
2023-10-23 8:57 ` Andreas Hindborg (Samsung)
2023-10-21 3:51 ` FUJITA Tomonori
2023-10-21 12:05 ` Miguel Ojeda
2023-10-22 6:30 ` FUJITA Tomonori
2023-10-23 8:58 ` Andreas Hindborg (Samsung)
2023-10-17 11:30 ` [PATCH net-next v5 4/5] MAINTAINERS: add Rust PHY abstractions for ETHERNET PHY LIBRARY FUJITA Tomonori
2023-10-17 11:30 ` [PATCH net-next v5 5/5] net: phy: add Rust Asix PHY driver 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=120631ca-3da3-441c-9536-43ee9dbe3b01@proton.me \
--to=benno.lossin@proton.me \
--cc=andrew@lunn.ch \
--cc=boqun.feng@gmail.com \
--cc=fujita.tomonori@gmail.com \
--cc=greg@kroah.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).