From patchwork Wed Apr 5 19:35:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 79880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp546964vqo; Wed, 5 Apr 2023 12:39:39 -0700 (PDT) X-Google-Smtp-Source: AKy350YH3bhaWvHJcCgi/HrnJbn/Mj1oMbrPQiFzVpidRkBi3TUobNQJ+jvp43H2Nzhi6dWq/crF X-Received: by 2002:a05:6a20:a91f:b0:d4:fd7e:c8b0 with SMTP id cd31-20020a056a20a91f00b000d4fd7ec8b0mr382441pzb.7.1680723578953; Wed, 05 Apr 2023 12:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680723578; cv=none; d=google.com; s=arc-20160816; b=LlenmFt8oCQt0TdUDnSNU60XYBsHbXPJfOgzZHolP6N+9TR4LQHgR9PVO+i3q+FHoA edaQENkeTNexI5Lz3L//jfcddwE7/Pfiyh1W90ekjbjnnxyl6fqys+5MnVU4m61JJIu3 0jn6d0yLQbzt2MWgIekjHM1eTWKrGo5N1O2l60+mJqP2e0nDUzxq3vZAjiw7PSUUjZgR kDtCmTHH4vPSHSSREj8rKi93GVt8JmWlWKT/OXM2SN1WrE/s93UOxam7degySDu0bKPc buSl8J+/Bc+Od78mzuCdbAobgcVI2qCeYO7M+MfCbN9tY1FVt4DeNF5Io9fYM3Tl0GmK ofWw== 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=y0jqQmRihbQy6PFbiLq9TWbJGhTdPblKZdeet4PB4xK3u2cFXsKSFvKpuErEpHX0h8 SjlUx3ziU04aFWK1Ue58488r8tRziYMxwO8xuDyC4mrKmdWtQHitqNGyW0qfTSmgy0E3 vRvmxkAl+luF4Yq1xHmxdNqE/aLNQSE4fR0CaMWyr/Sz5SKPbCRI9GsE3/TkCvOUNmqu JtswsKIyI43uLs7xokG5giIhjX2cMTHkIi+u/QybF5QlM/GG2o8Wq7arSmfelBvpNc7O WOAspVtuMX+fSgicAWwoRE8IEvxJ3CcKofGrNy+HN5CcztmBsWMEtWYosSE99Z3gZJ/e 9SAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=k1bDJwnR; 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 w4-20020a656944000000b004dacaa17ecbsi12242846pgq.559.2023.04.05.12.39.26; Wed, 05 Apr 2023 12:39:38 -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=k1bDJwnR; 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 S233686AbjDETga (ORCPT + 99 others); Wed, 5 Apr 2023 15:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233949AbjDETgU (ORCPT ); Wed, 5 Apr 2023 15:36:20 -0400 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D42D076AD for ; Wed, 5 Apr 2023 12:36:01 -0700 (PDT) Date: Wed, 05 Apr 2023 19:35:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680723360; x=1680982560; 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=k1bDJwnR1Mh5ZCHYhOi0VM/5Cn3q9uKQ1GskpL23RktG+pOXwX88WsSJXTjsDDUkF c1zIHMckBu0PVMq/kK60tC8HnenbCK2ohcsaUTBBt/6uK+ZOi/MnaSqgKEGA4h83oe efi1oMZyyYlrh+IVcx6MNdIfLLttFbdSIBHVfZ3Pr1S9x02NAOAi1sAtnaUNp1z21U Fai1shhRJxAk4LQ2FoxPIWFwaFp2WHfctXuslED7lCPFz0NxaEygg7CwZsXy0rKiWq O++PlEtzDODy8C3qq66iTxGLSiBJfEwuDRgz95b3FysbGrwUkVQViH9KW45RQfdQH7 uVZFH9hdVPqrA== 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 v6 04/15] rust: sync: add `assume_init` to `UniqueArc` Message-ID: <20230405193445.745024-5-y86-dev@protonmail.com> In-Reply-To: <20230405193445.745024-1-y86-dev@protonmail.com> References: <20230405193445.745024-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?1762366407483745477?= X-GMAIL-MSGID: =?utf-8?q?1762366407483745477?= 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