From patchwork Sat Apr 8 12:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y86-dev X-Patchwork-Id: 81188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp848315vqo; Sat, 8 Apr 2023 05:37:01 -0700 (PDT) X-Google-Smtp-Source: AKy350ZCnNY+QhLP0xWLiRgzbhOuJcXLX+kQzl1Yt3wJwksdEc368xprghFYTo8XYZfcwDwDPLHZ X-Received: by 2002:a17:906:4e14:b0:931:7adf:547e with SMTP id z20-20020a1709064e1400b009317adf547emr2566866eju.70.1680957421133; Sat, 08 Apr 2023 05:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680957421; cv=none; d=google.com; s=arc-20160816; b=O/k49NuN8r+fx5WD5A51qpsa4ovWBDb+yHz2IWDxpsbWqb9Lv/0oFbvinP+9iJ7Pi9 2h9fC+6iayekcPZmrW71KWVaJOUFAc/COKxowPh/qn9WU2FYc5sSdDKZF7kZMak7WTYy 8HylurQFzGHXonwdYvjrrvxom7XSJikJ1kDpRmQ3NekRbS22Ep0j28d/mVZ0G97yIPBG UZGM8JPcmMh7yDbQchT42S0reLKfpTgChy/QNZ62Gy/r3cZJCQbfB+6IMryR1Pa2F5La s1Di1D2nAt/fZPkShJ2kahHxHM5geNgbzTNhKYTaYg5UgfHgJgzUM45a7kTEPMjJh3rC PXTw== 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=mfdeZ0tlvZEiVDuT4K2c82YeL62xTzooOg48fEMpwYAuPZlVFmC0J1RYdiEILgLz2F CwN5CWeSXGDPlGA8d+h662n6MiayrUx6I8ilmRpOuAtsSEOHnK8KsM0NeusUDa0b4Dtg qqeMvlupUG77zUkZF2/CNt5RAlHAKO252cDNjKRSw0LClv/eUVkV3dGL44x/xQV87s2x iSLTt/I/zFwaRhZLdyh4Q5LZinSs6JUQ4MIakkI5GG3d8DizoO+f7+IS8JhCzApDMy2k Ko3V4E08j1FcMpGZOHatYwfSvGiSyylWJso3aKdQk+2ZmIsETLezIY915lrjkoPhJhdy MgnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=wYbDYJmr; 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 r11-20020a1709062ccb00b008e0bd541c68si4692960ejr.594.2023.04.08.05.36.37; Sat, 08 Apr 2023 05:37:01 -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=wYbDYJmr; 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 S230265AbjDHM0n (ORCPT + 99 others); Sat, 8 Apr 2023 08:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbjDHM0i (ORCPT ); Sat, 8 Apr 2023 08:26:38 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F0A3113C0 for ; Sat, 8 Apr 2023 05:26:14 -0700 (PDT) Date: Sat, 08 Apr 2023 12:25:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680956752; x=1681215952; 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=wYbDYJmraPxCNtugfl+8EK4ojUD3Ko0hK6aHHcOlLx0R9+315OfBsZnO80StwEO6Z e+z7tdr+IvLyy2OkDHyMY7VLCRqEbPJ2YbCWtRnKhwvEAgPuxl6gK8O6H5p3PwuBg9 EcSz2h+L4QvVhF3wI7W28D2bNfDzrPi/B/kVMHjEksLKrpwmCkiOc1JJV0ZGs9GJpe MeYi2OeYZyw2OqmwL7jIJJ7jZwmCQTjsJs+cXVAPaN0Dt4UUiTnzV13VPhWLY1Tpct VZ2A97rSNk2LxUJ2S+YQaqJAPj5oxBNgTYC3miw+8jf9UmXRHijjf5QQ03P3JckqvD 97JWFxJ34j1NQ== 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 v7 05/15] rust: types: add `Opaque::raw_get` Message-ID: <20230408122429.1103522-6-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?1762611608997181087?= X-GMAIL-MSGID: =?utf-8?q?1762611608997181087?= 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`.