From patchwork Sat Apr 8 12:25:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 81191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp851202vqo; Sat, 8 Apr 2023 05:43:36 -0700 (PDT) X-Google-Smtp-Source: AKy350bFMSEyDc89ATE8LBUkz/9kZXshs1rqg5rZGiz6iWXbPiUuBbpOIcEuAh6/Nam6bDHWMwW6 X-Received: by 2002:aa7:d4c4:0:b0:4fb:4f1a:d4e1 with SMTP id t4-20020aa7d4c4000000b004fb4f1ad4e1mr4888103edr.37.1680957816593; Sat, 08 Apr 2023 05:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680957816; cv=none; d=google.com; s=arc-20160816; b=WyiAItBK6fHrp/CWiPr5Idgqhz8r6uJs6lWlBBcv4Uj0Ugm6MLSvk4sZ/pKVg+jbK5 HHd6sLbBI8SmQ17yy/D1enh9iexwq7wK0Fm5tKXuie5NR2Xw9EZ2Kz26WRyg4ZZx5R4Z WHBLleGc4fv/9EpvOoMXHo4g1OIIRs1G6El7Ih5pLCAr5oW7zZSzLIuMVP8mb7GYxYI0 QxGSNMvT+8ERLCksV4TgU6yEewmjU0FSMAT9k1rS/VqEWeIDwsmrCMm5BM6FzVL/roZh Tz+DV25GUH/sfXEpkErE6Mik6N2wey/TG5ECCwWgdDOqa6t9GLA/wqSzvGYn5lw0n7tz mLnQ== 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=35ec0Ze6x4vGPDCyxTq1eqzjMeEQtTPCRJPMgIkdSpQ=; b=dqOQpybQ/PRA+G15Ph+2tniQtFweps+FGv+9QiwSdFeEFBFwK+PAEXHFOdy3Bmgcs9 B1hVLXI2oKIExqYvjnoVlyn2dOWpFLFtC8u4CIrHDHHnoi0EB7+QzfukSH0yXuGDkuq0 rLbExrqbyZbWgITln+gxuOADJMmQR36+u5HG/cp67qNY3eoCHKPIokHio4CywJYpEl8K xnpllF33AFt4NK4g3P0JAVUylRuVRbaPpgiX/LiuRjRsMcp/1AO1UriLrWM5KgTOA1am d7UU0/WmstIAMDaYnWEMZWpbyWtlGVZWR2iqg0e2Ikvd7xd5AqP+UXC2466ZjNrMyZg0 qU/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=FYV5X6kK; 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 a13-20020a50e70d000000b004bf976a1b56si4968562edn.627.2023.04.08.05.43.12; Sat, 08 Apr 2023 05:43:36 -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=FYV5X6kK; 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 S230388AbjDHM0G (ORCPT + 99 others); Sat, 8 Apr 2023 08:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230099AbjDHM0A (ORCPT ); Sat, 8 Apr 2023 08:26:00 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 750A9EF92 for ; Sat, 8 Apr 2023 05:25:43 -0700 (PDT) Date: Sat, 08 Apr 2023 12:25:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680956741; x=1681215941; bh=35ec0Ze6x4vGPDCyxTq1eqzjMeEQtTPCRJPMgIkdSpQ=; 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=FYV5X6kKzH5aJLDgjemr4GztE2oe4Czvvz/JEScQv86bVFwyj0bZQ1YRQ1hXChD9m 3TfJzwTozZAHgbsWWOZFmPzRq+oxCGxUubp6HDE1DA/kfD2Jl3me0k1jwGXVMFL7z1 G3PtJmyAHAvFh4bu8fmOqU6fUhvBZ4zTl2OnBlgsn5wTU0dbtv4rMv8j6Hgx+MG3iv /jmRBJoVztPeM8++iv/hgDoghU2IlJTC/z5XU/5+0xPRd8G9p/+5WdM5jBE9tJkzxm bWSk1b7oP1fY8hLYYx7rVrfQl3Efnj57NMVrR1orrmdGJfkmE2/0WKmBJ1K/XEuJWK usrgK6JiuE8fg== To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl , Andreas Hindborg From: Benno Lossin 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 v7 04/15] rust: sync: add `assume_init` to `UniqueArc` Message-ID: <20230408122429.1103522-5-y86-dev@protonmail.com> In-Reply-To: <20230408122429.1103522-1-y86-dev@protonmail.com> References: <20230408122429.1103522-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?1762612023518630381?= X-GMAIL-MSGID: =?utf-8?q?1762612023518630381?= 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