Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2269714rwl; Thu, 30 Mar 2023 08:09:50 -0700 (PDT) X-Google-Smtp-Source: AKy350b19d9mFsnPwanpH0HomU7EFm6leDGlIO1ToyhrkmFeZRatXNjMUS6kGIMoEjTC2S4JrsfU X-Received: by 2002:a17:906:207:b0:933:23c4:820b with SMTP id 7-20020a170906020700b0093323c4820bmr2240419ejd.4.1680188990261; Thu, 30 Mar 2023 08:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680188990; cv=none; d=google.com; s=arc-20160816; b=uzfLUhJKENA37kOZO2f/sspU8Wj8OPw4RtLXm4/y2EYKLwY/NYQuNhGy+YiXthJMDM jJzW9HkxZpt3X9fpAZRDrlTN+SS8O+aQW682hcEJuypsF2RZpandVzLEFITwzNnUr/zR niHjY8scAnUjEno93ilZPEfxJgUtS+kOJB1MZqJSUgGsoSg9SmegaETzF1+p4DsoQB7C gT1jrHFZV0hXbH2DxtmF/cfdqv9x6tg8Bjou7oRJVLYqSxUSb6IX8i8q2UsBtz+nDxQs vmdKaSdRUEjPV4dxKMVzU0JvFbfks4co3d/lNavUoxemTjf5EwvY5BCArYR3PhjI5Exu q+2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=LBgpEuVRLV1T8u09/zjqM82d32cWiHoXkNx4ST+kG3A=; b=byJI6A8H6OQSTKPSAsfhoqMfgDjFDWkrtrXWU2J7gDUjUksMRusxp4Ytl4efCrfsjj 5xY1CRpu15I5u6SfvAJkLmjrKilwS+8s5UMzHiG6MGqPCe2Q7Ui4iZozWhxkdWoqutUJ c/q/SiZFI7kczbF9b3x56vAmk9+H4can2iz4MpXntOKOQiCMpYEphtDZ6KGiy2TWyizL 3DC1PxRdAWlFZa7aSaEM3why2NTRoDMZUPdFzhdh4+8AUMJF0TXblsPvo8FVS7zCAIk7 n/imditYTi9RYwextrAgnWwtuMe7RTD7V9w32zNR8fEBwoX074z8TVM58P3dj/Leus8f xmPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=Mn2MQFtC; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=XrNXNbEq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk17-20020a170906b0d100b008e7916f1952si35206702ejb.822.2023.03.30.08.09.06; Thu, 30 Mar 2023 08:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=Mn2MQFtC; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=XrNXNbEq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232752AbjC3PIB (ORCPT + 99 others); Thu, 30 Mar 2023 11:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232749AbjC3PH7 (ORCPT ); Thu, 30 Mar 2023 11:07:59 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 228F0CDDC; Thu, 30 Mar 2023 08:07:17 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id E856032006F2; Thu, 30 Mar 2023 11:07:15 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 30 Mar 2023 11:07:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1680188835; x=1680275235; bh=LBgpEuVRLV1T8u09/zjqM82d32cWiHoXkNx 4ST+kG3A=; b=Mn2MQFtCMDufOJX/6+aQOJNyHseLzzRKdAl2dO3KvU3v+w7h9Fc YeMbp6Cc7bQPwqD7q8HOefnxg0+5xUhPtFnKMYr9VV6B1/G3XC0Mj3Pnz0cX6kTc uuniZZct/z2dQ+I1bV87rOUXNvnGbt+nTaoFaA3biIl+RVphQ4QU89OtoMk7Co9u qhl8lguld4RTt6DYWM10Xvny1FBFLA7behEISgiYVYTauHzzY3M6IgDDYvuQNulB gKyiomP4RUuIPOIRwvvJylhRBJIBcWnnuKiJ+B8oW/QGF6GDnPEndrnxLd8BXEny LnU2Lm9b6noFb8WUJDXXrMFIXRmBpBAkalQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680188835; x=1680275235; bh=LBgpEuVRLV1T8u09/zjqM82d32cWiHoXkNx 4ST+kG3A=; b=XrNXNbEqRcpRfGFnpxb5OG2gI1kYvM77ukQD9XGDt/0/lp4GlpF VM40nAoTCVRL8X7earO8EhwyWu+PZryL4F9vZQts1FNvIURzy491ijZt7h1nxTKC 6X1igKRoCrwvruAcRspvoFDEQHIjrbQZdMoYGbIP+P5CXX1eJwXJisDr0FVO7AUi J+e+SIILArAEWLTOAMWw9UKwAJtVM4rlxcf2KubOc25x/HpMxPsJcXbfzDyb3bu2 z9Me3HVFJQVqIHl+Vtn6sm9V06fa95UZqJCJgtIeBbqXcoWwH7wZD5Lo2HdmlrdN DKwDtpj+j6I1Fk5KHb0/ztRvUbTcJ+/KaRw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehkedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe ehudduvdetkedvkedtudeludfgfffhudegjeeguedvvedtteevjeehheeiffefgeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhitggvse hrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 11:07:13 -0400 (EDT) Message-ID: <672f991f-96af-9389-278d-77bde2ee2db8@ryhl.io> Date: Thu, 30 Mar 2023 17:07:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v3 08/13] rust: init: add `stack_pin_init!` macro Content-Language: en-US To: Gary Guo , y86-dev@protonmail.com Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-9-y86-dev@protonmail.com> <20230330120600.45418253.gary@garyguo.net> From: Alice Ryhl In-Reply-To: <20230330120600.45418253.gary@garyguo.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/30/23 13:06, Gary Guo wrote: >> +impl StackInit { >> + /// Creates a new [`StackInit`] that is uninitialized. Use [`stack_pin_init`] instead of this >> + /// primitive. >> + /// >> + /// [`stack_pin_init`]: kernel::stack_pin_init >> + #[inline] >> + pub fn uninit() -> Self { >> + Self(MaybeUninit::uninit(), false) >> + } >> + >> + /// Initializes the contents and returns the result. >> + /// >> + /// # Safety >> + /// >> + /// The caller ensures that `self` is on the stack and not accessible in any other way, if this >> + /// function returns `Ok`. >> + #[inline] >> + pub unsafe fn init(&mut self, init: impl PinInit) -> Result, E> { > > Could this be made safe if the signature takes `self: Pin<&mut Self>` > instead? > > The std `pin!` macro is stable in > 1.68 so we can just `core::pin::pin!(StackInit::uninit())` and then > call `init` on it. > > Best, > Gary Yeah, I think that would work. If it's marked safe, then it will be possible to call `init` several times, but this is fine if `init` transitions the `StackInit` back into its uninitialized state before attempting to initialize it again.