Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1706019lqz; Mon, 1 Apr 2024 14:46:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9/+oE0+APxuiQ1NoxIPHb7SC7MWes6MsoBIvtXlo3WvlHQv3o/bmVNJfyfJ0kcLYmrpTqoxiuZANNsvc8fK1UHpKfQ0KsfCXuAqBbnQ== X-Google-Smtp-Source: AGHT+IEHZvzVeO6rdGH+YJCY7mV0kn+r2fIzUzH8wmq0EOJ2QuDlEatwE3JBY3y0mM9k1FRvLj9A X-Received: by 2002:a05:620a:28d2:b0:78b:e65b:d55c with SMTP id l18-20020a05620a28d200b0078be65bd55cmr3975585qkp.64.1712008015343; Mon, 01 Apr 2024 14:46:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712008015; cv=pass; d=google.com; s=arc-20160816; b=ea1jTHMmVQrN33kzcF4EdWoBwsJTTWD1QT4m+Be0BD/kISW8xdmonDO0SEQAcV6X4B nCkc35eEjdYbT410/BIXoy/omKu6BapM6s0fQ+Nr1ZakM1pclYyx2RCD4CEJLULBljQq 2REb2V8Ofi5cv0be7L/fjFCqZeNskgfLvQNHcgyPxI8jazaP9H8WccrQS6gH/uIIDrql AoZick0qAPiqJm0neKPiD6Lj80wgH2f4KV6XFrKFYb2zrGxMfurXOwRlv942ch+3ZmNd gIFPX/0H+G+h/7CrwRIWHpdM6/WXUzSFI7RTYYkJ8BEqAt+EKCXGZ01n9JacEAS6ytqb JNzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:feedback-id:dkim-signature; bh=J7lSE+wLlV3A/nFCxQIWYeydbyIlsHZV9kGDRSJJqRs=; fh=byRHxsblg68MolDxtuyylMSZSpCbGswMyxWYsGgMgBc=; b=yTuVicKjx/wTXE+B1sRIBXQuUy5Z9nvpXF/deRvd7NDB+7Sqk++G+YozShsmVbZGeY AIq5NEw6w+uGbz4OWqkOjXt88CPklar6YnV4eA8tlM2vLOTqT+aep4C86nrwDC7x0dd0 l+bdS96O31s5j9tU51jM60X5rPgHmpNCWtaF4kGAiTpUHj9wxOc4SjQQC0nOafqSMHKL f1MEVFZ9Q5n6YActVtAOfOnS26it5pgfsKpiC5sstLOBRxRcriI7wwnzP63AF/db8hYz 2rfGiXZX7WioEj1Yg0XFitoqWrHnD51LEWvylQk+glAu71XHmyUvo1os2XQl+7wwPLV+ 0l6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LicG1RMm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-127102-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127102-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id vw25-20020a05620a565900b0078a2add7b88si9897309qkn.166.2024.04.01.14.46.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 14:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127102-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LicG1RMm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-127102-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127102-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 08FCD1C216CF for ; Mon, 1 Apr 2024 21:46:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 223965577C; Mon, 1 Apr 2024 21:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LicG1RMm" Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBC551C2E; Mon, 1 Apr 2024 21:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712008005; cv=none; b=eFvTonKSujmvPkCLKJXGJ695nhbMlpcI/avERa+Ba4jWh9FKCgfoxpTTznQZGy+rdRA/0kgONwE9BrzPJzuMgomAompbM2Vpb1EMkbYIbgZFc89a3FrnOdAMaGajt10qbUEG+C0iZmAP3IH4PboerMkbMqi/aPaNhiXpUY39x8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712008005; c=relaxed/simple; bh=lga2qVC6bx434ILieAy8p2z4iLgehhtKZVAlm+C3omw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=C4vcTRAXLcRKHuw+x67ze72X7a8LrROPSOwvlRKiECH4dDimIHG9/lzrbFYD2hChZLAkpVxPS/9NjJAhHyLFOc8wUAsi4/CryOV6l07rLS/3OV5P0ox8q2Pc3bw7ZWoQom+exaE61/WHloYvP9ca+xCSqAlg7cFFJXhnOs6NbH0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LicG1RMm; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-432fe06d76fso4733761cf.3; Mon, 01 Apr 2024 14:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712008003; x=1712612803; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=J7lSE+wLlV3A/nFCxQIWYeydbyIlsHZV9kGDRSJJqRs=; b=LicG1RMmPvJgno746Ls1Yq/b5s4vDKy0isUFXX5/ULCcIvV7iv9Y428yVfVB62mBCa eaXzfAkNafaaF8u2ETdsQn/hnsZBagNd/XPD9NKKI5ZLkH5i2dMLRwuoNfSx4zCT1lVQ C99ToilLivRZeVF5KDGp80wUoMnbhI7gNHqACKALvhTFIVH2X5jfav8LXvHfBU05mICx zvmSOyTo/mQXC6+zhe0dwq8NnwXq9jJ/7VppK6kInJLzvQMf8LUYhwgkCPzVbnkQAMuE sGhKKcQyZ8kL/+a8geMv6McY6s4l/KEM7StlnxILegKQDrj+4gIWLD59HC51kJhfwdv5 WlWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712008003; x=1712612803; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:feedback-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=J7lSE+wLlV3A/nFCxQIWYeydbyIlsHZV9kGDRSJJqRs=; b=q/TBEkCbyC4G2CR8s8MhzoyDYwqe+YXnkbaOX1kveMhzKGRNYcJYYiq3J6TKA8eOAw GZqfkEx12HDSH/bZw3boZEn82NcveK5XkLY0YxKCmMYTWzXykJRlZITojc6bpexgB3KA fHzQ5DLtEZspXX7OiMww2xtLUf3yYX3Dyl37qox9vQyxfkWaLsXmQURCMAdAxzaiCQkr wjq4ZQLkqrTboBubJPNhhCaCozgg1c/bY8YCpBxbCS6PW/1HWR9m1PSfnog/oQfD/do8 R6fVNXzWr4wW07gADkiTTA36E7c0l4qBPaA0qE0cmCAMnKxfmuyQ7zxkWHC6Tha6Zrub bZ+g== X-Forwarded-Encrypted: i=1; AJvYcCVq9MGuTQqfrt0NfSgFA9aoMKjTfRlo2KSJwBxfDLQ8MsCBcbGdx06PIFiGX/Jkt7xUMfppf8SpFWF08w5fYfpJaJDrQAGYCe74FpiI X-Gm-Message-State: AOJu0YzYSOaOV9OEXoj5VbXuaRKNqQO7l8JcmOk95umeOoswyXLr4Qr8 1+g7NIgsMeL/wAh8o6RbKU+8+IRlLTpjBJ6rwGLCSZm87ANpDqjskc1NLUS5 X-Received: by 2002:ac8:5e0a:0:b0:431:3fee:9d53 with SMTP id h10-20020ac85e0a000000b004313fee9d53mr13034473qtx.24.1712008002746; Mon, 01 Apr 2024 14:46:42 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id et16-20020a05622a4b1000b00430b385f721sm4908999qtb.15.2024.04.01.14.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 14:46:42 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id DDD321200032; Mon, 1 Apr 2024 17:46:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 01 Apr 2024 17:46:41 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudefuddgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpefgteffhfehjeegtdduieffudetfeehgfegudejudfhieefgfeigfevueduledu ffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsoh hquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedq udejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmh gvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 1 Apr 2024 17:46:40 -0400 (EDT) From: Boqun Feng To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Boqun Feng , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , Obei Sideg Subject: [PATCH] rust: types: Make Opaque::get const Date: Mon, 1 Apr 2024 14:45:36 -0700 Message-ID: <20240401214543.1242286-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To support a potential usage: static foo: Opaque = ..; // Or defined in an extern block. ... fn bar() { let ptr = foo.get(); } `Opaque::get` need to be `const`, otherwise compiler will complain because calls on statics are limited to const functions. Also `Opaque::get` should be naturally `const` since it's a composition of two `const` functions: `UnsafeCell::get` and `ptr::cast`. Signed-off-by: Boqun Feng --- rust/kernel/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 0949f9971074..25953c8f8acf 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -315,7 +315,7 @@ pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit { } /// Returns a raw pointer to the opaque data. - pub fn get(&self) -> *mut T { + pub const fn get(&self) -> *mut T { UnsafeCell::get(&self.value).cast::() } -- 2.44.0