From patchwork Fri Jul 14 09:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 13313410 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBECAC0015E for ; Fri, 14 Jul 2023 09:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235764AbjGNJcV (ORCPT ); Fri, 14 Jul 2023 05:32:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235920AbjGNJcG (ORCPT ); Fri, 14 Jul 2023 05:32:06 -0400 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781923595; Fri, 14 Jul 2023 02:31:42 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id 471AB5BC3C; Fri, 14 Jul 2023 09:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1689326052; bh=o+SeZO+TTzWLzgNWKeL/9Zv5OKicaLoX59hV3WtVOuQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=G1Wt2cxZ6pXf5tZHduVNikkCwJ3eY/lAhhmaHq//OZOo1deR9FPvpL756OTXtqF85 U8KN4XXHwq4kXASxrE4WM3foVumLTNRuyqWbxwvb3G5DVYK5urrwEpptS14bvFxNuV rM9oWkXKT6+KtlANMnhRwMIRrKKn/t+a1OQzzUInlbKfRIEEiKHfM46BpexZR3xeQo zw6WVMGuSbW3xPkeiUX1+B0n8oA2tixHQOpEQD8x35urVL0yabJLZeR9yatWjie17f HvYMnAtJzpmQQjPcKmEpSusQK/YGodFN0o0fLT0yKw6OpEZ1e/EstgBaO+Fg78oVw9 /bKFNaONUniCA== From: Asahi Lina Date: Fri, 14 Jul 2023 18:13:53 +0900 Subject: [PATCH RFC 01/11] rust: types: Add Opaque::zeroed() MIME-Version: 1.0 Message-Id: <20230714-classless_lockdep-v1-1-229b9671ce31@asahilina.net> References: <20230714-classless_lockdep-v1-0-229b9671ce31@asahilina.net> In-Reply-To: <20230714-classless_lockdep-v1-0-229b9671ce31@asahilina.net> To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , Daniel Vetter Cc: Hector Martin , Sven Peter , Alyssa Rosenzweig , asahi@lists.linux.dev, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev, Asahi Lina X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689326040; l=917; i=lina@asahilina.net; s=20230221; h=from:subject:message-id; bh=o+SeZO+TTzWLzgNWKeL/9Zv5OKicaLoX59hV3WtVOuQ=; b=P7T19OB+nyd6yqEUa+zAXigTFInuYsRPYk1q7QrYZWp3AGBZT9g7I8/XOtzJ0ql7JeJgdOQIU c1DhSVUSWWlDIOLTjbR15WVf3RuPsnSK+ax6uw3FGMMMCpBAJ/uBqK1 X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=Qn8jZuOtR1m5GaiDfTrAoQ4NE1XoYVZ/wmt5YtXWFC4= Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Opaque types are internally MaybeUninit, so it's safe to actually zero-initialize them as long as we don't claim they are initialized. This is useful for many FFI types that are expected to be zero-inited by the user. Signed-off-by: Asahi Lina Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo --- rust/kernel/types.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 1e5380b16ed5..185d3493857e 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -237,6 +237,11 @@ pub const fn uninit() -> Self { Self(MaybeUninit::uninit()) } + /// Creates a zeroed value. + pub fn zeroed() -> Self { + Self(MaybeUninit::zeroed()) + } + /// Creates a pin-initializer from the given initializer closure. /// /// The returned initializer calls the given closure with the pointer to the inner `T` of this