Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1064923rwl; Fri, 31 Mar 2023 06:19:41 -0700 (PDT) X-Google-Smtp-Source: AKy350aAFcBhrO+Qpme5O5IhbfrcUSRUNBjPvCUjBI/lDxew5qM9HkQQGgFL5YZ0v9b3zqcaHzGy X-Received: by 2002:a17:902:b702:b0:19a:723a:8405 with SMTP id d2-20020a170902b70200b0019a723a8405mr6173221pls.6.1680268781434; Fri, 31 Mar 2023 06:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680268781; cv=none; d=google.com; s=arc-20160816; b=uzf3Y6lW6Ufy0J2UE3o51AwZSS1hnXN7XhdaBz5xNbZPV/NLKD32YPFXgdJjHGg5V0 V85iekmHwDrk06wz0yynS+oyHOmHaJ8briSkHJS28qls6NlOD5A5+Q2TwsPenaevQWRK VrVKfndAPZ+UUXpYFCFFJ5ikkV/YGAe7ufa8iZhOsdB15LGsStPHGq0NZZtrmR8z5P0r eX6vDsGtUh47JYqZcarYvq0zpTAhvEhUrzQR6zP+Wp2eVHv+GNeL1WtQ2VFdVZBANwYl 9Sqgj1w0zBXrg10ckomn3uAEIJNXX0sna76USnXwAHq+KoqYQqBKxnUZG4l8M9OoV4IM HWgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=E8V1Bl8K2mO5BPBfvC+IG4HaObqCUBUdhVKIlW8yaQo=; b=hy1sdKThoZyD3cUH48qOvr4S2bmNtubbBb1K2UlP9ZQPy0QkH/Xi75iw3oFIC7EFRv gXPfH4QPflY6W1VLkK952FG2/XHBPr7egzlnjfYwEBDb/gXlzj+6ilRKF+GijyTYLkhJ pFXhiV7V//X1Uc11c7k33rgfr7tSfEL/W3O0EctFTGEUEK/5hK/U1NpcP8fzMVt18cVP fb3HJ9fvx3JCQv7g5KwXfehtjbAxaOpJZtBwLHu3cQpGq9tFS1vo51EyRewb6pDGmmyr 6XyRz0TV8nfNUo2t7AipyKHA4H5sc2zdZtHgY0l84O6y8OybaUYaivD2T+ZiYxqvBx9D i7Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=D+VDfK4V; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id co19-20020a17090afe9300b0023750b695e1si6458524pjb.156.2023.03.31.06.19.24; Fri, 31 Mar 2023 06:19:41 -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=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=D+VDfK4V; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232746AbjCaNIV (ORCPT + 99 others); Fri, 31 Mar 2023 09:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbjCaNIU (ORCPT ); Fri, 31 Mar 2023 09:08:20 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42B7E1A944 for ; Fri, 31 Mar 2023 06:08:16 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id s13so12831734wmr.4 for ; Fri, 31 Mar 2023 06:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20210112.gappssmtp.com; s=20210112; t=1680268095; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=E8V1Bl8K2mO5BPBfvC+IG4HaObqCUBUdhVKIlW8yaQo=; b=D+VDfK4ViTsTLqpx0PYLWBqb8J4neG7eMOaU8bJKAHpCu3K2VVXJrxkgG7HWg3RF7O 3YhBpfhQuOWzGFwPd9EmvBhb2eEAFocYMNDJPJ63OD12pRlFkZYUjZznBY6J4SL7/GRa HkrePY+ZI4Y/ouzuNx3DPy13aqAAt2vp+0saNScT4C60weOcSvZGni0SvWvojiB366yb a7Ku97b4NEoRLLi2nYa99gWk2ScH284ibaIerojT0XEi4+DAZIxIOtjVCdMvdE+cMlPb jAihkEPRJd+qbjGxkmWlVI6kKtUBJ+6S9Ff2/Ok/Ks1Hj7kA+poVXUGC5E3UfQtpTiuX wqAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680268095; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=E8V1Bl8K2mO5BPBfvC+IG4HaObqCUBUdhVKIlW8yaQo=; b=Dcz3j0b/feC9c1pZFdLWzj2HvXzd4haX33ZttkWSZSS3APHNYKnBCK6tGXksQtR2ae 0g3fUDUGnTNi4Lm4GnE4mxakfY+n93uCl6y74C8yxkJGkXEtCBSQ2e86X1Hv5vQRiY00 agdkFUWo/wi4l42rlmirTjCQlR9sWhAJbZD0H9gZkN+K4hDdbjYvbgFpT2GFwPyEwhBv G6F5DeO6Jicwlpi08oPZmdbFsv6hdMaw42aBRu/8bruVp54ncQfuStgw+mTCYaTDy8rA Ua3aCOK/w8Xo0ZfQtqcZM+6gVyisfVZlfd5lrXLWS9BSzgupwYvlPHtGz7UUXf9C9Rmp hzdw== X-Gm-Message-State: AO0yUKWfi+LD5OrjLB+fNbjcWUYOooZ20xPoqfPwRmeslOPnc9DyI0Hp Yle7HSMngHDVHWoAcumX4ogN/Q== X-Received: by 2002:a7b:c8c3:0:b0:3ed:711c:e8fe with SMTP id f3-20020a7bc8c3000000b003ed711ce8femr23029661wml.2.1680268094744; Fri, 31 Mar 2023 06:08:14 -0700 (PDT) Received: from localhost ([194.62.217.4]) by smtp.gmail.com with ESMTPSA id v16-20020a5d6110000000b002d89e113691sm2173758wrt.52.2023.03.31.06.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 06:08:14 -0700 (PDT) References: <20230329223239.138757-14-y86-dev@protonmail.com> User-agent: mu4e 1.9.18; emacs 28.2.50 From: Andreas Hindborg To: y86-dev@protonmail.com Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Andreas Hindborg Subject: Re: [PATCH v3 13/13] rust: sync: add functions for initializing `UniqueArc>` Date: Fri, 31 Mar 2023 15:07:18 +0200 In-reply-to: <20230329223239.138757-14-y86-dev@protonmail.com> Message-ID: <87v8ih1329.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 y86-dev@protonmail.com writes: > From: Benno Lossin > > Add two functions `init_with` and `pin_init_with` to > `UniqueArc>` to initialize the memory of already allocated > `UniqueArc`s. This is useful when you want to allocate memory check some > condition inside of a context where allocation is forbidden and then > conditionally initialize an object. > > Signed-off-by: Benno Lossin > --- Reviewed-by: Andreas Hindborg > rust/kernel/sync/arc.rs | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index 4ed6329a5e5f..64b0e9d67025 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -540,6 +540,30 @@ impl UniqueArc> { > inner: unsafe { Arc::from_inner(inner.cast()) }, > } > } > + > + /// Initialize `self` using the given initializer. > + pub fn init_with(mut self, init: impl Init) -> core::result::Result, E> { > + // SAFETY: The supplied pointer is valid for initialization. > + match unsafe { init.__init(self.as_mut_ptr()) } { > + // SAFETY: Initialization completed successfully. > + Ok(()) => Ok(unsafe { self.assume_init() }), > + Err(err) => Err(err), > + } > + } > + > + /// Pin-initialize `self` using the given pin-initializer. > + pub fn pin_init_with( > + mut self, > + init: impl PinInit, > + ) -> core::result::Result>, E> { > + // SAFETY: The supplied pointer is valid for initialization and we will later pin the value > + // to ensure it does not move. > + match unsafe { init.__pinned_init(self.as_mut_ptr()) } { > + // SAFETY: Initialization completed successfully. > + Ok(()) => Ok(unsafe { self.assume_init() }.into()), > + Err(err) => Err(err), > + } > + } > } > > impl From> for Pin> {