netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Tamir Duberstein <tamird@gmail.com>
Cc: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Andrew Lunn" <andrew@lunn.ch>,
	netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: cast to the proper type
Date: Mon, 23 Jun 2025 11:39:39 +0000	[thread overview]
Message-ID: <aFk8-_TNeV51v2OA@google.com> (raw)
In-Reply-To: <20250611-correct-type-cast-v1-1-06c1cf970727@gmail.com>

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@gmail.com>

Please use unqualified imports.

>  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,
};

Alice

>          // SAFETY: The struct invariant ensures that we may access
>          // this field without additional synchronization.
>          unsafe { (*phydev).duplex = v };
> 
> ---
> base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
> change-id: 20250611-correct-type-cast-1de8876ddfc1
> 
> Best regards,
> --  
> Tamir Duberstein <tamird@gmail.com>
> 

  parent reply	other threads:[~2025-06-23 11:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 10:28 [PATCH] rust: cast to the proper type Tamir Duberstein
2025-06-11 11:42 ` Alice Ryhl
2025-06-11 13:30   ` Tamir Duberstein
2025-06-11 13:41     ` Tamir Duberstein
2025-06-12  0:48       ` FUJITA Tomonori
2025-06-12  0:48     ` FUJITA Tomonori
2025-06-12  0:54       ` Tamir Duberstein
2025-06-19 15:29         ` Tamir Duberstein
2025-06-19 22:54           ` FUJITA Tomonori
2025-06-19 23:24             ` Tamir Duberstein
2025-06-20  1:05               ` FUJITA Tomonori
2025-06-20 17:25                 ` Miguel Ojeda
2025-06-23 11:39 ` Alice Ryhl [this message]
2025-06-24 11:56   ` Tamir Duberstein

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=aFk8-_TNeV51v2OA@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=davem@davemloft.net \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    /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).