[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1a717f2d-8512-47bd-a5b3-c5ceb9b44f03@lunn.ch>
Date: Sun, 18 Aug 2024 17:44:44 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: FUJITA Tomonori <fujita.tomonori@...il.com>, netdev@...r.kernel.org,
rust-for-linux@...r.kernel.org, tmgross@...ch.edu,
miguel.ojeda.sandonis@...il.com, aliceryhl@...gle.com
Subject: Re: [PATCH net-next v4 6/6] net: phy: add Applied Micro QT2025 PHY
driver
On Sat, Aug 17, 2024 at 09:34:13PM +0000, Benno Lossin wrote:
> On 17.08.24 20:51, Andrew Lunn wrote:
> >> + fn read_status(dev: &mut phy::Device) -> Result<u16> {
> >> + dev.genphy_read_status::<C45>()
> >> + }
> >
> > Probably a dumb Rust question. Shouldn't this have a ? at the end? It
> > can return a negative error code.
>
> `read_status` returns a `Result<u16>` and `Device::genphy_read_status`
> also returns a `Result<u16>`. In the function body we just delegate to
> the latter, so no `?` is needed. We just return the entire result.
>
> Here is the equivalent pseudo-C code:
>
> int genphy_read_status(struct phy_device *dev);
>
> int read_status(struct phy_device *dev)
> {
> return genphy_read_status(dev);
> }
>
> There you also don't need an if for the negative error code, since it's
> just propagated.
O.K, it seems to work. But one of the things we try to think about in
the kernel is avoiding future bugs. Say sometime in the future i
extend it:
fn read_status(dev: &mut phy::Device) -> Result<u16> {
dev.genphy_read_status::<C45>()
dev.genphy_read_foo()
}
By forgetting to add the ? to dev.genphy_read_status, have i just
introduced a bug? Could i have avoided that by always having the ?
even when it is not needed?
Andrew
Powered by blists - more mailing lists