From patchwork Wed Apr 5 19:35: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: 79877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp546472vqo; Wed, 5 Apr 2023 12:38:37 -0700 (PDT) X-Google-Smtp-Source: AKy350ZdcPoJtH9DvZwFuI6IlKc6QXV7jqsv+viSC1IthB7/Avn5xnohiigMOeHNpLVJmTkDDMCM X-Received: by 2002:a62:5102:0:b0:62d:91b0:b369 with SMTP id f2-20020a625102000000b0062d91b0b369mr5522025pfb.26.1680723516983; Wed, 05 Apr 2023 12:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680723516; cv=none; d=google.com; s=arc-20160816; b=oFIETKKUpHPFAA52r4qkmSz0ulZUiEnm8VynsdDLRN/x+1Snzh6ZrVEhJJUMkeLDJl cGk3EOxt8DKkNHwh2SppILwvZy9sH3SMyI9s5iD0EnNCeoj3Y4/uhJIjEIvtfTlQRGjP hnoHOuz0SiZ/MD1Xf2ha6TscKjAu7W5QlLZ9q056rWUDHCghIQ/3g0J64eO360iGxEG3 ik2zCVmpIJrmfAxY2oWVsFMeMKbTh7i7ic9hkmZ50j3bauId7Nu/cZLdFeXNrrwDUt59 UgEqdyP1iXGEXDUMmPRKfXphwD/YKmJRpU7Emrwi3BV5oZE8MwhAfiAVI+ePtBFftEOi 02NA== 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=7rH6H6G+ATzJ5NdhnHFFoHIa5Qvd43Dus1uGWQ71zqY=; b=flC2kltPr6EQkLkKHx5NTMm1jqKIY1BBxNIte+zd+mFg8FGTjKn97zcwXyqXvX1F+/ yJlaIuSbfuU2qRjNYJwR+MbJD1yZqCLS4Ba3pnllY4WHamncZxtG51uyM71l0DHjxhV7 nWM5WAiQgTM/e96kL/vc/OpEBcgzYU/ra7qWXwgfAFSy69qr1ZII7b6P0NlC1oLlZuY+ RSJjv4DkFdAPve4Te8fQqz35MFIbbuUPsG5vpMR/iY3ALxaNTYDQOOBuMCp6IajEtRuR xdvSXpZbVoQiqjixQVqYer6PbibWcPYKqqIi/03FYlm9a2o5PGHiSQGgSBp64ZSPS3xV uQxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=FZZCOcHO; 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 a190-20020a621ac7000000b0062dd75854ebsi12922351pfa.82.2023.04.05.12.38.24; Wed, 05 Apr 2023 12:38: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=FZZCOcHO; 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 S231574AbjDETgr (ORCPT + 99 others); Wed, 5 Apr 2023 15:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234058AbjDETgh (ORCPT ); Wed, 5 Apr 2023 15:36:37 -0400 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 367BE7298 for ; Wed, 5 Apr 2023 12:36:14 -0700 (PDT) Date: Wed, 05 Apr 2023 19:35:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680723372; x=1680982572; bh=7rH6H6G+ATzJ5NdhnHFFoHIa5Qvd43Dus1uGWQ71zqY=; 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=FZZCOcHOC/Mp6LipdJFIMGMkvtopwN7C0MWlZ5ngtjSzJMw3iU5v6hHzanI4lv+WZ KB31i4FgNkEUPEVLDoR1Nphk3mZkceC90kSPa0fNk+msZVIdUMa+KsRn9R1Jnieo+j DGk+DTaD8R9is8H/6s1+7685+2eOjggM9jUTNcdOm51x/LkFce5KBDK+bnBNOLd/gI iGEUb2SLFlfPj7/dx/nwGMNMfHydsB7TBIC4PZtfBZG9hcPq8uTvm2dpereR5Tfxxa lEjzVvHKsATfYukEToMxjMB/cgg2cfFHPe6rVkjVaUXmPeO5ASSAiKN3QLj9DSgcnM vA+hVVoOmm+0A== 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 , Andreas Hindborg , Alice Ryhl Subject: [PATCH v6 05/15] rust: types: add `Opaque::raw_get` Message-ID: <20230405193445.745024-6-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?1762366342794194754?= X-GMAIL-MSGID: =?utf-8?q?1762366342794194754?= 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`.