From patchwork Wed Mar 29 22:33:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 76848 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp738697vqo; Wed, 29 Mar 2023 16:00:52 -0700 (PDT) X-Google-Smtp-Source: AKy350YHbKqbJR0NhxNE11SHbFAeW6klXdt1CRO123Ck8AIiu6KWexHWcAYd8+RRlGGiLR1g60/0 X-Received: by 2002:a05:6402:4d5:b0:4ac:d2b4:ec2c with SMTP id n21-20020a05640204d500b004acd2b4ec2cmr21272390edw.29.1680130852222; Wed, 29 Mar 2023 16:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680130852; cv=none; d=google.com; s=arc-20160816; b=j2flvlMXSTi9VW9ystdpK/uUX5EPRo/BegP6j4V/hMeGNeBVUn9wRr6I66b3gOAsg9 5f7IDH3+p49hzIa+MRRTAtD+3F9qtlOrcz/7/c3cgNTiGqdbl+Ajf72Tm4PFXVqzzlGq p5FDYM4Cquw95isl/beIvCloG8Vd0hD8Q7DfavksiAyembstziNzBVpb+lHXUEtmLgfr zlt595L2T5G8mN1iL7eEvOGlNpAbO5eR6xogrFFMRAbMp6O0TK12xVWiuI3HuKOFSkAO TaCSpHWmKHPfRMtL2ZvspUr9EHhlIe3if1cwYHkryPLhofuJOj7xDmvv1vsvqD0whbUA vGgA== 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=V+3/FcGLR6mUBShB+6Z9iCT8/lNGpbiYW8ilej7HttM=; b=ZjLSYD61MehrnU2epogTdfClqDueke8mj16sc3637CA0+3xLvp7D6bjU3QgtaLrET9 kE/Ibp+5wnnIQs755+CUklQXW5T0k+PhSOwExmLHzPivll/aKLvzT+5sbge140mZDH6z hrf1E6E6tZVSxSmUmtMyFlvFsJYBl3crnQ6HISwhK0i47uMA/L2NoyF4r/vGZWDCsXEv SLOipil9cdhgQasJAvaiq7QP2jHDfgD2evPYfYjGrREzJKQgsiUZ4IeOLqfs8fpoNsYm PX68dKHtKGTtGQpEUbM1kWNWOv+vuGdW7dHZGuptVvK2bzvotr92UmptZ29fd6GOzFAU DOCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=bDcPvqDe; 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 c19-20020aa7df13000000b004acbd4990e5si36984575edy.158.2023.03.29.16.00.25; Wed, 29 Mar 2023 16:00:52 -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=bDcPvqDe; 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 S230048AbjC2Wd0 (ORCPT + 99 others); Wed, 29 Mar 2023 18:33:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjC2WdU (ORCPT ); Wed, 29 Mar 2023 18:33:20 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DA76A6D; Wed, 29 Mar 2023 15:33:16 -0700 (PDT) Date: Wed, 29 Mar 2023 22:33:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680129195; x=1680388395; bh=V+3/FcGLR6mUBShB+6Z9iCT8/lNGpbiYW8ilej7HttM=; 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=bDcPvqDeoH3HgHItPWiY5emWTJ2TX1MqqC7sOLgsCNM8WmYcK/611sDpdtejDg9vS CD8Uz3Hwdb7Q9J60WqcXrp0iCYnz/5jejXKuwNbraYsuR0pz0CgmfM/jQAM0meV9NK EcW/syx2qDYE2D0ZGrv+njm9ulKY2QONkjjIBI4CcAQkx4OOFEFsWgL2H6KMTj8M8F +9h6gMRCzyieRB66Hz34ZmRHoPQBUCF8jLbwAJLsjhARLowJJof0wyKAVV+o1dTk6c jiKOnUKHa05PP1d8O8K5ZWVQaWRCG8N9IsrwDv+zdYLDx5c1GPnkxX+jzVvWvnUo6r 3YK7ZkTB84MUQ== 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 03/13] rust: types: add `Opaque::raw_get` Message-ID: <20230329223239.138757-4-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?1761744888611623780?= X-GMAIL-MSGID: =?utf-8?q?1761744888611623780?= From: Benno Lossin This function mirrors `UnsafeCell::raw_get`. It avoids creating a reference and allows solely using raw pointers. The `pin-init` API will be using this, since uninitialized memory requires raw pointers. Signed-off-by: Benno Lossin Reviewed-by: Gary Guo Reviewed-by: Andreas Hindborg Reviewed-by: Alice Ryhl --- rust/kernel/types.rs | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.39.2 diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 9d0fdbc55843..ff2b2fac951d 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -238,6 +238,14 @@ impl Opaque { pub fn get(&self) -> *mut T { UnsafeCell::raw_get(self.0.as_ptr()) } + + /// Gets the value behind `this`. + /// + /// This function is useful to get access to the value without creating intermediate + /// references. + pub const fn raw_get(this: *const Self) -> *mut T { + UnsafeCell::raw_get(this.cast::>()) + } } /// A sum type that always holds either a value of type `L` or `R`.