lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250919112007.940061-2-thorsten.blum@linux.dev>
Date: Fri, 19 Sep 2025 13:20:08 +0200
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: FUJITA Tomonori <fujita.tomonori@...il.com>,
	Trevor Gross <tmgross@...ch.edu>,
	Andrew Lunn <andrew@...n.ch>,
	Heiner Kallweit <hkallweit1@...il.com>,
	Russell King <linux@...linux.org.uk>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	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>,
	Alice Ryhl <aliceryhl@...gle.com>,
	Danilo Krummrich <dakr@...nel.org>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
	netdev@...r.kernel.org,
	rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH net-next] rust: net::phy inline if expressions to improve read_status

Inline the if expressions for dev.set_speed() and dev.set_duplex() to
improve read_status(). This ensures dev.set_speed() is called only once
and allows us to remove the local variable 'duplex'.

Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
---
 drivers/net/phy/ax88796b_rust.rs | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/ax88796b_rust.rs b/drivers/net/phy/ax88796b_rust.rs
index bc73ebccc2aa..2dfd37936689 100644
--- a/drivers/net/phy/ax88796b_rust.rs
+++ b/drivers/net/phy/ax88796b_rust.rs
@@ -56,18 +56,17 @@ fn read_status(dev: &mut phy::Device) -> Result<u16> {
         // linkmode so use MII_BMCR as default values.
         let ret = dev.read(C22::BMCR)?;
 
-        if ret & BMCR_SPEED100 != 0 {
-            dev.set_speed(uapi::SPEED_100);
+        dev.set_speed(if ret & BMCR_SPEED100 != 0 {
+            uapi::SPEED_100
         } else {
-            dev.set_speed(uapi::SPEED_10);
-        }
+            uapi::SPEED_10
+        });
 
-        let duplex = if ret & BMCR_FULLDPLX != 0 {
+        dev.set_duplex(if ret & BMCR_FULLDPLX != 0 {
             phy::DuplexMode::Full
         } else {
             phy::DuplexMode::Half
-        };
-        dev.set_duplex(duplex);
+        });
 
         dev.genphy_read_lpa()?;
 
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ