From patchwork Wed Mar 29 22:32:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 76842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp732303vqo; Wed, 29 Mar 2023 15:43:15 -0700 (PDT) X-Google-Smtp-Source: AKy350bsL8Y7X/OccrayKntTGdaIslX1/NZ9gGFqOecm98qg/2yuOqsw9dvMyYGL3zsLLgYNiyGw X-Received: by 2002:a05:6402:206:b0:4fa:ac78:7f2a with SMTP id t6-20020a056402020600b004faac787f2amr17850278edv.41.1680129795546; Wed, 29 Mar 2023 15:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680129795; cv=none; d=google.com; s=arc-20160816; b=GTtmNhFfG85+65xOCY814ILTplJNQhaPjRn5pndQnpIJLKZfVYq6lHLL8Rp7VoGq5X GQvWqinrC2un7okoDJ/lQ/sIQC083oonIYvgnFoGy+AaA7DLiwC97r2lhbX7qkZ41F3T A5zL5H+Lg+Myrd5T5Yp0/ZsS+Os8+9Z7izrQFv9QjI6405kQ55xKvI4gQZmtIZeQpnWT lnDlqpdHVO+wOHBwAXGtDwF6uqJOF2yKmQ+HfurxnQ/nk0arw9WtJXtUl9vdtrbQqwx/ lhfEQZaHlYUh68h17wzpvhIUwN7jWyE9p2hg7ESJE6b9h1pVAy11YVdN2PcNVIJp5M0x ZNrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=sT/rlttzNSF7UJt0mIvVFloU5vc3XfQjYu+rGHSgh10=; b=tcHap3E+Aie/gqIyMTF0+1AnyDnX53Moxzuen5uYzXDZC9UwdJN9IB2aHny2FijF4Q bNm+94ifWUwXo0w1hjni1SEe9F+YtvXby/uqs5KLrywOlZxroW8ryPmoLLDOnmtjk+NG pOQokPze4J+MdYEoJG4Oy8i8UOY+eJ30aIKBz2MTnK6PSvBEUA8iFIqu5j/T0Zryqbjt jTInGmFICNI5Gca71W7izfMvqbphDXVUYQicfF0e3/bT9b1Ay42SnZRsswN0jKZUSC/+ dfcY4I7l4EebXyXBUlCvNWkhqDCO4i0MLu+xa4rxpQYaygGA4tk4MjJa1HU5uSx8+QDH L4mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=Tn7sB5nJ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n25-20020aa7db59000000b005021cf63eacsi15112063edt.265.2023.03.29.15.42.50; Wed, 29 Mar 2023 15:43:15 -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=@protonmail.com header.s=protonmail3 header.b=Tn7sB5nJ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbjC2WdN (ORCPT + 99 others); Wed, 29 Mar 2023 18:33:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbjC2WdJ (ORCPT ); Wed, 29 Mar 2023 18:33:09 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27F005B85; Wed, 29 Mar 2023 15:33:08 -0700 (PDT) Date: Wed, 29 Mar 2023 22:32:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680129186; x=1680388386; bh=sT/rlttzNSF7UJt0mIvVFloU5vc3XfQjYu+rGHSgh10=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Tn7sB5nJn4N2i7HWNE/zjhOZpRWOd6S0DMu6MgG5akvtvuHDXIMQntUfXxB7q8YFV ww54eUY7myQqcAwFR7VLBnTJTYefMwwIJUSd+2AvdYeIzSkTteD8eSVbrwMy0TkhKX bm6D5yLgYepYQXtfCdLvSC/u8be2ZT1Il99R8/invz9CO7ra4RUXBVVKTI1+W/eZV0 0GULkuJc0PI+XbKrRe06xlv447qC+Wd5YlyjG3y+uesNyVLx/41cwZmwPKvNUSg3d0 yjgz38rp3F0VIWeivFzxTGKsqB/1Sk1y44SEDCduZiTPdsjZ4RsqMtPW3Z7rHkVwU2 8adQcBLMH0gHg== To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl From: y86-dev@protonmail.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v3 02/13] rust: sync: add `assume_init` to `UniqueArc` Message-ID: <20230329223239.138757-3-y86-dev@protonmail.com> In-Reply-To: <20230329223239.138757-1-y86-dev@protonmail.com> References: <20230329223239.138757-1-y86-dev@protonmail.com> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761743780308297766?= X-GMAIL-MSGID: =?utf-8?q?1761743780308297766?= From: Benno Lossin Adds the `assume_init` function to `UniqueArc>` that unsafely assumes the value to be initialized and yields a value of type `UniqueArc`. This function is used when manually initializing the pointee of an `UniqueArc`. Signed-off-by: Benno Lossin Reviewed-by: Wedson Almeida Filho Reviewed-by: Andreas Hindborg Reviewed-by: Alice Ryhl --- rust/kernel/sync/arc.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.39.2 diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index f2f1c83d72ba..16ec174637b2 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -489,6 +489,17 @@ impl UniqueArc> { /// Converts a `UniqueArc>` into a `UniqueArc` by writing a value into it. pub fn write(mut self, value: T) -> UniqueArc { self.deref_mut().write(value); + // SAFETY: We just wrote the value to be initialized. + unsafe { self.assume_init() } + } + + /// Unsafely assume that `self` is initialized. + /// + /// # Safety + /// + /// The caller guarantees that the value behind this pointer has been initialized. It is + /// *immediate* UB to call this when the value is not initialized. + pub unsafe fn assume_init(self) -> UniqueArc { let inner = ManuallyDrop::new(self).inner.ptr; UniqueArc { // SAFETY: The new `Arc` is taking over `ptr` from `self.inner` (which won't be