From patchwork Sat Dec 14 19:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Rameshbabu X-Patchwork-Id: 13908594 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A8151119A; Sat, 14 Dec 2024 19:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.29 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734205395; cv=none; b=WmtEFWNKGQ+8h6C9PPEO/6HrYJISFoEhJeuEiKNsYT4ogbjLR+vcKFLJ/sRgqWWrcLkFYB3/8fQP3KBdkSiflixXPsivK9uw3aLe4oKbJf1fVqx+/8OuI39mIpqBkCdXy9Y6yFVWz1Fy1S/tIq7NlANncOOaUBt8vfkzSSYsg0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734205395; c=relaxed/simple; bh=tXqciZ4bi16lw4tGIOlIHwU2qwiOiHAdCX1Cma++6LQ=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=rADVA5whkHqlWCd+6vTauS+ycEuLP+GhGv9gmdjZc1ii4axVq938u5Q9gAUe3PBUwegOeDa+a63HsFiBzmCxgMN+pfybhm1Qq7eFVdji6Rw+Nkjzs23q/XIOGL1333UJWAZwJEIkhDVv2+9+3lklxOOO2MuXP31H36lM1A8gnXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=qu8Bfyvo; arc=none smtp.client-ip=79.135.106.29 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="qu8Bfyvo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734205391; x=1734464591; bh=djRhhUH3mgerGdQ1ZA/d9QHoyZN0+WSjWLmBCwL3nhs=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=qu8BfyvoDw0wDK/ggOhvkWyvkNqVmOTzGnu4M0LU/oyljt7vHz7PHMWdPAsUbpyuu czyYh2Tk62SyQek/JTYmD9CQzqKdmZuuAkgUPx4QwTR2hHedZr5yVMBe24tTKV252f 8s/fbrcKKYK4Ru0XgcNEThKawYFSxojESBFi7ia7Y1NMvIJ5FMHOT2v9JSxjdvUIeq G4F5ir+PIRLqOXcjxPdCxvm4WGSh28WSOLZQ1PB/mWSYiwRWpZnF7GGuP/DYg4h7z9 T28y8iwJiedWKJn0w328e3uPx8Qr9WMIFGI5L4u0+c7K7tYN1l3OK5IPR03qllC3Wa JgSD4yC4NIB9g== Date: Sat, 14 Dec 2024 19:43:06 +0000 To: netdev@vger.kernel.org, rust-for-linux@vger.kernel.org From: Rahul Rameshbabu Cc: Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" , Andrew Lunn , Rahul Rameshbabu , FUJITA Tomonori , Alice Ryhl Subject: [PATCH net-next v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro Message-ID: <20241214194242.19505-1-sergeantsagara@protonmail.com> Feedback-ID: 26003777:user:proton X-Pm-Message-ID: 343454d894d86e60e952ec0404fc15c470e70326 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Similar to the use of $crate::Module, ThisModule should be referred to as $crate::ThisModule in the macro evaluation. The reason the macro previously did not cause any errors is because all the users of the macro would use kernel::prelude::*, bringing ThisModule into scope. Signed-off-by: Rahul Rameshbabu Reviewed-by: FUJITA Tomonori Reviewed-by: Alice Ryhl --- Notes: Notes: v1->v2: Dropped the Fixes: tag and target net-next. How I came up with this change: I was working on my own rust bindings and rust driver when I compared my macro_rule to the one used for module_phy_driver. I noticed, if I made a driver that does not use kernel::prelude::*, that the ThisModule type identifier used in the macro would cause an error without being scoped in the macro_rule. I believe the correct implementation for the macro is one where the types used are correctly expanded with needed scopes. rust/kernel/net/phy.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) base-commit: 9bc5c9515b4817e994579b21c32c033cbb3b0e6c diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index b89c681d97c0..00c3100f5ebd 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -837,7 +837,7 @@ const fn as_int(&self) -> u32 { /// [::kernel::net::phy::create_phy_driver::()]; /// /// impl ::kernel::Module for Module { -/// fn init(module: &'static ThisModule) -> Result { +/// fn init(module: &'static ::kernel::ThisModule) -> Result { /// let drivers = unsafe { &mut DRIVERS }; /// let mut reg = ::kernel::net::phy::Registration::register( /// module, @@ -903,7 +903,7 @@ struct Module { [$($crate::net::phy::create_phy_driver::<$driver>()),+]; impl $crate::Module for Module { - fn init(module: &'static ThisModule) -> Result { + fn init(module: &'static $crate::ThisModule) -> Result { // SAFETY: The anonymous constant guarantees that nobody else can access // the `DRIVERS` static. The array is used only in the C side. let drivers = unsafe { &mut DRIVERS };