From patchwork Fri Mar 31 21:52:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 77995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp863549vqo; Fri, 31 Mar 2023 15:00:10 -0700 (PDT) X-Google-Smtp-Source: AKy350adjBFg2lvqpQz9KD09BEDZ2yvU+umcqxv5GOQEjWUOcEIY0jAl5oAkYevPFOZubK9SLav1 X-Received: by 2002:a17:903:234c:b0:1a1:b9e6:28a8 with SMTP id c12-20020a170903234c00b001a1b9e628a8mr35912608plh.45.1680300010400; Fri, 31 Mar 2023 15:00:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680300010; cv=none; d=google.com; s=arc-20160816; b=ZKqKfFlmrw3jRfaZdGqPPDGvUngqG54SC27Jnx02p7YqfAN8wqdq9+zla3aLmo0YNs S4S8LotLDT9GZoWPvJQNgzQch2ePa0LETnBHWxW9oohvEXitaVFwsf6eEzz21XXpYrk3 sE3p4RSuDEBL0a5vCQKdZRqh73iQatcHswEa0Vh/fqtdT0kKrNpUp3zE/T/Vpo6e/W8l Cd3PNTO8C2+w9r3XTfMrOWBn7xMj1QJxFlaNd5oDsYbQLvINKUcNDy65nJw6gf1rFHao 4h36/9icV3KpLA4+50o+N4d676MS1oT4Q/gcJE/cQIRMjWPNLM1HMoCdnpjjZEC7XOzS aO2A== 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=Za/m4aK9PnJEmnWJB3YV+TN80PGCqO5M482kG2Z4FzU=; b=AyHaGbAiNENDmc5U5q14/Vhsy2D3RFHqsBXOacdDwAWzJBlhjjg3bb0AeV9kHnXUEd 5i6IfbsaW8VM23GGXiCqo4UMTW9nWAYmI5AB3L8YCj72rlY0y202ndyz/Rfq36iMINrP TDOVzEidQVvZy7kUY4OWFh/IexecwRl56g/7aNVGlEkwFHrikZd0LbHebvzEI+f54ezo FHa7L1fRuwIGL7nkJIRvgOU4rdNv+Wc7hO/yQCrR6TJz46jsFYOvEP/Lubh0+do9MSgp CwUpGGE0Glt4jgHJODqDaiik2jiVydMjhoLedW0d8PsbhLiP+Q03JxhwShOtXnH2RhKD Txig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=bp06f2HF; 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 la16-20020a170902fa1000b001a1cbba6fedsi3047118plb.382.2023.03.31.14.59.57; Fri, 31 Mar 2023 15:00:10 -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=bp06f2HF; 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 S233324AbjCaVxn (ORCPT + 99 others); Fri, 31 Mar 2023 17:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233233AbjCaVxa (ORCPT ); Fri, 31 Mar 2023 17:53:30 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0728A1BC0 for ; Fri, 31 Mar 2023 14:53:01 -0700 (PDT) Date: Fri, 31 Mar 2023 21:52:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680299574; x=1680558774; bh=Za/m4aK9PnJEmnWJB3YV+TN80PGCqO5M482kG2Z4FzU=; 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=bp06f2HFPkWAuvmFbH5+BrrVjCnYBmETv//Z6r7awcX8quV3JtC6GLwpBD0ePTaBi YM6jx4Cu64pWBD4kceJX0BMGE2V6tuP1hNmHw/N0fF+acmzXr/fsy6RnshFkPdjWXL Jb96CjH2DWAFhWw8gwsTA0qBHkJDdKtpg3Xbzw7EhCENzdg7XuS3D8fctEWEerrqJp UMOkOOKdu6Ho8/nYBHJqLKhnKBdIoNUbdCI2MrlZ5kDn1jlaV7mHBDb3K0+0J3jNuk 3DHBySotwGyvFPp5eRWFCAWc5u6TinoRUcqrZuCltH70oEUL2YEKy2zIbgF6vAqfKJ wFOnlHfHhRF2w== 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 , Andreas Hindborg , Alice Ryhl Subject: [PATCH v4 05/15] rust: types: add `Opaque::raw_get` Message-ID: <20230331215053.585759-6-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?1761922263357215856?= X-GMAIL-MSGID: =?utf-8?q?1761922263357215856?= 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`.