From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 837D229A9FD; Thu, 15 May 2025 11:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747308484; cv=none; b=YI5q/ggjtTB8lVms3MLkBm2TDBtjfLyAhsQM+SHAtCppddWKPAgV/HspetPVkdSPwjy171mB3kqfpb1zO7kzA1/L1ZrUlvP05fh3ziMgeeyJbvFFKUvglMKuD+tCnzGuvScYT+ODkrgC53jUPE5YpavmDuxG9MHJuTFpnmudacE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747308484; c=relaxed/simple; bh=7+tI8hwLbYdzJV+gBIpLHIKMoHARD16RXhpQ66Lpp4g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mm/MbQEMTC6+x9nGk6a+baq2xfXsDnJpcIWnA0ASnrJflMl24dnAAVbr4onxxC5mv3W5YLjzBdMl1sur/FnRwxaUzbpgyhGqr0nuc4Rd2s0XZ9bnxpE/qHf7cc5+mnYePfvARn/BW2kW10UVbQPm6qB2Oe7zZSScGnzNnhdeLjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OJK9ePG8; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OJK9ePG8" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3a0adcc3e54so456529f8f.1; Thu, 15 May 2025 04:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747308481; x=1747913281; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/WRUASopis39OXvLEPbV9DFXqukBSZqYvvkgfn67TzI=; b=OJK9ePG8NDNx0v+dTR8ejo+gzdtEqT2dMy1sxFLl8/Gv89r2wUveXS6KnfoEzCz5qM +tlMmcF+bVkPx6BOlIPjBgtc2OdiPnNOOhJb+k3qzhrvtFZeyp7XGPrLV79K8L90Hh3W RQiupyhlHzJhlikskHfmArc7+GlR0T6bAzrW/L732y0/wuiYyAxa/9+IkbydgS2NGXuw 3VTM85k6yG+yCOLvSljwSPXzbzc0aLDsHePGQ5gBCl1n/rCI6dFnfqJU336SToApzbvU tzsf8pwWDuaeAaDU3ytLnUhjWro5tapXDYdhogjfb0usHoB7Rb2lQ0rSMIs8+svJMM9W 7h7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747308481; x=1747913281; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/WRUASopis39OXvLEPbV9DFXqukBSZqYvvkgfn67TzI=; b=OWPwI5uNOKL1yVd8w99m32dF/bL8tbE1tJYgjlM8fEIQ84kX5ezYbquPMmssdTqBT0 tew9cncY/+gbx/A/naN1MGEMUWvE6GJ66P1w5lRF8E2SKaQ3k+BDQTVvOli14zoe/aUn UD/Lz8GwTilgkA273F6VkPi2BdiQAnnockjnc0J+pTpWProoxbaQGwfxNDhwjW/dkqJ9 eVNRLzZuOZuwASQ87oxt6xohu0mhcxH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Source: AGHT+IGbTtkMc2zafm9iTKM3qZMaH0v+dLTSZ0CIbIO+8P/WRxIaRaD668iTpr1FLDn6Kp0dcuBW3Q== X-Received: by 2002:a05:6000:18c4:b0:3a3:58f0:a38b with SMTP id ffacd0b85a97d-3a358f0a69fmr1000632f8f.43.1747308480571; Thu, 15 May 2025 04:28:00 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-442f39517f7sm64497795e9.20.2025.05.15.04.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 04:28:00 -0700 (PDT) From: Christian Marangi To: Christian Marangi , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Andrei Botila , FUJITA Tomonori , Trevor Gross , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Danilo Krummrich , Sabrina Dubroca , Michael Klein , Daniel Golle , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [net-next PATCH v10 7/7] rust: net::phy sync with match_phy_device C changes Date: Thu, 15 May 2025 13:27:12 +0200 Message-ID: <20250515112721.19323-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250515112721.19323-1-ansuelsmth@gmail.com> References: <20250515112721.19323-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sync match_phy_device callback wrapper in net:phy rust with the C changes where match_phy_device also provide the passed PHY driver. As explained in the C commit, this is useful for match_phy_device to access the PHY ID defined in the PHY driver permitting more generalized functions. Signed-off-by: Christian Marangi --- rust/kernel/net/phy.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index a59469c785e3..936a137a8a29 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -418,15 +418,18 @@ impl Adapter { /// # Safety /// - /// `phydev` must be passed by the corresponding callback in `phy_driver`. + /// `phydev` and `phydrv` must be passed by the corresponding callback in + // `phy_driver`. unsafe extern "C" fn match_phy_device_callback( phydev: *mut bindings::phy_device, + phydrv: *const bindings::phy_driver ) -> crate::ffi::c_int { // SAFETY: This callback is called only in contexts // where we hold `phy_device->lock`, so the accessors on // `Device` are okay to call. let dev = unsafe { Device::from_raw(phydev) }; - T::match_phy_device(dev) as i32 + let drv = unsafe { T::from_raw(phydrv) }; + T::match_phy_device(dev, drv) as i32 } /// # Safety @@ -574,6 +577,23 @@ pub const fn create_phy_driver() -> DriverVTable { /// This trait is used to create a [`DriverVTable`]. #[vtable] pub trait Driver { + /// # Safety + /// + /// For the duration of `'a`, + /// - the pointer must point at a valid `phy_driver`, and the caller + /// must be in a context where all methods defined on this struct + /// are safe to call. + unsafe fn from_raw<'a>(ptr: *const bindings::phy_driver) -> &'a Self + where + Self: Sized, + { + // CAST: `Self` is a `repr(transparent)` wrapper around `bindings::phy_driver`. + let ptr = ptr.cast::(); + // SAFETY: by the function requirements the pointer is valid and we have unique access for + // the duration of `'a`. + unsafe { &*ptr } + } + /// Defines certain other features this PHY supports. /// It is a combination of the flags in the [`flags`] module. const FLAGS: u32 = 0; @@ -602,7 +622,7 @@ fn get_features(_dev: &mut Device) -> Result { /// Returns true if this is a suitable driver for the given phydev. /// If not implemented, matching is based on [`Driver::PHY_DEVICE_ID`]. - fn match_phy_device(_dev: &Device) -> bool { + fn match_phy_device(_dev: &mut Device, _drv: &T) -> bool { false } -- 2.48.1