Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2931334lqz; Wed, 3 Apr 2024 12:44:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/tYQoHKO2xxB4EFIJ8EpO0slJDeC9A0qyUlflsmd8qpx405thUHav7zhEAGKvXsK2mhvxFPJWhmJjChWrzGI/7q9vOoTRjMBXmPpIqg== X-Google-Smtp-Source: AGHT+IEB0WzgOIFWST6IFRq/kyTJHljlTz8ddyTe8ZP1h00N7FXDBXvknWtVnY6iETTr56+9VK6q X-Received: by 2002:a05:6a00:230b:b0:6e5:43b5:953b with SMTP id h11-20020a056a00230b00b006e543b5953bmr517775pfh.14.1712173473765; Wed, 03 Apr 2024 12:44:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712173473; cv=pass; d=google.com; s=arc-20160816; b=rDVKtJfHeNNgXMRKHZC2ahIVrFIoZeqMOk1ZsgE/Dz0p4exR5OGvigz+CV0WpoUX6J dRa/Dp6ZARCuAE2OxO4Bu1K8/txeQfmkI8n/EM7OOD/+HzemF8dlUCtzuCap05aSpLAr wUoHVv813RV5ohRLtjO4lRl20hnonQ3abj1WH1JpG/JTh8JPMjM5BvvyI1AeSyOJ8c7e XL1bJTpA/+ES2ns+Lf23u9RgB3uFXVE8zOBU3xaCl537VUaHqx2vSQ+ek9/1EyhDHPjC hZDAi4MqlLfb1wYb3Ri4OOmH3efKHxjr4d6APPFHyS2O0Drs54uTMXTRFtuMhWq9w+00 zrhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:message-id:subject:cc :from:to:date:dkim-signature; bh=Z/cYaiGjtg8Hl/T+kAOXPPgB1Msfoi/aGGBHya0iD3M=; fh=Ov/rTNdileIkvoFBvDwlWN6kRuLU6cjKBx/1/vxBh1M=; b=ecw10x5kX0IMR9NZT8Y+Ouzg4maGVsDoeDtcYIO4yCn7n87YtA1y39ZX/IeNaMlv2I 9BfkGkQi87mcx5Qs/NKXrG//ZZ4fh/QQwUqGavfC1p/8Sjf+IHkphYxI7n1earI07OJn wvN6CZwXzNPE+/OxwimYuDHhNjF+JPyVxCXdLOx4jmG54ncgHcwxUSKAohhcMc/r1n+N zaCuWlPkPUp6PoQ+7d70X1ZmqI+vRmWf6a8+yKsBVEINfbqBfsTn+7B885fl2Pnxi1yt gLbhID6bfKa3ZZ0A0vwKCbOibFeK7FHaaSM3uvkg8omRjwHOifT8xs/5EpQy8Me0IGfY Dv7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=CWdGqKKH; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-130515-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z11-20020a634c0b000000b005f0a512f885si8946964pga.224.2024.04.03.12.44.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 12:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130515-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=CWdGqKKH; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-130515-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E9FE128285D for ; Wed, 3 Apr 2024 19:43:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE045155394; Wed, 3 Apr 2024 19:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="CWdGqKKH" Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (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 F012D2F24 for ; Wed, 3 Apr 2024 19:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712173426; cv=none; b=ZqHp8fIZA0VgqYZ4dTTzl3WnaE+boTiepQyDk8oMopd8G1RzmthZANeASuDWH1qP0Q2Ah+1Q6mkTqXACeSXblWE2XK4rqvnxKMwTmAceUqIBDeGgpE8V0aPNTGvU8nBtGN7yPGvE1qTqEdpvlK5emO3x0OWQ24nVTp/vvSSRLTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712173426; c=relaxed/simple; bh=lzf+ES6yHZZVg6XniA+JFvQLjo8zG+VMBXl7BaaBibs=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=DBLWRCAbd1qTx9RMgRMlwT0mw8kpAz3yTy8EkILL7qosTczKzilEKcQercbEsxh9dZyEsslSZAaKnzObp2/E2JBwQzqDRvoytd2MhAV7H/NTDaLlR4DamFEKyypiFEIT+6EkgM3Ggfo3BWxcUBWrh0f34hqszw7eYJQ2BmfUxwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=CWdGqKKH; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712173422; x=1712432622; bh=Z/cYaiGjtg8Hl/T+kAOXPPgB1Msfoi/aGGBHya0iD3M=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=CWdGqKKHsAsyjwmhI5qIPRNj3R979LLdUL13yfBfn2xREbHxs/5Nqcjh2uILvfI5O JZPJy+Otrd+NutyHe9h+ONVRsSIcKOyBuiuVFYGba+GsQZOau3ZW71NpEozrU/2Z+x hRaj2IQzTATd50O0EiLt6V546HEYTYe68Od/d9CRFpVqGj93a2ImfgGU9tw0TGQHyL vC+QA1/BmpAGTnSRjtsFB/UUFtIByWdp6Mm5f1FlbL/Qvnr9rWXpnCOdWkFcmyF65q 7F/PnsO8oMpJD4it0zHRM5+iv2zdkOloAKCXUACNaGtzddHCLsi5ZEbREfo8KUXJUB npe1RSrkHXkMQ== Date: Wed, 03 Apr 2024 19:43:37 +0000 To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rust: init: change the generated name of guard variables Message-ID: <20240403194321.88716-1-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The initializers created by the `[try_][pin_]init!` macros utilize the guard pattern to drop already initialized fields, when initialization fails mid-way. These guards are generated to have the same name as the field that they handle. To prevent namespacing issues when the field name is the same as e.g. a constant name, add `__` as a prefix and `_guard` as the suffix. Signed-off-by: Benno Lossin --- rust/kernel/init/macros.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rust/kernel/init/macros.rs b/rust/kernel/init/macros.rs index cb6e61b6c50b..93bf4c3080f9 100644 --- a/rust/kernel/init/macros.rs +++ b/rust/kernel/init/macros.rs @@ -250,7 +250,7 @@ //! // error type is `Infallible`) we will need to dro= p this field if there //! // is an error later. This `DropGuard` will drop t= he field when it gets //! // dropped and has not yet been forgotten. -//! let t =3D unsafe { +//! let __t_guard =3D unsafe { //! ::pinned_init::__internal::DropGuard::new(::co= re::addr_of_mut!((*slot).t)) //! }; //! // Expansion of `x: 0,`: @@ -261,14 +261,14 @@ //! unsafe { ::core::ptr::write(::core::addr_of_mu= t!((*slot).x), x) }; //! } //! // We again create a `DropGuard`. -//! let x =3D unsafe { +//! let __x_guard =3D unsafe { //! ::kernel::init::__internal::DropGuard::new(::c= ore::addr_of_mut!((*slot).x)) //! }; //! // Since initialization has successfully completed= , we can now forget //! // the guards. This is not `mem::forget`, since we= only have //! // `&DropGuard`. -//! ::core::mem::forget(x); -//! ::core::mem::forget(t); +//! ::core::mem::forget(__x_guard); +//! ::core::mem::forget(__t_guard); //! // Here we use the type checker to ensure that eve= ry field has been //! // initialized exactly once, since this is `if fal= se` it will never get //! // executed, but still type-checked. @@ -461,16 +461,16 @@ //! { //! unsafe { ::core::ptr::write(::core::addr_of_mut!((*slo= t).a), a) }; //! } -//! let a =3D unsafe { +//! let __a_guard =3D unsafe { //! ::kernel::init::__internal::DropGuard::new(::core::add= r_of_mut!((*slot).a)) //! }; //! let init =3D Bar::new(36); //! unsafe { data.b(::core::addr_of_mut!((*slot).b), b)? }; -//! let b =3D unsafe { +//! let __b_guard =3D unsafe { //! ::kernel::init::__internal::DropGuard::new(::core::add= r_of_mut!((*slot).b)) //! }; -//! ::core::mem::forget(b); -//! ::core::mem::forget(a); +//! ::core::mem::forget(__b_guard); +//! ::core::mem::forget(__a_guard); //! #[allow(unreachable_code, clippy::diverging_sub_expression= )] //! let _ =3D || { //! unsafe { @@ -1192,14 +1192,14 @@ fn assert_zeroable(_: *m= ut T) {} // We use `paste!` to create new hygiene for `$field`. ::kernel::macros::paste! { // SAFETY: We forget the guard later when initialization has s= ucceeded. - let [<$field>] =3D unsafe { + let [< __ $field _guard >] =3D unsafe { $crate::init::__internal::DropGuard::new(::core::ptr::addr= _of_mut!((*$slot).$field)) }; =20 $crate::__init_internal!(init_slot($use_data): @data($data), @slot($slot), - @guards([<$field>], $($guards,)*), + @guards([< __ $field _guard >], $($guards,)*), @munch_fields($($rest)*), ); } @@ -1223,14 +1223,14 @@ fn assert_zeroable(_: *m= ut T) {} // We use `paste!` to create new hygiene for `$field`. ::kernel::macros::paste! { // SAFETY: We forget the guard later when initialization has s= ucceeded. - let [<$field>] =3D unsafe { + let [< __ $field _guard >] =3D unsafe { $crate::init::__internal::DropGuard::new(::core::ptr::addr= _of_mut!((*$slot).$field)) }; =20 $crate::__init_internal!(init_slot(): @data($data), @slot($slot), - @guards([<$field>], $($guards,)*), + @guards([< __ $field _guard >], $($guards,)*), @munch_fields($($rest)*), ); } @@ -1255,14 +1255,14 @@ fn assert_zeroable(_: *m= ut T) {} // We use `paste!` to create new hygiene for `$field`. ::kernel::macros::paste! { // SAFETY: We forget the guard later when initialization has s= ucceeded. - let [<$field>] =3D unsafe { + let [< __ $field _guard >] =3D unsafe { $crate::init::__internal::DropGuard::new(::core::ptr::addr= _of_mut!((*$slot).$field)) }; =20 $crate::__init_internal!(init_slot($($use_data)?): @data($data), @slot($slot), - @guards([<$field>], $($guards,)*), + @guards([< __ $field _guard >], $($guards,)*), @munch_fields($($rest)*), ); } base-commit: 9ffe2a730313f27cebd0859ea856247ac59c576c --=20 2.44.0