From patchwork Fri Mar 31 21:52:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 77990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp861403vqo; Fri, 31 Mar 2023 14:54:26 -0700 (PDT) X-Google-Smtp-Source: AK7set8m7Btdf5pY0/tG60yA/Jb6UShW1H+1uJF7OzAPNKynwipv+ZE0gttaTs+kfU8EFhbNmGqV X-Received: by 2002:a05:6a20:4e02:b0:d5:2bf3:fd8e with SMTP id gk2-20020a056a204e0200b000d52bf3fd8emr23633744pzb.2.1680299666430; Fri, 31 Mar 2023 14:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680299666; cv=none; d=google.com; s=arc-20160816; b=SJdXya/dLmvJRgaaSXauLEZeCHwG4XifXTnKuPzP6zpzP+jkKYik0cn66Is8VrHKRK zq3aISdcQdXI7W8deP6l7N3ouPZY90GRvoSvcYN5MgzC8LqB8KmQzR9wllhY0+4sdIF8 a5/Q4HcnlfpB5YGH3rF94G6/rlDZBsUlxH5ZcvXe62/Fs3Kg10IR6mX9YY9yuYFGOwbj rah9E8O6EHV1DT59hK3FeZhrnAYdx3qULzvLEXHLGWQFrk00nSI+zmSvJgPVO6z4OjZ4 EUIFy4IO2bKA1Aq46CTlI+oYwhuAn2ukZZyOxkYiu/KcB3Grj+emSNnFsTU/6yxOyai3 LStQ== 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=fCD7QTf0NZAcpNwJgHyXCpsYx4VPF0WMhGRDfNF+eao=; b=Zt5jMEOPuWrrfWIZ7eTPGSFNY7vZJKj3WxFu7j+Ygb6a2Hvkjr8pFGgZWLIrNogTWq l/UGtLNEamWNT03/i18txxSBWPmp+e/MI1TrwngUfQRe/JoLd9TXtbBzCWodkvH0WaZL Yyhjv4XUk7bVB+kv/mFCgRpGdAaDyufx03OKWmwPMqPaDfFfAZBtHzs4I3gdSyqRRYq9 Tt9l8rOhRgODyoQQUOn93W3JerdStpwPuDUBo/+a0zC3zf8/vve/uRom6Zg+Uf2qwU7G vjZf6NG29+qPSn6ZrMpO5rOHXcoY9NsicuK9kEzqGWomEqS29dotPz8b+GncYS7bFHRU yolQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=fkwXxkoQ; 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 s5-20020a632c05000000b0051323b8a185si3362491pgs.811.2023.03.31.14.54.13; Fri, 31 Mar 2023 14:54:26 -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=fkwXxkoQ; 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 S233290AbjCaVxi (ORCPT + 99 others); Fri, 31 Mar 2023 17:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbjCaVx2 (ORCPT ); Fri, 31 Mar 2023 17:53:28 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EC5F30E4; Fri, 31 Mar 2023 14:52:56 -0700 (PDT) Date: Fri, 31 Mar 2023 21:52:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680299567; x=1680558767; bh=fCD7QTf0NZAcpNwJgHyXCpsYx4VPF0WMhGRDfNF+eao=; 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=fkwXxkoQiGH2lxZtZFilav8ir/R+Obh5Y4WxmpOce5eII0NrPjqzhI3b/fT9kPwbA xlblEwRFZo+AMIjzIC+7F9VhvZKB9qh/Wy6o5l2qpT05hH89TFhFWYPEzsksKgs34C 7PBPR4+0bYWxYteXCw2WcW2m3GWNywrEb1cWl6+fuxwjIDB/SGVYma8owNnkRcq8fZ lNG1UQShykTKTfXTDgXqTtwbg3ooU2obaZwAv14GrnQWWXPx9xHn2N3OloXz5R488L 3C0hk1jkKhGhQs8zQDSHmE9ciVlNQfVk7fbnhsjjazIqmFGe3aoH3U9/6k551B7tlx vE7FqwVEqTh4w== 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, Benno Lossin , Wedson Almeida Filho , Andreas Hindborg , Alice Ryhl Subject: [PATCH v4 04/15] rust: sync: add `assume_init` to `UniqueArc` Message-ID: <20230331215053.585759-5-y86-dev@protonmail.com> In-Reply-To: <20230331215053.585759-1-y86-dev@protonmail.com> References: <20230331215053.585759-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?1761921902953443305?= X-GMAIL-MSGID: =?utf-8?q?1761921902953443305?= 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 aa7135f0f238..eee7008e5e3e 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