[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJ-ks9nsjSOBE8LQtWpC5r98WAekXwzC9yDZxHdsJ=p1BX5ZYw@mail.gmail.com>
Date: Tue, 24 Jun 2025 04:56:08 -0700
From: Tamir Duberstein <tamird@...il.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: FUJITA Tomonori <fujita.tomonori@...il.com>, Trevor Gross <tmgross@...ch.edu>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Danilo Krummrich <dakr@...nel.org>, "David S. Miller" <davem@...emloft.net>, Andrew Lunn <andrew@...n.ch>,
netdev@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: cast to the proper type
On Mon, Jun 23, 2025 at 4:39 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> On Wed, Jun 11, 2025 at 06:28:47AM -0400, Tamir Duberstein wrote:
> > Use the ffi type rather than the resolved underlying type.
> >
> > Fixes: f20fd5449ada ("rust: core abstractions for network PHY drivers")
> > Signed-off-by: Tamir Duberstein <tamird@...il.com>
>
> Please use unqualified imports.
OK, I will change this to two patches in v2; the first will change all
ffi references in this file to unqualified, the second will be this
with unqualified references.
>
> > rust/kernel/net/phy.rs | 10 +++++-----
> > 1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
> > index 32ea43ece646..905e6534c083 100644
> > --- a/rust/kernel/net/phy.rs
> > +++ b/rust/kernel/net/phy.rs
> > @@ -163,17 +163,17 @@ pub fn set_speed(&mut self, speed: u32) {
> > let phydev = self.0.get();
> > // SAFETY: The struct invariant ensures that we may access
> > // this field without additional synchronization.
> > - unsafe { (*phydev).speed = speed as i32 };
> > + unsafe { (*phydev).speed = speed as crate::ffi::c_int };
>
> unsafe { (*phydev).speed = speed as c_int };
>
> > }
> >
> > /// Sets duplex mode.
> > pub fn set_duplex(&mut self, mode: DuplexMode) {
> > let phydev = self.0.get();
> > let v = match mode {
> > - DuplexMode::Full => bindings::DUPLEX_FULL as i32,
> > - DuplexMode::Half => bindings::DUPLEX_HALF as i32,
> > - DuplexMode::Unknown => bindings::DUPLEX_UNKNOWN as i32,
> > - };
> > + DuplexMode::Full => bindings::DUPLEX_FULL,
> > + DuplexMode::Half => bindings::DUPLEX_HALF,
> > + DuplexMode::Unknown => bindings::DUPLEX_UNKNOWN,
> > + } as crate::ffi::c_int;
>
> I would keep the imports on each line.
>
> let v = match mode {
> DuplexMode::Full => bindings::DUPLEX_FULL as c_int,
> DuplexMode::Half => bindings::DUPLEX_HALF as c_int,
> DuplexMode::Unknown => bindings::DUPLEX_UNKNOWN as c_int,
> };
Could you help me understand why that's better?
Powered by blists - more mailing lists